Echarts柱狀圖修改柱子顏色漸變及柱子圓角效果實(shí)例
前言
修改柱狀圖柱子背景色漸變和圓角,可通過修改series.itemStyle.normal.barBorderRadius屬性實(shí)現(xiàn)圓角設(shè)置,series.itemStyle.normal.color:new echarts.graphic.LinearGradient()來設(shè)置漸變色柱子。
效果圖:
代碼如下:
series: [{ data: data, type: 'bar', barWidth: '40%', itemStyle: { normal: { //這里設(shè)置柱形圖圓角 [左上角,右上角,右下角,左下角] barBorderRadius:[5, 5, 0, 0], color: new echarts.graphic.LinearGradient( 0, 1, 0, 0, [{//只要修改前四個(gè)參數(shù)就ok offset: 0, color: '#c6e6ca' }, //柱圖漸變色 { offset: 1, color: '#45ac53' } ] ), }, }, }]
附:Echarts繪制橫向柱狀圖(圓角+漸變)
圓角配置
series: [ { name: '數(shù)量', type: 'bar', data: barData, barWidth: 14, itemStyle: { emphasis: { barBorderRadius: 7 }, normal: { barBorderRadius: 7 } } } ]
漸變實(shí)現(xiàn)
設(shè)置itemStyle的color為new echarts.graphic.LinearGradient()線性漸變即可. 這個(gè)API在官方文檔里面都沒找到, 經(jīng)過測試前四個(gè)參數(shù)設(shè)置為0, 0, 1, 0可以從左到右漸變. 設(shè)置為0,0,0,1可以從上到下漸變. 第5個(gè)參數(shù)數(shù)組表示開始的顏色和結(jié)束的顏色.
itemStyle: { emphasis: { barBorderRadius: 7 }, normal: { barBorderRadius: 7, color: new echarts.graphic.LinearGradient( 0, 0, 1, 0, [ {offset: 0, color: '#3977E6'}, {offset: 1, color: '#37BBF8'} ] ) } }
完整代碼如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="ECharts"> <title>Echarts繪制橫向柱狀圖(圓角+漸變)</title> <script src="https://cdn.bootcss.com/echarts/3.5.4/echarts.min.js"></script> </head> <body> <div id="main" style="width: 1000px;height:400px;"></div> <script type="text/javascript"> var myChart = echarts.init(document.getElementById('main')); //初始化數(shù)據(jù) var category = ['小王', '小李', '小趙', '小馬', '小劉', '小張', '小齊']; var barData = [3100, 2142, 1218, 581, 431, 383, 163]; var option = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: { type: 'value', axisLine: { show: false }, axisTick: { show: false } }, yAxis: { type: 'category', data: category, splitLine: {show: false}, axisLine: { show: false }, axisTick: { show: false }, offset: 10, nameTextStyle: { fontSize: 15 } }, series: [ { name: '數(shù)量', type: 'bar', data: barData, barWidth: 14, barGap: 10, smooth: true, label: { normal: { show: true, position: 'right', offset: [5, -2], textStyle: { color: '#F68300', fontSize: 13 } } }, itemStyle: { emphasis: { barBorderRadius: 7 }, normal: { barBorderRadius: 7, color: new echarts.graphic.LinearGradient( 0, 0, 1, 0, [ {offset: 0, color: '#3977E6'}, {offset: 1, color: '#37BBF8'} ] ) } } } ] }; myChart.setOption(option); </script> </body> </html>
總結(jié)
到此這篇關(guān)于Echarts柱狀圖修改柱子顏色漸變及柱子圓角的文章就介紹到這了,更多相關(guān)Echarts柱狀圖顏色漸變圓角內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 解決echarts 一條柱狀圖顯示兩個(gè)值,類似進(jìn)度條的問題
- Echarts基本入門之柱狀圖、折線圖通用配置
- Echarts Bar橫向柱狀圖實(shí)例代碼
- Vue使用Echarts實(shí)現(xiàn)立體柱狀圖
- vue echarts實(shí)現(xiàn)柱狀圖動(dòng)態(tài)展示
- vue echarts實(shí)現(xiàn)橫向柱狀圖
- uniapp引用echarts的詳細(xì)步驟(附柱狀圖實(shí)例)
- echarts動(dòng)態(tài)渲染柱狀圖背景顏色及頂部數(shù)值方法詳解
- 基于vue+echarts實(shí)現(xiàn)柱狀圖漸變色效果(每個(gè)柱子顏色不同)
相關(guān)文章
微信小程序chooseImage的用法(從本地相冊選擇圖片或使用相機(jī)拍照)
這篇文章主要介紹了微信小程序chooseImage的用法(從本地相冊選擇圖片或使用相機(jī)拍照),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08Antd?ProComponents中的EditableProTable無法在子行繼續(xù)新增子行的解決方案
這篇文章主要介紹了Antd?ProComponents中的EditableProTable無法在子行繼續(xù)新增子行的解決方案,本文通過復(fù)現(xiàn)代碼給大家詳細(xì)講解,需要的朋友可以參考下2022-08-08JavaScript數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí)之?dāng)?shù)組、棧與隊(duì)列
這篇文章主要給大家介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組、棧與隊(duì)列的相關(guān)資料,文中對數(shù)組、棧與隊(duì)列的使用方法進(jìn)行了詳細(xì)的總結(jié),相信對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-05-05JavaScript兩個(gè)變量交換值的實(shí)現(xiàn)方法
本文主要介紹了JavaScript兩個(gè)變量交換值(不使用臨時(shí)變量)的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-03-03bootstrap模態(tài)框遠(yuǎn)程示例代碼分享
這篇文章主要為大家詳細(xì)介紹了bootstrap模態(tài)框遠(yuǎn)程示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05