vue echarts 一个页面多图表自适应(网上千万种方法 各有各解决方案 )

重点(自适应这段放在mounted方法中)

// 自适应不同屏幕尺寸
mounted:function(){
	this.init();
 	const self=this;
 	 window.addEventListener("resize",function(){
	      self.chart.resize();
	      // 如有多图表
	      self.chartLogOutflow.resize();
	      self.chartLogMethodQPS.resize();
	      self.chartNetFlow.resize();
	      self.chartLogCodeQPS.resize();
  });
}

创建图表

// 写入流量
logInflowLine:function(){
      this.chart=this.$echarts.init(document.getElementById("logInflowChart"));
      this.chart.setOption({
          title: {
              text: '写入流量(Byte)',
              textStyle:{
                  color:'#000',        //颜色
                  fontStyle:'normal',     //风格
                  fontWeight:'600',    //粗细
                  fontSize:13    //大小
              }
          },
          tooltip : {
              trigger: 'axis',
              axisPointer: {
                  type: 'cross',
                  label: {
                      backgroundColor: '#6a7985'
                  }
              }
          },
          legend: {
              x: 'right',  
              data:['写入流量']
          },
          series: [{
              name:'写入流量',
              type:'line',
              data:this.logInflow,
              itemStyle: {
                  normal: {
                      color: "#91c7ae",
                      lineStyle: {
                          color: "#91c7ae"
                      }
                  }
              }
          }],
          grid: {
              left: '3%',
              bottom: '3%',
              containLabel: true
          },
          xAxis : [
              {
                  type : 'category',
                  boundaryGap : false,
                  data: this.logInflowXAxisData.map(function (str) {
                      return str.replace(' ', '\n')
                  })
              }
          ],
          yAxis : [
              {
                  splitNumber:4,
                  type : 'value'
              }
          ]
      })                
  },

引用方法
关键:init方法里的setTimeout

init:function(){
      setTimeout(()=>{
            this.logInflowLine();
        })
    }
// 掉接口出x轴和y轴数据
 checkMonitorModuleIndex: function(){
     this.$api.cloudWatch.checkMonitorModuleIndex({
         "accountId":12
     })
     .then(res => {
         this.logInflow= res.data.logInflow;
         this.logInflowXAxisData= res.data.logInflowXAxisData;
         this.init();
     })
 },
created(){
         this.checkMonitorModuleIndex();
 },
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值