Echarts如何创建一个根据数值范围不同而颜色不同的柱状图?
针对echarts3柱状图的答案:在series里配置如下itemStyle,即可实现值大于0时为红色,小于0时为绿色
itemStyle: {
normal: {
color: function(params) {
var index_color = params.value;
if(index_color>=0){
return '#fe4365';
}else {
return '#25daba';
}
}
}
},
参考样例
http://echarts.baidu.com/doc/example/bar1.html
对代码做如下变更
name:'降水量',
type:'bar',
// data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
data:[{
value:30,
itemStyle: {
normal: {
color:'red',
label: {
show: false
},
labelLine: {
show: false
}
} ,
emphasis: {
label: {
show: true,
position: 'outer'
},
labelLine: {
show: true,
lineStyle: {
color: 'red'
}
}
}
}
}, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],