Echarts 折线图下方阴影(若Y轴有负值)设置

2,672 阅读1分钟

1. 需求,阴影一直位于折线图下方

按照官方给出的基本配置,写出来的图,当数值为负数时,阴影会出现在上方,如下图:

image.png

上图所展示出来的,当数值为负数时,阴影会出现在上方,不是我们所需要的

2. 解决方法

在 areaStyle 属性中 增加属性: origin: 'start', 即可

所需效果如下图: image.png

// before 
areaStyle: {
    color: {
      type: 'linear',
      x: 0,
      y: 0,
      x2: 0,
      y2: 1,
      colorStops: [
        { offset: 0, color: colorList[1] },
        { offset: 0.8, color: colorList[2] },
      ],
      global: false,
      },
},


// after 
areaStyle: {
  origin: 'start',
  color: {
      type: 'linear',
      x: 0,
      y: 0,
      x2: 0,
      y2: 1,
      colorStops: [
        { offset: 0, color: colorList[1] },
        { offset: 0.8, color: colorList[2] },
    ],
    global: false,
  },
},