echart 柱状图改变柱子颜色

很早以前接触过echars,最近又用到了,记录一下。

series: [{
name: ”,
type: ‘bar’,
label: {
normal: {
show: true,
position: ‘top’
}
},
itemStyle: {
normal: {
// 随机显示
//color:function(d){return “#”+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
// 定制显示
color: function(params) {
var colorList = [‘#C33531’,’#EFE42A’,’#64BD3D’,’#EE9201’,’#29AAE3’, ‘#B74AE5’,’#0AAF9F’,’#E89589’,’#16A085’,’#4A235A’ ];
return colorList[params.dataIndex]
}
//如果是两色交替 可以判断params.dataIndex的奇偶去设置颜色
},
},
data: [],
}]

备注:不光是柱状图 ,别的图形应该也适用,可以多去试试它的属性。

猜你喜欢

转载自blog.csdn.net/qq_33301459/article/details/82223405