tab切换时,echart图显示宽度问题,以及自适应屏幕法缩小。

  mounted () {
    this.drawLine()
  },
  methods: {
    drawLine () {
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById('myChart'))
      // 绘制图表
      myChart.setOption({
        title: {
          text: 'XXXXXX',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '收入类型分布<br/>{b} : {c} ({d}%)'
        },
        legend: {
          bottom: 10,
          left: 'center',
          data: ['1', '2', '3,'4', '其他']
        },
        series: [{
          type: 'pie',
          radius: '65%',
          center: ['50%', '50%'],
          selectedMode: 'single',
          data: [
            {value: 100, name: '1'},
            {value: 120, name: '2'},
            {value: 300, name: '3'},
            {value: 260, name: '4'},
            {value: 80, name: '其他'}
          ]
        }]
      })

      window.addEventListener('resize', function () {    //自适应屏幕大小
        myChart.resize()
      })
    },
    }
 <el-tabs v-model="activeName" type="card" @tab-click="handleClick"> 
 handleClick (tab, event) {     //点击tab切换时 重新调用显示图( this.$nextTick) 防止echart图宽度问题
      console.log(tab.index)
      if (tab.index == 0) {
        this.$nextTick(() => {
          this.drawLine()
          this.draw2()
        })
      } else if (tab.index == 1) {
        this.$nextTick(() => {
          this.draw3()
          this.draw4()
        })
      } else {
        this.$nextTick(() => {
          this.draw5()
          this.draw6()
        })
      }
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值