echarts绘制多条折线图

效果

在这里插入图片描述
首先引入echarts可以看这篇文章哦~
如何在项目中使用echarts

1.定义一个div

这里的height就是y轴的高度了~

 <div style="width: 100%; height: 600px" ref="chart"></div>

2.定义一个方法init

在mounted引用

 mounted() {
    this.init()
  },

3.定义数据

这个一般是后台给的接口的数据,我这里是模拟的哦~

let lineData = {
        x: [
          '9月15日',
          '9月16日',
          '9月17日',
          '9月18日',
          '9月19日',
          '9月20日',
          '9月21日',
          '9月22日',
          '9月23日',
          '9月24日',
          '9月25日',
          '9月26日',
        ],
        y_green: [103, 98, 120, 65, 63, 130, 125, 75, 130, 125, 75, 115],
        y_red: [210, 190, 190, 160, 170, 210, 207, 176, 176, 210, 170, 180],
        y_blue: [315, 316, 315, 315, 317, 317, 316, 316, 315, 315, 315, 315],
      }

4.配置属性

const option = {
        title: {
          text: '巡检次数',
          x: 'left',
          textStyle: {
            fontSize: 15,
            fontStyle: 'normal', // 主标题文字字体的风格。 'normal'  'italic'  'oblique'
            fontWeight: 'normal', // 主标题文字字体的粗细。 'normal' 'bold'  'bolder'  'lighter' 500|600
          },
        },
        tooltip: {
          trigger: 'axis',
        },
        grid: {
          left: '1%',
          right: '4%',
          bottom: '23%',
          containLabel: true,
        },
        legend: {
          padding: 10,
          tooltip: {
            show: true,
          },
          y: 'bottom',
          data: ['实际巡检', '计划巡检', '漏检次数'],
        },
        xAxis: { type: 'category', data: lineData.x },
        yAxis: { type: 'value' },
        series: [
          {
            name: '实际巡检',
            data: lineData.y_green,
            type: 'line',
            itemStyle: { normal: { color: 'green', lineStyle: { color: 'green' } } },
          },
          {
            name: '计划巡检',
            data: lineData.y_red,
            type: 'line',
            itemStyle: { normal: { color: 'red', lineStyle: { color: 'red' } } },
          },
          {
            name: '漏检次数',
            data: lineData.y_blue,
            type: 'line',
            itemStyle: { normal: { color: 'blue', lineStyle: { color: 'blue' } } },
          },
        ],
      }

在这里插入图片描述
完成啦~

  • 6
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小莉爱编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值