<template>
  <div :id="'chartDl-' + id" style="width: 100%; height: 100%"></div>
</template>

<script>
import { mapState } from 'vuex';
export default {
  name: "ChartDl",
  props: {
    id: {
      type: String,
      default: () => '0'
    }
  },
  computed: {
    ...mapState(['color'])
  },
  data() {
    return {
      myChart: null
    }
  },
  watch: {
    color(newVal) {
      if(newVal) {
        this.myChart.clear();
        this.init()
      }
    }
  },
  methods: {
    init() {
      let dataAxis = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', '测试月'];
      let start = dataAxis.length - 12;
      let end = dataAxis.length - 1;
      let options = {
        tooltip: {
          trigger: 'axis',
        },
        color: [this.color],
        dataZoom: [{
          type: 'inside',
          startValue: start,
          endValue: end,
          show: false
          // zoomOnMouseWheel: false,
          // zoomLock: true,
        }],
        // dataZoom: [
        //
        //   {
        //     type: 'slider',
        //     startValue: start,
        //     endValue:end,
        //     zoomOnMouseWheel: false,
        //     zoomLock: true,
        //   },
        //   {
        //     type: 'inside'
        //   },
        // ],
        xAxis: [
          {
            type: 'category',
            data: dataAxis,
            axisPointer: {
              type: 'shadow'
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: '#6e7079',
              }
            },
            axisTick:{
              show:false
            },
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '电量统计情况',
            axisLabel: {
              formatter: '{value} KW·h'
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: '#6e7079',
              }
            },
            axisTick:{
              show:false
            },
          }
        ],
        series: [
          {
            name: '电量',
            type: 'line',
            // stack: 'Total',
            smooth: true,
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            itemStyle : {
              color: this.color,
              borderColor: this.color,
              normal: {
                label : {
                  show: true,
                  textStyle: {
                    fontSize: 14
                  }
                }
              }
            },
            data: [120, 132, 101, 134, 90, 230, 210, 210, 245, 203, 124, 214, 210]
          }
        ]
      }
      this.myChart.setOption(options)
    }
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById('chartDl-' + this.id));
    this.init()
  }
}
</script>

<style scoped>

</style>
