<template>
  <div class="e-echarts-line">
    <div :id="eId" :style="styles"></div>
  </div>
</template>
<script>
import * as echarts from "echarts";
export default {
  name: "EEchartsBar",
  props: {
    eId: {
      type: String
    },
    styles: {
      type: String
    },
    colorList: {
      type: [Array, String],
      default: ""
    },
    option: {
      stype: Object,
      default: {}
    }
  },
  data() {
    return {
      chart: null
    };
  },
  created() {
    this.chart = null;
  },
  mounted() {
    this.drawBar();
  },
  methods: {
    updateEchart() {
      if (this.chart) {
        this.chart = null;
      }
      this.drawBar();
    },
    drawBar() {
      if (!this.chart) {
        this.chart = echarts.init(document.getElementById(this.eId));
      }
      this.chart.setOption(this.option);
    }
  },
  watch: {
    option: {
      handler(val) {
        if (val) {
          this.chart = null;
          this.drawBar();
        }
      },
      deep: true
    }
  }
};
</script>
<style lang="scss">
.e-echarts-line {
  position: relative;
  height: 100%;
  top: 0px;
  width: 100%;
}
</style>
