浏览代码

修改获取预警的markArea

littleblue55 4 周之前
父节点
当前提交
586b559504

+ 26 - 10
src/views/dashboard/sandianpredict.vue

@@ -65,8 +65,12 @@
             {{ selectedModel }}
           </div>
         </el-form-item>
-        <el-form-item  style="margin-bottom: 0">
-          <el-button type="primary" icon="el-icon-search" @click="updateChart" size="mini"
+        <el-form-item style="margin-bottom: 0">
+          <el-button
+            type="primary"
+            icon="el-icon-search"
+            @click="updateChart"
+            size="mini"
             >搜索</el-button
           >
         </el-form-item>
@@ -82,7 +86,7 @@ import { listPredict } from "@/api/predict/predict";
 import { listBase_data_month } from "@/api/base_data_month/base_data_month";
 require("echarts/theme/macarons");
 import resize from "./mixins/resize";
-
+import { Decimal } from "decimal.js";
 export default {
   mixins: [resize],
   props: {
@@ -350,23 +354,24 @@ export default {
           ]);
           break;
       }
-      // littlegreen - 获取预警的markArae
+      // littlegreen - 获取预警的markArea
       function getErrorArray(flag, yValues, monthYValues, xValues) {
         if (flag == 0) {
           return [];
         }
         const errorArray = [];
+        const error = new Decimal(that.errorVal);
         yValues.forEach((yValue) => {
-          const yVal = yValue[0];
+          const yVal = new Decimal(yValue[0]);
           const month = yValue[1];
           // 在 base_data_monthYValues 中找到相应的月
           const baseData = monthYValues.find((base) => base[1] === month);
           if (baseData) {
-            const baseVal = baseData[0];
+            const baseVal = new Decimal(baseData[0]);
             // 计算差值
-            const difference = Math.abs(baseVal - yVal);
+            const difference = yVal.minus(baseVal);
             // 如果差值大于10,添加该月到新数组
-            if (difference > that.errorVal) {
+            if (difference.gt(error)) {
               // 10-90 80分成xValues.length份
               errorArray.push([
                 {
@@ -388,7 +393,18 @@ export default {
         });
         return errorArray;
       }
-
+      // console.log(yValues, base_data_monthYValues);
+      // base_data_monthYValues = [
+      //   [1096, "2"],
+      //   [563, "3"],
+      //   [1053, "4"],
+      //   [737, "5"],
+      //   [1043, "6"],
+      //   [980, "7"],
+      //   [1428, "8"],
+      //   [1098, "9"],
+      // ];
+      // yValues = [[823.04, "10"],[1000, "9"]];
       this.chart.setOption(
         {
           legend: {
@@ -443,8 +459,8 @@ export default {
                 },
                 data: getErrorArray(
                   flag,
-                  yValues,
                   base_data_monthYValues,
+                  yValues,
                   xValues
                 ),
               },

+ 10 - 8
src/views/dashboard/sandianpredictseason.vue

@@ -82,6 +82,7 @@ import { listPredict } from "@/api/predict_season/predict_season";
 import { listBase_data_season } from "@/api/base_data_season/base_data_season";
 require("echarts/theme/macarons");
 import resize from "./mixins/resize";
+import { Decimal } from "decimal.js";
 
 export default {
   mixins: [resize],
@@ -214,7 +215,7 @@ export default {
           // 获取实际数据
           listBase_data_season(this.queryParams).then((response) => {
             this.base_data_seasonData = response.rows;
-            console.log("vvv" + this.base_data_seasonData.length);
+            // console.log("vvv" + this.base_data_seasonData.length);
             this.initChart();
           });
         })
@@ -332,24 +333,25 @@ export default {
           ]);
           break;
       }
-      // littlegreen - 获取预警的markArae
+      // littlegreen - 获取预警的markArea
       function getErrorArray(flag, yValues, monthYValues, xValues) {
         if (flag == 0) {
           return [];
         }
         const errorArray = [];
+        const error = new Decimal(that.errorVal);
+        // console.log(yValues, monthYValues,"实际和预测")
         yValues.forEach((yValue) => {
-          const yVal = yValue[0];
+          const yVal = new Decimal(yValue[0]);
           const month = yValue[1];
-          console.log(yVal,month)
           // 在 base_data_monthYValues 中找到相应的月
           const baseData = monthYValues.find((base) => base[1] === month);
           if (baseData) {
-            const baseVal = baseData[0];
+            const baseVal = new Decimal(baseData[0]);
             // 计算差值
-            const difference = Math.abs(baseVal - yVal);
+            const difference = yVal.minus(baseVal);
             // 如果差值大于10,添加该月到新数组
-            if (difference > that.errorVal) {
+            if (difference.gt(error)) {
               // 10-90 80分成xValues.length份
               errorArray.push([
                 {
@@ -447,8 +449,8 @@ export default {
               },
               data: getErrorArray(
                 flag,
-                yValues,
                 base_data_seasonYValues,
+                yValues,
                 xValues
               ),
             },

+ 23 - 17
src/views/dashboard/sandianpredictyear.vue

@@ -65,9 +65,14 @@
             {{ selectedModel }}
           </div>
         </el-form-item>
-        <el-form-item  style="margin-bottom: 0">
-          <el-button type="primary" icon="el-icon-search" @click="updateChart" size="mini"
-            >搜索</el-button>
+        <el-form-item style="margin-bottom: 0">
+          <el-button
+            type="primary"
+            icon="el-icon-search"
+            @click="updateChart"
+            size="mini"
+            >搜索</el-button
+          >
         </el-form-item>
       </el-form>
     </div>
@@ -82,7 +87,7 @@ import { listBase_data_year } from "@/api/base_data_year/base_data_year";
 require("echarts/theme/macarons");
 import resize from "./mixins/resize";
 import basicInfoFormVue from '../tool/gen/basicInfoForm.vue';
-
+import { Decimal } from "decimal.js";
 export default {
   mixins: [resize],
   props: {
@@ -343,23 +348,24 @@ export default {
           break;
       }
 
-      // littlegreen - 获取预警的markArae
-      function getErrorArray(flag, yValues, monthYValues, xValues) {
+      // littlegreen - 获取预警的markArea
+      function getErrorArray(flag, monthYValues, yValues, xValues) {
+        // console.log(yValues, monthYValues,flag)
         if (flag == 0) {
           return [];
         }
         const errorArray = [];
-        yValues.forEach((yValue) => {
-          const yVal = yValue[0];
-          const month = yValue[1];
-          // 在 base_data_monthYValues 中找到相应的月
-          const baseData = monthYValues.find((base) => base[1] === month);
+        const error = new Decimal(that.errorVal);
+        monthYValues.forEach(monthYValue => {
+          const yVal = new Decimal(monthYValue[0]);
+          const month = monthYValue[1];
+          const baseData = yValues.find((base) => base[1] === month);
           if (baseData) {
-            const baseVal = baseData[0];
-            // 计算差值
-            const difference = Math.abs(baseVal - yVal);
-            // 如果差值大于10,添加该月到新数组
-            if (difference > that.errorVal) {
+            const baseVal = new Decimal(baseData[0]);
+            // console.log(yVal,baseVal)
+            const difference = yVal.minus(baseVal);
+            // console.log(difference.toNumber(),error)
+            if (difference.gt(error)) {
               errorArray.push([
                 {
                   x: 10 + (80 / (xValues.length)) * (xValues.indexOf(month+"年")) + "%",
@@ -456,7 +462,7 @@ export default {
               itemStyle: {
                 color: "rgba(255, 173, 177, 0.4)",
               },
-              data: getErrorArray(flag, yValues, base_data_yearYValues, xValues),
+              data: getErrorArray(flag, base_data_yearYValues, yValues, xValues),
             },
             // itemStyle: {
             //   // color: "rgba(245,0,0,0.6)",