<!--
 * @Author: zwq
 * @Date: 2022-01-21 14:43:06
 * @LastEditors: DY
 * @LastEditTime: 2024-05-30 14:52:05
 * @Description:
-->
<template>
  <!-- <div> -->
  <!-- <div :id="id" :class="className" :style="{ height: '65%', width:width}" /> -->
  <div :id="id" :class="className" :style="{ height: height, width: width }" />
  <!-- </div> -->
</template>

<script>
import * as echarts from 'echarts'
import 'echarts/theme/macarons' // echarts theme
import resize from '@/mixins/resize'
export default {
  name: 'OverviewBar',
  mixins: [resize],
  props: {
    id: {
      type: String,
      default: 'reportChart'
    },
    className: {
      type: String,
      default: 'reportChart'
    },
    width: {
      type: String,
      default: '100%'
    },
    beilv: {
      type: Number,
      default: 1
    },
    height: {
      type: String,
      default: '30vh'
    },
    legendPosition: {
      type: String,
      default: 'center'
    },
    showLegend: {
      type: Boolean,
      default: false
    },
    legendData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      chart: null
    }
  },
  // mounted() {
  //   this.$nextTick(() => {
  //     this.initChart()
  //   })
  // },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart(xAxis, seriesList) {
      this.chart = echarts.init(document.getElementById(this.id))
      console.log(this.$parent);
      this.chart.setOption({
        title: {
          text: '',
          // subtext: 'Fake Data'
        },
        tooltip: {
          trigger: 'axis'
        },
        grid: { top: 100, right: 90, bottom: 10, left: 10, containLabel: true },
        legend: {
          // data: ['工厂1', '工厂2'],
          right: '90px',
          top: '0%',
          icon: 'rect',
          itemWidth: 10,
          itemHeight: 10,
          itemGap: 40,
        },
        // toolbox: {
        //   show: true,
        //   feature: {
        //     dataView: { show: true, readOnly: false },
        //     magicType: { show: true, type: ['line', 'bar'] },
        //     restore: { show: true },
        //     saveAsImage: { show: true }
        //   }
        // },
        calculable: true,
        xAxis: [
          {
            type: 'category',
            // prettier-ignore
            data: xAxis
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        grid: {
          top: '20%',
          left: "1%",
          right: "3%",
          bottom: "1%",
          containLabel: true
        },
        series: seriesList
      }, true)
    }
  }
}
</script>

<style scoped>
/* .reportChart {
  position: absolute;
  height: 100%;
  width: 100%;
  top: 10px;
} */
</style>
