使用echart完成折线图

效果图:

上代码:

<template>
  <div>
    <div id="demo"></div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      option: {
        title: {
          text: "设备增长", //标题设置‘参保情况’
          // subtext: "纯属虚构",
          left: "center", //标题位置
        },
        tooltip: {
          //鼠标hover覆盖提示框
          trigger: "axis", //坐标线提示
          // trigger: "item", //根据item提示信息
          // formatter: "{b} : {c} ", //提示内容
        },
        legend: {
          bottom: "5%",
          data: ["在线", "总数"],
        },
        xAxis: {
          axisTick: {
            show: false, //不显示坐标轴刻度线
          },
          axisLine: {
            show: false, //不显示坐标轴线
          },
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          axisTick: {
            show: false, //不显示坐标轴刻度线
          },
          axisLine: {
            show: false, //不显示坐标轴线
          },
          type: "value",
          // splitLine: {
          //   show: false, //不显示网格线
          // },
        },
        grid: {
          left: "5%",
          right: "5%",
          bottom: "20%",
          containLabel: true,
        },
        series: [
          {
            name: "在线", //设置名称,跟数据无相关性
            hoverAnimation: true, //鼠标悬停效果,默认是true
            data: [
              { value: 335, name: "设备1" },
              { value: 310, name: "设备2" },
              { value: 234, name: "设备3" },
              { value: 135, name: "设备4" },
              { value: 1548, name: "设备5" },
            ],
            type: "line",
          },
          {
            name: "总数",
            data: [220, 222, 333, 222, 444, 222, 444],
            type: "line",
          },
        ],
      },
    };
  },
  mounted() {
    //   这个方法不能放在greated生命周期,因为那时候dom还没初始化完成
    this.echarts();
  },
  methods: {
    echarts() {
      // 引入 ECharts 主模块
      var echarts = require("echarts/lib/echarts");
      // 引入柱状图(这个例子可以去掉)
      require("echarts/lib/chart/bar");
      // 引入提示框和标题组件
      require("echarts/lib/component/tooltip");
      require("echarts/lib/component/title");
      // 基于准备好的dom,初始化echarts实例
      var myChart1 = echarts.init(document.getElementById("demo"));
      // 绘制饼图
      myChart1.setOption(this.option);
      // 绘制折线图
    },
  },
};
</script>

<style lang="scss">
#demo {
  width: 500px;
  height: 300px;
}
</style>
09-12 11:30