我对每一个柱状图添加点击事件之后没颜色不会改变,颜色也获取到了?但是颜色点击之后不会改变成自己需求的颜色
配置项如下
option = {
title: {
// subtext: '单位(元)',
padding: [10, 0, 0, 20],
borderRadius: [5, 5, 0, 0],
subtextStyle: {
fontSize: 14,
fontWeight: 'normal',
color: "black",
}
},
color: ['#3398DB'],
tooltip: {
trigger: 'axis',
confine: true,
backgroundColor: "#fff",
position: function(point, params, dom, rect, size) {
// 固定在顶部
// console.log(point);
// console.log(point[0]);
return [point[0] - 80, '20%'];
},
axisPointer: { // 坐标轴指示器,坐标轴触发有效
// type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
lineStyle: {
color: "rgba(255,255,255,0)"
}
},
textStyle: {
color: "black"
},
//提示框阴影
extraCssText: 'box-shadow: 0 5px 5px 5px rgba(30,30,30, 0.3);width:190px;'
},
grid: {
top: "10%",
left: '1%',
right: '7%',
bottom: '3%',
// width: '95%',
height: '75%',
containLabel: true,
show: false,
},
xAxis: [{
name: "单位(月)",
type: 'category',
splitLine: {
show: true
},
data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', "8月", "9月", "10月", "11月", "12月"],
axisTick: {
alignWithLabel: true
},
}],
yAxis: [{
type: 'value',
name: "单位(元)",
gridIndex: 0,
splitNumber: 10,
}],
series: [{
name: '车辆总数',
barGap: '0%',
type: 'bar',
barWidth: '50%',
barGap: 0,
cursor: "pointer",
data: [1000, 2000, 3000, 4000, 5000, 6000, 8000, 9000, 6500, 5500, 8550, 6300],
itemStyle: {
normal: {
barBorderRadius: [10, 10, 0, 0],
}
},
}, {
name: '总计支出',
type: 'bar',
barGap: '-100%',
cursor: "pointer",
barWidth: '50%',
data: [1000, 2000, 3000, 4000, 5000, 6000, 8000, 9000, 6500, 5500, 8550, 6300],
itemStyle: {
normal: {
barBorderRadius: [10, 10, 0, 0],
}
},
}]
};
myChart.on('click', params => {
params.color = "#FFD66A";
params.event.target.style.fill = 'rgba(255,215,0,1)';
});