Echarts柱狀圖修改柱子顏色漸變及柱子圓角效果實例
前言
修改柱狀圖柱子背景色漸變和圓角,可通過修改series.itemStyle.normal.barBorderRadius屬性實現(xiàn)圓角設置,series.itemStyle.normal.color:new echarts.graphic.LinearGradient()來設置漸變色柱子。
效果圖:

代碼如下:
series: [{
data: data,
type: 'bar',
barWidth: '40%',
itemStyle: {
normal: {
//這里設置柱形圖圓角 [左上角,右上角,右下角,左下角]
barBorderRadius:[5, 5, 0, 0],
color: new echarts.graphic.LinearGradient(
0, 1, 0, 0, [{//只要修改前四個參數(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
}
}
}
]
漸變實現(xiàn)
設置itemStyle的color為new echarts.graphic.LinearGradient()線性漸變即可. 這個API在官方文檔里面都沒找到, 經過測試前四個參數(shù)設置為0, 0, 1, 0可以從左到右漸變. 設置為0,0,0,1可以從上到下漸變. 第5個參數(shù)數(shù)組表示開始的顏色和結束的顏色.
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ù)據
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>
總結
到此這篇關于Echarts柱狀圖修改柱子顏色漸變及柱子圓角的文章就介紹到這了,更多相關Echarts柱狀圖顏色漸變圓角內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
微信小程序chooseImage的用法(從本地相冊選擇圖片或使用相機拍照)
這篇文章主要介紹了微信小程序chooseImage的用法(從本地相冊選擇圖片或使用相機拍照),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
Antd?ProComponents中的EditableProTable無法在子行繼續(xù)新增子行的解決方案
這篇文章主要介紹了Antd?ProComponents中的EditableProTable無法在子行繼續(xù)新增子行的解決方案,本文通過復現(xiàn)代碼給大家詳細講解,需要的朋友可以參考下2022-08-08
JavaScript數(shù)據結構學習之數(shù)組、棧與隊列
這篇文章主要給大家介紹了JavaScript數(shù)據結構之數(shù)組、棧與隊列的相關資料,文中對數(shù)組、棧與隊列的使用方法進行了詳細的總結,相信對大家具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-05-05

