| db11048f  阿宝
 
设备状态,学校管理 | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 |   <template>
    <div class="chart" :id="id"></div>
  </template>
  
  <script>
  export default {
    name: "pieChart",
    props: {
      id: String,
      params: Array,
    },
    watch: {
      params: {
        handler: function (val) {
          if (val.length) {
            this.initData();
          }
        },
        deep: true,
      },
    },
    data() {
      return {
        chart: null,
      };
    },
    created() {},
    mounted() {
      this.initData();
    },
    methods: {
      setOption() {
        const that = this;
 | 
| db11048f  阿宝
 
设备状态,学校管理 | 34
35
36
37
38
39
40 |         const options = {
          color: this.colors || ["#ff80db", "#c8cc00", "#67c6b5"],
          backgroundColor: "#f8f8f8",
          tooltip: {
            trigger: "item",
            confine: true,
            formatter(v) {
 | 
| 225a00b6  梁保满
 
飞书问题解决 | 41 |               return `${v.marker} ${v.name}:${v.value}`
 | 
| db11048f  阿宝
 
设备状态,学校管理 | 42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 |             },
          },
          legend: {
            show: false,
            bottom: 40,
            left: 60,
            tight: 60,
            selectedMode: false,
            formatter: function (name) {},
            textStyle: {
              rich: {
                b: {
                  color: "#999",
                },
              },
            },
          },
          series: {
            type: "pie",
            center: ["50%", "50%"], // 位置
            radius: [0, "80%"],
            data: that.params,
            label: {
              normal: {
                formatter(v) {
 | 
| 23a6dc5f  阿宝
 
学校管理相关接口简单对接 | 67 |                   console.log(v)
 | 
| 225a00b6  梁保满
 
飞书问题解决 | 68 |                   let rate = v.data.rate*100
 | 
| 1365ef5e  梁保满
 
优化 | 69 |                   return v.name + rate.toFixed(2) + "%";
 | 
| db11048f  阿宝
 
设备状态,学校管理 | 70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 |                 },
              },
            },
            selectedMode: true,
            hoverAnimation: true,
            avoidLabelOverlap: true,
            animationType: "scale",
            animationEasing: "elasticOut",
            animationDelay() {
              return Math.random() * 100;
            },
          },
        };
        return options;
      },
      initData() {
        if (!this.chart) {
          const div = document.getElementById(this.id);
          this.chart = this.$echarts.init(div);
        }
        const options = this.setOption();
        this.chart?.clear();
        this.chart.setOption(options, true);
        this.chart.off("click");
        this.chart.on("click", "series", (params) => {
          this.$emit("clickPieChart", params);
        });
      },
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .chart {
    height: 100%;
  }
  </style>
 |