<!--
 * @Author: your name
 * @Date: 2021-10-25 16:13:34
 * @LastEditTime: 2021-10-25 16:55:38
 * @LastEditors: Please set LastEditors
 * @Description: 折线图
 * @FilePath: \hyyfScreen\src\views\Zoology\charts\ChartLine.vue
-->
<template>
  <div :id="'chartLine' + id" class="chart-line">

  </div>
</template>
<script>
export default {
  props: {
    id: {
      type: Number
    },
    data: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      myChart: null
    }
  },
  methods: {
    init() {
      let options = {
        // title: {
        //   text: '存栏变动',
        //   x: 10,
        //   y: 0
        // },
        tooltip: {
          trigger: 'axis',
        },
        // legend: {
        //   data: ['头']
        // },
        // color: ['#3aa0ff', '#4dcb73', '#fad337', '#f2637b', '#975fe4'],
        grid: {
          top: '10%',
          left: '10%',
          bottom: '20%',
          right: '10%'
        },
        xAxis: [
          {
            type: 'category',
            // name: this.data.xAxisName,
            data: this.data.xAxisData,
            axisPointer: {
              type: 'shadow'
            },
            axisLabel: {
              textStyle: {
                color: '#fff'
              }
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgb(0, 255, 255)',
              }
            },
            axisTick:{
              show: false
            },
          }
        ],
        yAxis: //[
          {
            type: 'value',
            name: this.data.yAxisName,
            nameTextStyle: {
              color: 'red'
            },
            axisLabel: {
              textStyle: {
                color: '#fff'
              },
              formatter: '{value}' + this.data.yAxisName
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgb(0, 255, 255)',
              }
            },
            axisTick:{
              show:false
            },
            splitLine:{
              show:false
            }
          },
        //],
        series: [
          {
            name: this.data.xAxisName,
            type: 'line',
            smooth: false,
            data: this.data.yAxisData,
            itemStyle: {
              normal: {
                color: '#3aa0ff',
                lineStyle: {
                  color: '#3aa0ff'
                }
              }
            }
          }
        ]
      }
      this.myChart.setOption(options);
    }
  },
  mounted() {
    this.myChart = this.$echarts.init(document.getElementById('chartLine' + this.id));
    this.init();
  },
  watch: {
    data: {
      handler(newVal) {
        if(newVal) {
          this.myChart.clear();
          this.init();
        }
      },
      deep: true,
    }
  }
}
</script>
<style scoped>
.chart-line {
  width: 100%;
  height: 160px;
}
</style>
