From 1dbdda3517a01851d8d9894b22e61aa4462b541c Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期四, 07 十二月 2023 19:16:36 +0800
Subject: [PATCH] tooltip值优化

---
 src/views/cockpitPage/components/MachineStartupRate.vue |   56 ++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/src/views/cockpitPage/components/MachineStartupRate.vue b/src/views/cockpitPage/components/MachineStartupRate.vue
index 5e66228..8af3e2f 100644
--- a/src/views/cockpitPage/components/MachineStartupRate.vue
+++ b/src/views/cockpitPage/components/MachineStartupRate.vue
@@ -5,10 +5,10 @@
         <img src="/cockpitPage/machine-top.png" alt="" />
         <div class="top-title">
           <span>鏈哄櫒寮�鏈虹巼</span>
-          <span class="top-rate">{{ "60%" }}</span>
+          <span class="top-rate">{{ startupRate + "%" }}</span>
         </div>
       </div>
-      <div class="chart" ref="chart"></div>
+      <div id="main" class="chart" ref="chart"></div>
     </div>
   </div>
 </template>
@@ -16,27 +16,32 @@
 <script>
 //寮曞叆echart
 import * as echarts from "echarts";
+let myChart;
 export default {
   components: {},
-  props: {},
+  props: {
+    startupRate: {
+      type: String,
+      default: "",
+    },
+  },
   data() {
     return {};
   },
-  mounted() {
-    let chartData = [
-      { value: 20, name: "闂茬疆" },
-      { value: 20, name: "缁翠慨" },
-      { value: 60, name: "宸ヤ綔" },
-    ];
-    this.pieChart("chart", chartData);
-  },
+  mounted() {},
   watch: {},
   methods: {
     //鍦ㄨ亴
     pieChart(chartName, data) {
       let chartDom = this.$refs[chartName];
-      let myChart = echarts.init(chartDom);
+
+      if (myChart != null && myChart != "" && myChart != undefined) {
+        myChart.dispose(); //閿�姣�
+      }
+      myChart = echarts.init(chartDom);
       let img = "/cockpitPage/machine-chart-bg.png";
+      let height = myChart.getHeight() / 1;
+      let width = height + 5;
       let option;
       if (data) {
         option = {
@@ -49,11 +54,10 @@
               {
                 type: "image",
                 z: 5,
-                right: 25,
                 style: {
                   image: img,
-                  width: 240,
-                  height: 245,
+                  width: width,
+                  height: height,
                   opacity: 0.55,
                 },
                 left: "center",
@@ -71,6 +75,7 @@
               label: {
                 color: "#01f7fd",
                 fontSize: 14,
+                padding: [0, -60],
                 formatter: function (params) {
                   return `{a|${params.name}} {b|${params.value + "%"}}`;
                 },
@@ -94,8 +99,13 @@
               },
               labelLine: {
                 show: true,
-                length: 50,
+                length: 40,
                 color: "blue",
+                length2: 70,
+              },
+              labelLayout: {
+                verticalAlign: "bottom",
+                dy: -5,
               },
               data: data,
             },
@@ -103,6 +113,20 @@
         };
 
         option && myChart.setOption(option);
+        // window.addEventListener("resize", function () {
+        //   // var chart = echarts.getInstanceByDom(document.getElementById("main"));
+        //   let width = myChart.getWidth();
+        //   let height = myChart.getHeight();
+        //   console.log(width, height, "sssssssssss");
+        //   let logo = myChart.getOption().graphic[0].elements[0];
+        //   console.log(logo, "fffff");
+        //   logo.style.width = width / 2;
+        //   logo.style.height = height / 2;
+        //   myChart.setOption({
+        //     graphic: [logo],
+        //   });
+        //   myChart.resize();
+        // });
       } else {
         option = {};
         myChart.setOption(option, true);

--
Gitblit v1.8.0