<template>
  <div @click="openSteamUsed">
    <div id="bottomRightChart2" style="width:100%;height:2.6rem;">
    </div>
    <el-dialog  :close-on-click-modal="false" class="my-info-dialog" :visible.sync="openChart" title="瞬时值" @open="open" width="1600px" destroy-on-close append-to-body>
      <div id="bottomRightChart2Dialog" style="width:100%;height:600px;"></div>
    </el-dialog>
  </div>
</template>

<script>
import echartMixins from "@/utils/resizeMixins";
import echarts from "@/api/cpms/echarts.min";

export default {
  props: ['latest24HourData'],
  data() {
    return {
      chart:null,
      openChart: false,
    };
  },
  mixins: [echartMixins],
  mounted() {
    this.draw();
  },
  methods: {
    openSteamUsed(){
      this.openChart = true
    },
    open(){
      this.$nextTick(() => {
        this.drawDialog()
      })
    },
    draw() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = this.echarts.init(document.getElementById('bottomRightChart2'))
      // let lineData = [
      //   820, 932, 901, 934, 1290, 1330, 1320
      // ];

      let hourArray = [];
      let gasArray = [];
      let data = this.latest24HourData;
      for (let i = 0; i < data.length; i++) {
        let pullDate = new Date(data[i].pullDate);
        hourArray.push(pullDate.getHours() + ":00");
        gasArray.push(data[i].gasRealTime);
      }
      if (hourArray.length > 12) {
        hourArray = hourArray.slice(0, 12);
        gasArray = gasArray.slice(0, 12);
      }
      hourArray.reverse();
      gasArray.reverse();

      let option={
        legend:{
          orient:'horizontal',
          x: 'left',
          y: 'top',
        },
        grid: {
          top: '16%',   // 等价于 y: '16%'
          left: '3%',
          right: '8%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          axisLine: {
            lineStyle: {
              // 设置x轴颜色
              color: '#ffffff'
            }
          },
          axisLabel: {
            rotate: 0, // 旋转角度
            interval: 1  //设置X轴数据间隔几个显示一个，为0表示都显示
          },
          boundaryGap: false,
          type: 'category',
          data: hourArray
        },
        yAxis: {
          type: 'value',
          name: 'Units:(Nm³)',
          axisLine: {
            lineStyle: {
              // 设置x轴颜色
              color: '#ffffff'
            }
          },
        },
        series: [
          {
            data: gasArray,
            type: 'line',
            smooth: 0.5,
            symbolSize: 10,
            areaStyle:{
              color:new echarts.graphic.LinearGradient(0,0,0,1,[{
                offset:0,
                color:'#92bda6',
              },{
                offset: 1,
                color: '#2480bb'
              }
              ])
              },
            itemStyle: {
              normal: {
                lineStyle:{
                  width:1,
                  type:'solid'
                },
                borderColor:'red',
                color: "#92bda6"
              }
            },
          },

          // {
          //   name: 'HP',
          //   type: "bar",
          //   barGap: "-100%",
          //   stack: 'Ad',
          //   barWidth: 10,
          //   itemStyle: {
          //     normal: {
          //       barBorderRadius: 5,
          //       color: new this.echarts.graphic.LinearGradient(0, 0, 0, 1, [
          //         { offset: 0, color: "#956FD4" },
          //         { offset: 1, color: "#3EACE5" }
          //       ])
          //     }
          //   },
          //   z: -12,
          //   data: lineData
          // },
        ]
      }
      this.chart.setOption(option);
    },
    drawDialog() {
      // 基于准备好的dom，初始化echarts实例
      this.chart1 = this.echarts.init(document.getElementById('bottomRightChart2Dialog'))
      // let lineData = [
      //   820, 932, 901, 934, 1290, 1330, 1320
      // ];
      let hourArray = [];
      let gasArray = [];
      let data = this.latest24HourData;
      for (let i = 0; i < data.length; i++) {
        let pullDate = new Date(data[i].pullDate);
        hourArray.push(pullDate.getHours() + ":00");
        gasArray.push(data[i].gasRealTime);
      }
      if (hourArray.length > 12) {
        hourArray = hourArray.slice(0, 12);
        gasArray = gasArray.slice(0, 12);
      }
      hourArray.reverse();
      gasArray.reverse();
      let option={
        legend:{
          orient:'horizontal',
          x: 'left',
          y: 'top',
        },
        grid: {
          top: '16%',   // 等价于 y: '16%'
          left: '3%',
          right: '8%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          axisLine: {
            lineStyle: {
            }
          },
          type: 'category',
          data: hourArray
        },
        yAxis: {
          type: 'value',
          name: 'Units:(Nm³)',
          axisLine: {
            lineStyle: {
            }
          },
        },
        series: [
          {
            data: gasArray,
            type: 'line',
            smooth: 0.5,
            symbolSize: 10,
            label: {
              show: true,
              position: 'top'
            },
            areaStyle:{
              color:new echarts.graphic.LinearGradient(0,0,0,1,[{
                offset:0,
                color:'#92bda6',
              },{
                offset: 1,
                color: '#2480bb'
              }
              ])
            },
            itemStyle: {
              normal: {
                lineStyle:{
                  width:1,
                  type:'solid'
                },
                borderColor:'red',
                color: "#92bda6"
              }
            },
          },
        ]
      }
      this.chart1.setOption(option);
    }
  },
}
</script>

<style scoped>

</style>
