echart 实现添加警戒线

发布时间 2023-08-08 16:56:34作者: 每天都要进步一点点

代码:

option = {
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    type: 'value',
  },
  series: [
    {
      name: '数据系列1',
      type: 'line',
      data: [120, 200, 150, 80, 70, 110, 130],
      markLine: {
        symbol: 'none',
        data: [{
          yAxis: 120,
          lineStyle: {
            color: 'red',
            type: 'dashed',
            width: 2
          },
          label: {
            show: true,
            position: 'end',
            formatter: '警戒线'
          }
        }]
      }
    },
    {
      name: '数据系列2',
      type: 'line',
      data: [80, 90, 100, 120, 110, 100, 90]
    }
  ]
};

效果: