<template>
  <el-row>
    <div id="index3" style="width:100%;height:100%;"></div>
  </el-row>
</template>
<script>
import * as echarts from "echarts";
export default {
  props: ["resData"],
  data() {
    return {};
  },
  watch: {
    resData() {
      this.getData();
    }
  },
  methods: {
    getData() {
      let chartDom = document.getElementById("index3");
      let myChart = echarts.init(chartDom);
      let data = this.resData;
      let seriesData = [];
      let lineData = [];
      let date = new Date();
      for (let i = 0; i < data.length; i++) {
        lineData.push(data[i].time);
      }
      for (let i = 0; i < data[0].list.length; i++) {
        seriesData[i] = {data:[],name:undefined};
        seriesData[i].name = data[0].list[i].deviceTypeS;
        for (let a = 0; a < data.length; a++) {
          seriesData[i].data.push(data[a].list[i].deviceCount);
        }
      }
      let series = []; //定义一个数组变量用于存放配置
      let colorShown= [
        {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [

              {
                offset: 0,
                color: 'rgb(255, 0, 135)'
              },
              {
                offset: 1,
                color: 'rgb(135, 0, 157)'
              }
          ])
        },
        {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
                offset: 0,
                color: 'rgb(0, 221, 255)'
              },
              {
                offset: 1,
                color: 'rgb(77, 119, 255)'
              }

          ])
        },
        {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: 'rgb(55, 162, 255)'
              },
              {
                offset: 1,
                color: 'rgb(116, 21, 219)'
              }
          ])
        },
        {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [

               {
                offset: 0,
                color: 'rgb(128, 255, 165)'
              },
              {
                offset: 1,
                color: 'rgb(1, 191, 236)'
              }
          ])
        },
        {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [

              {
                offset: 0,
                color: 'rgb(255, 191, 0)'
              },
              {
                offset: 1,
                color: 'rgb(224, 62, 76)'
              }
          ])
        }
      ]
      for (var i = 0; i < data[0].list.length; i++) {
        series.push(
          {
            name: seriesData[i].name,
            type: 'line',
            stack: 'Total',
            smooth: true,
            lineStyle: {
              width: 0
            },
            showSymbol: false,
            areaStyle: colorShown[i],
            emphasis: {
              focus: 'series'
            },
            data: seriesData[i].data
          }
        );
      }
      let option = {
        legend: {
          itemGap: 6, // 图例每项之间的间隔。
          icon: "stack",
          padding: 0, // 图例内边距
          textStyle: {
            color: "#000",
            align: "center"
          }
        },
        color: ['#FF0087', '#00DDFF', '#37A2FF', '#80FFA5', '#FFBF00'],
        grid: {
          bottom: "0",
          right: "10",
          left: "10",
          top: "35",
          containLabel: true
        },
        tooltip: {
          trigger: "axis",
          confine: true,
          textStyle: {
            fontSize: 12
          }
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          // data: ["12：00", "13：00", "14：00", "15：00", "16：00", "17：00"],
          data: lineData,
          axisLabel: {
            color: "#6F99FA"
          },
          axisLine: {
            lineStyle: {
              color: "rgba(0,130,255,.2)"
            }
          },
          axisTick: {
            show: false
          }
        },
        yAxis: {
          type: "value",
          axisLabel: {
            color: "#6F99FA"
          },
          axisTick: {
            show: false
          },
          axisLine: {
            lineStyle: {
              color: "rgba(0,130,255,.2)"
            }
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255,255,255,.1)"
            }
          }
        },
        series: series
      };
      option && myChart.setOption(option);
      setTimeout(function (){
          window.onresize = function () {
            myChart.resize();
          }
      },200)
    }
  }
};
</script>

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