Browse Source

2022-01-12

East 3 years ago
parent
commit
d274774069

+ 19 - 31
src/views/PdcData/analysis/ChartInventoryPie.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2021-09-30 15:46:57
- * @LastEditTime: 2021-12-09 17:20:30
+ * @LastEditTime: 2022-01-12 15:07:13
  * @LastEditors: Please set LastEditors
  * @Description: 存栏结构图
  * @FilePath: \hyyfClient\src\views\PdcData\analysis\ChartInventoryPie.vue
@@ -26,11 +26,24 @@ export default {
   },
   methods: {
     init() {
-      const _this = this;
       let total = this.data.reduce(
         (prev, item) => prev + item.stockQuantity,
         0
       );
+      const clientLabels = [];
+      // 将右侧文字备注放上去
+      this.data.forEach((item) => {
+        let percentStr = "";
+        if (item.stockQuantity !== 0) {
+          percentStr =
+            (parseFloat(item.stockQuantity / total) * 100).toFixed(2) + "%, ";
+        }
+        clientLabels.push({
+          name: item.stockName,
+          percent: percentStr,
+          number: item.stockQuantity,
+        });
+      });
       let options = {
         title: {
           text: "存栏结构",
@@ -60,35 +73,10 @@ export default {
             color: "#666",
           },
           formatter: function(name) {
-            var legendIndex = 0;
-            const clientLabels = [];
-            // 将右侧文字备注放上去
-            _this.data.forEach((item) => {
-              let percentStr = "";
-              if (item.stockQuantity !== 0) {
-                percentStr =
-                  (parseFloat(item.stockQuantity / total) * 100).toFixed(2) +
-                  "%, ";
-              }
-              clientLabels.push({
-                name: item.stockName,
-                percent: percentStr,
-                number: item.stockQuantity,
-              });
+            const item = clientLabels.find((item) => {
+              return item.name === name;
             });
-            clientLabels.forEach(function(value, i) {
-              if (value.name == name) {
-                legendIndex = i;
-              }
-            });
-            return (
-              name +
-              " (" +
-              clientLabels[legendIndex].percent +
-              clientLabels[legendIndex].number +
-              "头" +
-              ") "
-            );
+            return name + " (" + item.percent + item.number + "头" + ") ";
           },
         },
         graphic: [
@@ -154,7 +142,7 @@ export default {
             data: [
               { value: this.data[0].stockQuantity, name: "母猪存栏" },
               { value: this.data[1].stockQuantity, name: "公猪存栏" },
-              { value: this.data[2].stockQuantity, name: "哺乳猪存栏" },
+              { value: this.data[2].stockQuantity, name: "哺乳猪存栏" },
               { value: this.data[3].stockQuantity, name: "保育猪存栏" },
               { value: this.data[4].stockQuantity, name: "育肥猪存栏" },
             ],

+ 1 - 1
src/views/PdcData/analysis/ProductionDonuts.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2021-10-11 14:56:37
- * @LastEditTime: 2021-12-22 10:30:13
+ * @LastEditTime: 2022-01-12 15:09:35
  * @LastEditors: Please set LastEditors
  * @Description: In User Settings Edit
  * @FilePath: \hyyfClient\src\views\PdcData\analysis\ProductionDonuts.vue