<!--
 * @Author: zwq
 * @Date: 2022-01-21 14:43:06
 * @LastEditors: zhp
 * @LastEditTime: 2024-04-17 10:03:39
 * @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() {
      console.log(1111)
      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: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        grid: {
          top: '20%',
          left: "1%",
          right: "3%",
          bottom: "1%",
          containLabel: true
        },
        series: [
          {
            name: '工厂1',
            type: 'bar',
            itemStyle: {
              normal: {
                color: 'rgba(99, 189, 255, 1)', //改变折线点的颜色
                lineStyle: {
                  color: 'rgba(99, 189, 255, 1)' //改变折线颜色
                }
              }
            },
            data: [
              2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3
            ],
          },
          {
            name: '工厂2',
            type: 'bar',
            itemStyle: {
              normal: {
                color: 'rgba(142, 240, 171, 1)', //改变折线点的颜色
                lineStyle: {
                  color: 'rgba(142, 240, 171, 1)' //改变折线颜色
                }
              }
            },
            data: [
              2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3
            ],
          },
        ]
      })
    }
  }
}
</script>

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