
import * as echarts from "echarts";
export default {
  data() {
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        },
      wpIdslist: {
        name: "",
        id: "",
      },
      loading:true,
      loading2:true,
      wtIdslist: {
        name: "麻黄山1号风机",
        id: "MG01_01",
      },
      fc: "MHS_FDC",
      fj: "MG01_01",
      year: "2021",
      month: "12",
      sdtDate: [],
      lineDate:[],
    };
  },
  created() {},
  methods: {
    /**
     * 查询风机风场
     */
    query() {
      this.wtIdslist = [];
      let that = this;
      this.API
        .get("powercompare/windturbineAjax?wpId=" + that.fc)
        .then((res) => {
          this.wtIdslist = res.data;
        });
    },
    query_wpid() {
      let that = this;
      let newData = new Date();
      this.year = newData.getFullYear()+'';
      this.month = newData.getMonth()+''; 
      if(this.month==0){that.month=12;that.year=that.year-1};
      this.API.get("powercompare/windfarmAjax?").then((res) => {
        this.wpIdslist = res.data;
      });
      this.query();
    },
    /**
     * 获取数据
     */
    query_scatter() {
      let sdtDate = [];
      let lineDate = [];
      var digital = new URLSearchParams();
      digital.append("wtId", this.fj);
      digital.append("year", this.year);
      digital.append("month", this.month);
      this.API.postL("/scatter/scatterWtAjax", digital).then((res) => {
        sdtDate = res.data.data.scatter;
        lineDate = res.data.data.line;
        this.draw_scatter_diagram(sdtDate,lineDate);
        this.loading=false;
      });
    },
    /**
     * 画图
     */
    draw_scatter_diagram(a,b) {
      var chartDom = document.getElementById("scatter_diagram");
      var myChart = echarts.init(chartDom);
      var option;

      //echarts.registerTransform(ecStat.transform.regression);

      

      option = {
        title: {
          text: "风机功率排布情况",
        },
        legend: {
          data: ["功率"],
          left: "right",
        },
        
        tooltip: {
          show: false,
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
        },
        xAxis: {
          splitLine: {
            lineStyle: {
              type: "dashed",
            },
          },
          axisLabel: {
            formatter: "{value} m/s",
          },
          splitNumber: 20,
        },
        yAxis: {
          min: -40,
          splitLine: {
            lineStyle: {
              type: "dashed",
            },
          },
          axisLabel: {
            formatter: "{value} 万kw",
          },
        },
        series: [
          {
            name: "功率",
            type: "scatter",
            color: "#FF7F50",
            data : a,
            markPoint: {
              data: [
                { type: "max", name: "最大值" },
                { type: "min", name: "最小值" },
              ],
              symbol: "pin",
              symbolSize: 50,
              silent: true,
            },
            markLine: {
              data: [{ type: "average", name: "平均值" }],
            },
          },
          {
            name: "line",
            type: "line",
            data:b,
            smooth: true,
            datasetIndex: 1,
            symbolSize: 0.1,
            symbol: "circle",
            color: "#87CEFA",
            label: { show: false },
            labelLayout: { dx: -20 },
            encode: { label: 2, tooltip: 1 },
          },
        ],
      };

      option && myChart.setOption(option);
    },
  },
  mounted() {
    this.query_wpid();
    this.query_scatter();
  },
};
