更新時間:2022-10-18 09:48:05 來源:動力節(jié)點 瀏覽2759次
Echarts柱狀圖顏色如何設(shè)置?動力節(jié)點小編來告訴大家。通過ECharts的itemStyle設(shè)定一個數(shù)組設(shè)定顏色的循環(huán)。
option= {
backgroundColor: '#003',
title: {
text: '耗時',
textStyle: {
color: '#eee'
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01],
axisLine: {
lineStyle: {
color: '#eee'
}
}
},
yAxis: {
type: 'category',
data: serviceKey,
axisLine: {
lineStyle: {
color: '#eee'
}
}
},
series: [
{
name: '耗時',
type: 'bar',
data: avgTime,
//begin
itemStyle: {
normal:{
color: function (params){
var colorList = ['rgb(205,85,85)','rgb(210,105,30)','rgb(0,139,0)','rgb(178,58,238)','rgb(54,100,139)'];
return colorList[params.dataIndex];
}
},
//鼠標懸停時:
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
//end
}
]
}
myChart.setOption(option);