echarts官方给的渐变色设置demo代码如下
color: this.$echarts.graphic.LinearGradient(0, 1, 0, 0, [
{
offset: 0,
color: colorList1[i],
},
{
offset: 1,
color: colorList2[i],
},
]),
因为我这里是遍历了series的数据,所以是多条颜色渐变,但是代码运行的结果是,所有的线条和柱子都是同一种渐变色,没有达到预期的效果,具体原因不明。
解决办法如下:
color: {
type: "linear",
x: 1,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: ColorList2[i], // 0% 处的颜色
},
{
offset: 1,
color: ColorList1[i], // 100% 处的颜色
},
],
global: false, // 缺省为 false
},
这样就能实现不同的线条或柱子的渐变色也不一样