let myColor = ["#1089E7"]; //设定柱状图颜色
let opt = { index: 0 };
myChart.setOption({
grid: {
top: "1%",
left: "10%",
right: "15%",
bottom: "1%",
containLabel: true
},
xAxis: {
show: false
},
yAxis: [
{
show: true,
data: titlename,
inverse: true,
axisLine: {
show: false
},
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
color: "#fff",
formatter: (value, index) => { //根据你的需求判断第几个是什么颜色
if (index < 3) {
return (
"{lgs|" +
(1 + index + opt.index) +
"} {title|" +
value +
"}"
);
} else {
return (
"{lg|" +
(1 + index + opt.index) +
"} {title|" +
value +
"}"
);
}
},
rich: { // rich是文字属性自定义
lg: {
backgroundColor: "#8d7fec",
color: "#fff",
borderRadius: 10,
align: "center",
width: 20,
height: 15
},
lgs: {
backgroundColor: "#ff0000",
color: "#fff",
borderRadius: 10,
align: "center",
width: 20,
height: 15
},
title: {
color: "#fff",
width: 35,
align: "left"
}
}
}
}
],
series: [
{
name: "条",
type: "bar",
yAxisIndex: 0,
data: data, //外部定义,这里接收接口
barWidth: 10,
label: {
normal: {
show: true,
position: "right",
textStyle: {
color: "#fff",
fontSize: "12"
},
formatter: function(data) {
return data.value + "次";
}
}
},
itemStyle: {
normal: {
barBorderRadius: 20,
color: function(params) {
var num = myColor.length;
return myColor[params.dataIndex % num];
}
}
}
}
]
});