随机生成颜色器:
for(var i=0; i<10; i++){
var colorStr = Math.floor(Math.random()*0xffffff).toString(16);
//如果颜色值是五位,则补零
if(colorStr.length<6){
colorStr += '0';
}
if(colorStr == '005094'){
i--;
continue;
}
colorList.push('#'+colorStr);
}
只要在配置项中使用以下配置即可:
series: [{
name: '数值',
type: 'bar',
barWidth: '20%',
data: dataList,
itemStyle: {
normal: {
color: function(params){
//颜色渐变,右/下/左/上,从下往上渐变
return new echarts.graphic.LinearGradient(0,1,0,0,[
{offset: 0,color: colorList[params.dataIndex]},
{offset: 1,color: colorList[params.dataIndex].slice(0,6)+'0'},
]);
},
}
}
}],