<template>
  <div class="echarts_cap">
    <div :id="`chart_${id}`" style="height: 100%"></div>
  </div>
</template>
<script>
import { pillars } from "@/utils/app-ecahrts";
export default {
  props: {
    id: {
      type: [String, Number],
      default: 1,
    },
    texter: {
      type: Object,
    },
  },
  watch: {
    texter: function (val) {
      if (val) {
        alert(val);
        this.init();
      }
    },
  },
  data() {
    return {};
  },
  // mounted() {
  //   if (this.texter) {
  //     this.init();
  //   }
  // },
  methods: {
    init() {
      let myChart = this.$echarts.init(
        document.getElementById(`chart_${this.id}`)
      ); //统计折线
      pillars.series[0].data = this.texter.data;
      // pillars.title.text = this.texter.name;
      // pillars.title.subtext = this.texter.cont;
      // pillars.title.top = this.texter.top;
      pillars.series[0].color = this.texter.color;
      myChart.clear();
      myChart.setOption(pillars, true);
      // myChart.setOption(pillar);
      window.onresize = () => {
        myChart.resize();
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.echarts_cap {
  width: 100%;
  height: 100%;
}
</style>