一個頁面多個echarts圖表自適應


methods 方法

    // 訂單Echarts
    drawOrder () {
      this.charts = echarts.init(document.getElementById('order'))
      // 繪制圖表
      this.charts.setOption({
        title: {
          text: '',
          subtext: '',
          left: 'center'
        },
        tooltip: {
          trigger: 'item',
        },
        // legend: {
        //   orient: 'horizontal',
        //   left: 'top',
        //   data: ['直接訪問', '郵件營銷', '聯盟廣告', '視頻廣告', '搜索引擎']
        // },
        series: [
          {
            name: '訂單數量',
            type: 'pie',
            radius: '70%',
            center: ['50%', '60%'],
            data: [
              { value: 335, name: '直接訪問' },
              { value: 310, name: '郵件營銷' },
              { value: 234, name: '聯盟廣告' },
              { value: 135, name: '視頻廣告' },
              { value: 1548, name: '搜索引擎' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      });
    },

自適應

在需要window.onresize的函數內直接使用echarts.init()去取:

  mounted () {
    this.$nextTick(function () {
      // 圖表自適應
      window.onresize = function () {
       echarts.init(document.getElementById("order")).resize();
        echarts.init(document.getElementById("ranking")).resize();
      };
      this.drawOrder()
      this.drawRanking()
    });
  },

 借鑒:https://www.pianshen.com/article/5586274051/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM