<template>
  <div>
    <div id="centerChartLine" style="width: 5.2rem;height: 3rem;"></div>
  </div>
</template>

<script>
import echartMixins from "@/utils/resizeMixins";

export default {
  data() {
    return {
      chart: null
    };
  },
  mixins: [echartMixins],
  mounted() {
    // this.draw();
  },
  methods: {
    draw(data) {
      // 基于准备好的dom，初始化echarts实例
      this.chart = this.$echarts.init(document.getElementById('centerChartLine'));
      let option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },  
        grid: {
          top: '15%',
          left: '8%',
          right: '10%',
          bottom: '0%',
          containLabel: true
        },
        legend: {
          textStyle: {
            color: '#fff'  
          }
        },
        xAxis: {
          type: 'category',
          data: data.timeList,
          axisLabel: {
            show: true,
            textStyle: {
              color: '#fff',  //更改坐标轴文字颜色
              fontSize : 16      //更改坐标轴文字大小
            }
          },
          axisLine:{
            lineStyle: {
              color:'#fff' //更改坐标轴颜色
            }
          }
        },
        yAxis: {
          type: 'value',
          splitLine: { show: false },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#fff',  //更改坐标轴文字颜色
              fontSize : 16      //更改坐标轴文字大小
            }
          },
          axisLine:{
            lineStyle: {
              color:'#fff' //更改坐标轴颜色
            }
          }
        },
        series: [
          {
            name: '温度',
            data: data.tlist,
            type: 'line',
            itemStyle:{
              normal:{
                color:'#9FE0B2', //折点颜色
                lineStyle:{
                  color:'#9FE0B2' //折线颜色
                }
              }
            },
            markPoint: {
              data: [
                {type: 'max', name: '最大值'},
                {type: 'min', name: '最小值'}
              ]
            },
            markLine: {
              data: [
                {type: 'average', name: '平均值'}
              ]
            }
          },
          {
            name: '湿度',
            data: data.hlist,
            type: 'line',
            itemStyle:{
              normal:{
                color:'#5470C6', //折点颜色
                lineStyle:{
                  color:'#5470C6' //折线颜色
                }
              }
            },
            markPoint: {
              data: [
                {type: 'max', name: '最大值'},
                {type: 'min', name: '最小值'}
              ]
            },
            markLine: {
              data: [
                {type: 'average', name: '平均值'}
              ]
            }
          }
        ]
      };
      this.chart.setOption(option);
    }
  },
  destroyed() {
    window.onresize = null;
  }
};
</script>

<style lang="scss" scoped>
</style>