<template>
  <div
    id="right"
    style="width: 100%; height: 100%;"

    ref="fg13"
    v-loading="isLoading"
  ></div>
</template>

<script>
import { getEventFeatureAmplitudeLineChart } from "@/api/Statistical-analysis/transientIndicators/transientIndicators";
export default {
  props: {
    form: {
      type: Object,
      default: undefined,
    },
  },
  data() {
    return {
      device: null,
      zoom: undefined, //图表焦点校验
      h: null,
      isLoading: false,
      dataListX: [],
      dataListY: [],
    };
  },
  created() {},
  mounted() {
    this.zoom = 1 / document.body.style.zoom;
    window.addEventListener("resize", () => {
      this.zoom = 1 / document.body.style.zoom;
    });
    this.$nextTick(() => {
      this.echarts();
    });

    //   console.log(this.time[0],'1234567');
  },
  updated() {},
  methods: {
    async echarts() {
      this.isLoading = true;
      this.dataListX = [];
      this.dataListY = [];
      const data = await getEventFeatureAmplitudeLineChart(this.form);
      data.data.forEach((item) => {
        this.dataListX.push(item.name);
        this.dataListY.push(item.value);
      });
      this.isLoading = false;
      let echarts = require("echarts");
      let domID1 = document.getElementById("right");
      setTimeout(()=>{
        domID1.style.width = (window.sessionStorage.getItem('appwidth') - 80)/3 +'px'
        domID1.style.height = (window.sessionStorage.getItem('appheight')-185)/2 + 'px'
      },0)
      let echartsColor = JSON.parse(window.localStorage.echartsColor);
      let myChart = echarts.init(domID1);
      let option = {
        title: {
          text: "暂降幅值的概率分布函数 ",
          left: "center",
          top: 0,
          textStyle: {
            color: echartsColor.WordColor,
          },
        },
        tooltip: {
          //提示框组件
          trigger: "axis",

          axisPointer: {
            type: "shadow",
            label: {
              color: "#fff",
              fontSize: 16,
            },
          },
          textStyle: {
            color: "#fff",
            fontStyle: "normal",
            opacity: 0.35,
            fontSize: 14,
          },
          backgroundColor: "rgba(0,0,0,0.35)",
          borderWidth: 0,
        },
        grid: {
          top: "40px",
          left: "40px",
          bottom: "40px",
          right: "40px",
        },
        xAxis: {
          type: "category",
          data: this.dataListX,
          name: "暂降幅值",
          nameLocation: "middle",
          nameTextStyle: {
            color: echartsColor.WordColor,
            padding: 5,
          },
          boundaryGap: false,
          axisTick: { show: false },

          axisLine: {
            lineStyle: {
              color: echartsColor.thread,
            },
          },
          axisLabel: {
            color: echartsColor.WordColor,
          },
        },
        yAxis: {
          name: "概率分布",
          nameGap: '20',
          nameTextStyle: {
            color: echartsColor.WordColor,
            padding: 0,
          },
          minInterval: 1,
          type: "value",
          axisLine: {
            show: true,
            lineStyle: {
              color: echartsColor.thread,
            },
          },
          axisLabel: {
            color: echartsColor.WordColor,
          },
          splitLine: {
            lineStyle: {
              // 使用深浅的间隔色
              color: [echartsColor.thread],
              type: "dashed",
              opacity: 0.5,
            },
          },
        },
        series: [
          {
            data: this.dataListY,
            type: "line",
            itemStyle: {
              normal: { show: true, color: echartsColor.FigureColor[0] },
            },
            label: {
              show: true,
              position: "top",
              textStyle: {
                //数值样式
                color: echartsColor.WordColor,
              },
              fontSize: 12,
            },
          },
        ],
      };
      myChart.setOption(option)
window.echartsArr.push(myChart);
      // myChart.resize();
      let _this = this;
      _this.$erd.listenTo(_this.$refs.fg13, (element) => {
        _this.$nextTick(() => {
          myChart.resize();
        });
      });
      window.onresize = function () {
        myChart.resize();
      };
    },
  },
};
</script>

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