<!--
 * @Author: your name
 * @Date: 2021-10-08 17:24:29
 * @LastEditTime: 2021-12-02 10:18:24
 * @LastEditors: Please set LastEditors
 * @Description: 存栏结构 - 存栏变动折线图
 * @FilePath: \hyyfClient\src\views\PdcData\analysis\ChartInventoryLines.vue
-->
<template>
  <div class="chart-inventory-lines">
    <div id="chartLines"></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 = "暂无数据";
      }
      console.log("日期为-------------", this.data.month);
      let options = {
        title: {
          text: "存栏变动",
          x: 10,
          y: 0,
          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: "头",
          // 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.sowStock,
            itemStyle: {
              normal: {
                color: "#3aa0ff",
                lineStyle: {
                  color: "#3aa0ff",
                },
              },
            },
          },
          {
            name: "头",
            type: "line",
            smooth: false,
            data: this.data.boarStock,
            itemStyle: {
              normal: {
                color: "#4dcb73",
                lineStyle: {
                  color: "#4dcb73",
                },
              },
            },
          },
          {
            name: "头",
            type: "line",
            smooth: false,
            data: this.data.griceStock,
            itemStyle: {
              normal: {
                color: "#fad337",
                lineStyle: {
                  color: "#fad337",
                },
              },
            },
          },
          {
            name: "头",
            type: "line",
            smooth: false,
            data: this.data.pigletStock,
            itemStyle: {
              normal: {
                color: "#f2637b",
                lineStyle: {
                  color: "#f2637b",
                },
              },
            },
          },
          {
            name: "头",
            type: "line",
            smooth: false,
            data: this.data.fatpigStock,
            itemStyle: {
              normal: {
                color: "#975fe4",
                lineStyle: {
                  color: "#975fe4",
                },
              },
            },
          },
          // {
          //   name: '湿度',
          //   type: 'line',
          //   smooth: false,
          //   yAxisIndex: 1,
          //   data: [20, 22, 33, 45, 63, 102, 23, 24, 23, 65, 50, 62]
          // }
        ],
      };
      this.myChart.setOption(options);
    },
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById("chartLines"));
    // this.init();
  },
  watch: {
    data: {
      handler(newValue) {
        console.log(newValue);
        this.init();
      },
      deep: true,
    },
  },
};
</script>

<style scoped>
.chart-inventory-lines {
  display: inline-block;
  width: 50%;
  height: 280px;
}
#chartLines {
  width: 100%;
  height: 100%;
}
</style>
