ercharts遇到的情况创建销毁自适应

81 阅读1分钟

b7c4b0c8f57dd34ed357b4ea1737341.jpg

     切换你图表是销毁再创建的吗 
     如果页面有多个图表  两个if不可以在一个if里面写 我之前在if两个实例是或关系或导致下面的图表不可以resize 
      // 销毁eacharts
      beforeDestroy() {
        if (this.wgbarEcharts) {
          console.log("系统");
          this.wgbarEcharts.dispose();
        }
        if (this.wglineEcharts) {
          this.wglineEcharts.dispose();
        }
      },
       mounted() {
// 切换下拉框数据
    this.$nextTick(() => {
      this.switchFile();
    });
    var that = this;
    window.addEventListener("resize", () => {
      if (that.wgbarEcharts) {
        that.wgbarEcharts.resize();
      }
      if (that.wglineEcharts) {
        that.wglineEcharts.resize();
      }
    });
  },
      initLine(data) {
  this.wglineEcharts = echarts.init(this.$refs.assetSafty, "macarons");
  //随着屏幕大小调节图表
  this.wglineEcharts.setOption({
    tooltip: {
      trigger: "axis",
    },
    //   legend: {
    //     data: ["低危", "中危", "高危"],
    //   },
    grid: {
      top: "10%",
      left: "3%",
      right: "4%",
      bottom: "15%",
      containLabel: true,
    },
    toolbox: {},
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: data.map((r) => r.name),
    },
    yAxis: {
      type: "value",
    },
    series: [
      {
        type: "line",
        stack: "Total",
        data: data,
      },
    ],
  });
},

}, 350167f85c2fbf2eba34c6d2acbea82.jpg