项目实践中遇到一个根据需要,当X轴等于某个值是,柱状变成特殊颜色的需求,大致有两个方案实现:
1、在前台遍历数据对象,判断设置;
2、在后台拼装数据是,按照格式要求拼装好;
具体代码如下:
方法一:
option = {
title: {
text: 'ECharts 示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"],
axisLabel: {color: 'green'}
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20],
itemStyle: {
color: function(params){
var c ='';
if(params.value>20){
c='red&#