peng
2026-03-24 05c7478c26954ee6031f98fce6c8c9901abb98a0
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
34
35
36
37
38
39
40
41
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
67
68
69
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<template>
  <div>
    <div class="pie-chart" :id="domId"></div>
  </div>
</template>
 
<script>
import * as echarts from 'echarts'
export default {
  props: {
    chartData: {
      type: Object,
      default: () => {
        return {}
      },
    },
    domId: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      chartEntity: null,
    }
  },
  methods: {
    //设置停车规范占比图表
    setChart() {
      if (!this.chartEntity) {
        let chartDom = document.getElementById(this.domId)
        this.chartEntity = echarts.init(chartDom)
      }
      let arr = []
      this.chartData.xData.map((el, index) => {
        arr.push({
          percent: this.chartData.lineData[index],
          value: this.chartData.barData[index],
          name: el,
        })
      })
      let data = []
      for (var i = 0; i < arr.length; i++) {
        data.push({
          value: arr[i].value,
          name: arr[i].name,
          itemStyle: {
            borderWidth: 6,
            shadowBlur: 5,
            borderRadius: 5,
          },
        })
      }
      let option = {
        // color: color,
        tooltip: {
          trigger: 'item',
          backgroundColor: 'rgba(49, 66, 114, .7)',
          borderColor: 'rgba(52, 58, 68, 1)',
          textStyle: { color: '#fff' },
          borderWidth: 1,
          shadowColor: ' rgba(111, 193, 253, 0.35)',
          shadowBlur: 10,
        },
        legend: {
          orient: 'vertical',
          icon: 'circle',
          right: '2%',
          top: 'middle',
          itemWidth: 14,
          itemGap: 12,
          textStyle: {
            rich: {
              a: {
                color: '#AFB1B4',
                fontSize: 12,
                padding: [0, 5, 0, 0],
              },
              b: {
                color: '#5B81F9',
                fontSize: 12,
                padding: [0, 10, 0, 5],
              },
            },
          },
          formatter: function (name) {
            var target, unit
            for (var i = 0, l = data.length; i < l; i++) {
              if (data[i].name == name) {
                target = data[i].value
                unit = data[i].unit
                break
              }
            }
            return `{a| ${name}}`
          },
        },
        series: [
          {
            name: '',
            type: 'pie',
            clockwise: false,
            radius: ['70%', '100%'],
            width: '100%',
            height: '100%',
            emphasis: {
              scale: false,
            },
            center: ['28%', '52%'],
            top: 'center',
            right: '62%',
            label: {
              show: true,
              position: 'inside',
              color: '#fff',
              formatter: function (params) {
                if (params.percent == 0) {
                  return ''
                } else {
                  return params.percent + '%'
                }
              },
            },
            data: data,
          },
        ],
      }
 
      option && this.chartEntity.setOption(option)
    },
  },
}
</script>
<style lang="less" scoped>
.pie-chart {
  height: 20vh;
}
</style>