echarts+vue,根据窗口变化重新渲染

HTML部分

<div id="myLine" class="e-line"></div>

 然后是js data

data() {
    return {
      myEchartLine:{},
    }
}

在生命周期mounted里面添加监听 :

mounted() {
  let that = this 
  that.drawLine()
  window.addEventListener("resize", () => { 
    that.myEchartLine.resize();
  });
},

methods里面的绘图:

drawLine() {
    let _this = this
      // 基于准备好的dom,初始化echarts实例
      this.myEchartLine = echarts.init(document.getElementById('myLine'))
      this.myEchartLine .setOption({
        grid:{
            left:'8%',
            top: '4%',
            bottom:'8%',      
        },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            label: {
                backgroundColor: '#000'
            }
        }
      },
        textStyle: {
          fontSize:15,
          color:'#0ec8ff'
        },
        xAxis: {
          splitLine: {
              show: true,
              lineStyle:{
                color: ['#315070'],
                width: 1,
                type: 'solid'
            }
        },
          type: 'category',
          data: [1,2,3,4,5,6,7,8,9,10,11,12],
        },
        yAxis: {
          type: 'value',
          splitLine: {
              show: true,
              lineStyle:{
                color: ['#315070'],
                width: 1,
                type: 'solid'
            }
        }
        },
        series: [{
          data: [567,345,511,244,455,87,570,65,99,432,655,229],
          type: 'line',
          smooth: true,
          itemStyle: {
              color: '#81D1FA'
          },
        },
        {
          data: [323,200,111,104,455,222,547,568,99,810,141,799],
          type: 'line',
          smooth: true,
          itemStyle: {
              color: '#C211EE'
          },
        },
        {
          data: [78,238,70,467,455,326,98,508,99,45,456,429],
          type: 'line',
          smooth: true,
          itemStyle: {
              color: '#0000FF'
          },
        },
        {
          data: [224,111,821,38,344,90,555,79,99,810,141,329],
          type: 'line',
          smooth: true,
          itemStyle: {
              color: '#F7F709'
          },
        },
        {
          data: [414,403,311,234,455,65,547,568,229,810,141,109],
          type: 'line',
          smooth: true,
          itemStyle: {
              color: '#F73809'
          },
        },
        ]
    }); 
    },

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值