在使用echarts绘制图表时, 如果需要使用渐变色
, 则应使用echarts内置的渐变色生成器echarts.graphic.LinearGradient
series: [{
name: "2017",
type: "bar",
barWidth: 25,
stack: "1",
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
offset: 0,
color: colors[0].start
},
{
offset: 1,
color: colors[0].end
}
]),
}
},
label: {
normal: {
show: false,
}
},
data: lastYearData,
animationEasing: "elasticOut"
}]
入了5个参数:
前4个参数用于配置渐变色的起止位置, 这4个参数依次对应右/下/左/上四个方位. 而0 0 0 1则代表渐变色从正上方开始.
第5个参数则是一个数组, 用于配置颜色的渐变过程. 包含offset和color两个参数. offset的范围是0 ~ 1, 用于表示位置, color表示颜色