import { EleResize } from '../funTools/self-adaption/ezresize.js'
import echarts from 'echarts'
export default {
  data() {
    return {
      chart: null
    }
  },
  beforeDestroy() {
    this.offEchartsListener(this.elId, this.eachartResize)
  },
  methods: {
    drawEcharts(id, option) {
      const dom = document.getElementById(id)
      this.chart = echarts.init(dom)
      this.chart.setOption(option)
      //   const listener = _ => {
      //     chart.resize()
      //   }
      //   EleResize.on(dom, listener)
      EleResize.on(dom, this.eachartResize)
      return this.chart
    },
    eachartResize() {
      this.chart.resize()
    },
    offEchartsListener(id, handle) {
      const dom = document.getElementById(id)
      EleResize.on(dom, handle)
    }
  }
}
