<!--
 * @Author: your name
 * @Date: 2021-10-08 17:24:29
 * @LastEditTime: 2022-01-04 13:21:13
 * @LastEditors: Please set LastEditors
 * @Description: 存栏结构 - 存栏变动折线图
 * @FilePath: \hyyfClient\src\views\PdcData\analysis\ChartInventoryLines.vue
-->
<template>
  <div class="chart-inventory-lines">
    <div id="chartElecLines"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      myChart: null,
    };
  },
  props: {
    data: {
      type: Object,
      required: true,
      default: () => ({}),
    },
  },
  methods: {
    init() {
      let flag = "";
      if (this.data.month.length === 0) {
        flag = "暂无数据";
      }
      let options = {
        title: {
          text: "重量统计",
          x: 65,
          y: 15,
          subtext: flag,
        },
        tooltip: {
          trigger: "axis",
        },
        // legend: {
        //   data: ['头']
        // },
        color: ["#3aa0ff", "#4dcb73", "#fad337", "#f2637b", "#975fe4"],
        grid: {
          top: "20%",
          left: "10%",
          bottom: "10%",
          right: "10%",
        },
        xAxis: [
          {
            type: "category",
            // name: "月",
            data: this.data.month,
            axisPointer: {
              type: "shadow",
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#6e7079",
              },
            },
            axisTick: {
              show: true,
            },
          },
        ],
        //[
        yAxis: {
          type: "value",
          name: "kg",
          // axisLabel: {
          //   formatter: '{value} °C'
          // },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#6e7079",
            },
          },
          axisTick: {
            show: false,
          },
          splitLine: {
            show: false,
          },
        },
        // {
        //   type: 'value',
        //   name: '湿度',
        //   axisLabel: {
        //     formatter: '{value} RH'
        //   },
        //   axisLine: {
        //     show: false,
        //     lineStyle: {
        //       color: '#6e7079',
        //     }
        //   },
        //   axisTick:{
        //     show:false
        //   },
        //   // splitLine:{
        //   //   show:false
        //   // }
        // }
        //],
        series: [
          {
            name: "重量",
            type: "line",
            smooth: false,
            data: this.data.elecList,
            itemStyle: {
              normal: {
                color: "#3aa0ff",
                lineStyle: {
                  color: "#3aa0ff",
                },
              },
            },
          },
          // {
          //   name: '湿度',
          //   type: 'line',
          //   smooth: false,
          //   yAxisIndex: 1,
          //   data: [20, 22, 33, 45, 63, 102, 23, 24, 23, 65, 50, 62]
          // }
        ],
      };
      this.myChart.setOption(options, true);
    },
  },
  mounted() {
    this.myChart = this.$echarts.init(
      document.getElementById("chartElecLines")
    );
    this.init();
  },
  watch: {
    data: {
      handler() {
        this.init();
      },
      deep: true,
    },
  },
};
</script>

<style scoped>
.chart-inventory-lines {
  /* display: inline-block; */
  width: 100%;
  height: 100%;
}
#chartElecLines {
  width: 100%;
  height: 100%;
}
</style>
