vue-echarts配置markLine的一些状况

667 阅读1分钟

图表能正常显示,但配置的标线不显示!

问题描述:图表上正常显示没报错,但配置的 series.markLine 不显示。同时,将最终的 option 配置放到 echarts 示例网页上,标线却能显示。

问题解决:忘了从echarts/components引入MarkLineComponent

// 引入并use MarkLineComponent
import { MarkLineComponent } from 'echarts/components';

use([MarkLineComponent]);

如何知道 echarts 暴露了哪些模块?

为了实现复杂的图表绘制,往往需要依赖 Echarts 中不同的模块。如果想查阅 Echarts core/components/renders都对外暴露了哪些模块,可以通过以下两种方式:

  1. node_modules/echarts/libcore/components/renders都有哪些文件夹
  2. 将 options 配置贴到 ECharts examples 演示网页,切换到“完整代码”,勾选“按需引入”,即可看到依赖哪些模块

如何配置多条标线?

根据 series.markLine.data 配置文档 配置。

data 是一个数组,数组中每个配置对象就对应一条标线,甚至可以配置各自的样式

data: [
  // 取值方式可以通过关键字
  {
    name: '平均线',
    type: 'average',
  },
  {
    name: '最小值',
    type: 'min',
  },
  {
    name: '最大值',
    type: 'max',
  },
  // 也可以指定具体的值
  {
    name: '警戒值300',
    yAxis: 300,
  },
];