月球大数据地理空间分析展示平台-【中台】
Surpriseplus
2023-06-14 a7ceb07fdcbcac1edcecb8c96bfa7808ea7670c5
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<template>
  <div class="echart" ref="chart"></div>
</template>
 
<script>
import * as echarts from "echarts"
import { countCountryDimension, countProvinceDimension } from "@/api/screen.js"
export default {
  data() {
    return {
      currentProject: '全球项目'
    }
  },
  mounted() {
    this.initChart()
  },
 
  methods: {
    async initChart() {
      const res = await countProvinceDimension()
      let dataPie = [
        {
          value: 410,
          name: "企业",
        },
        {
          value: 380,
          name: "政府",
        },
        {
          value: 50,
          name: "个人",
        },
        {
          value: 50,
          name: "个人1",
        },
        {
          value: 50,
          name: "个人2",
        },
        {
          value: 50,
          name: "个人3",
        },
        {
          value: 50,
          name: "个人4",
        },
        {
          value: 50,
          name: "个人5",
        },
      ]
      let count = 0
      if (res.code == 200) {
        dataPie = res.result.map(item => {
          return {
            name: item.province,
            value: item.count
          }
        })
      }
 
 
      let colorPie = ["#173852", "#0b2036", "#002e49"]
      let colorWrap = [
        "#3087d6",
        "#f6ce54",
        "#4be1ff",
        "#b6e9ff",
        "#18edc9",
        "#6ac5fa",
      ]
      let baseDataPie = [],
        baseDataWrap = []
      let total = 0
      dataPie
        .sort((a, b) => b.value - a.value)
        .forEach(function (val, idx, arr) {
          count += val.value
        })
      for (let i = 0; i < dataPie.length; i++) {
        baseDataWrap.push(
          {
            value: dataPie[i].value,
            name: dataPie[i].name,
            itemStyle: {
              normal: {
                color: colorWrap[i],
                borderWidth: 1,
                borderColor: colorWrap[i],
                shadowBlur: 10,
                shadowColor: "rgba(7, 132, 250, 0.8)",
              },
            },
          },
          {
            value: 0.1,
            name: "",
            itemStyle: {
              normal: {
                color: "transparent",
                borderWidth: 5,
                borderColor: "transparent",
              },
            },
            tooltip: {
              show: false,
            },
          }
        )
 
        if (i < 3) {
          baseDataPie.push({
            value: dataPie[i].value,
            name: dataPie[i].name,
            itemStyle: {
              normal: {
                borderWidth: 10,
                borderColor: colorPie[i],
              },
            },
          })
        }
      }
 
      let option = {
        backgroundColor: "transparent",
        title: {
          text: count,
          subtext: "项目总数",
          textStyle: {
            color: "#fff",
            fontSize: 20,
            fontWeight: 400,
            fontFamily: "YouSheBiaoTiHei",
          },
          subtextStyle: {
            align: "center",
            fontSize: 14,
            color: ["#fff"],
            fontWeight: 400,
            fontFamily: "YouSheBiaoTiHei",
          },
          x: "center",
          y: "center",
        },
        grid: {
          left: "1%", // 与容器左侧的距离
          right: "1%", // 与容器右侧的距离
          top: "1%", // 与容器顶部的距离
          bottom: "1%", // 与容器底部的距离
        },
        tooltip: {
          show: true,
          trigger: "item",
        },
        legend: [
          {
            show: false,
            data: ["在线", "维修", "离线", "检修", "抢修", "其他"],
            icon: "vertical",
            right: "5px",
            top: "center",
            orient: "vertical",
            itemGap: 20,
            itemWidth: 15,
            itemHeight: 8,
            formatter: function (name) {
              let target, percent
              for (let i = 0; i < dataPie.length; i++) {
                if (dataPie[i].name === name) {
                  target = dataPie[i].value
                  percent = ((target / total) * 100).toFixed(1)
                }
              }
              let arr = [
                percent + "% " + " {yellow|" + target + "}",
                " {blue|" + name + "}",
              ]
              return arr.join("\n")
            },
            textStyle: {
              lineHeight: 20,
              color: "#f0f4f6",
              align: "right",
              rich: {
                yellow: {
                  color: "#00b5f3",
                  fontWeight: "bold",
                },
                blue: {
                  color: "#4be1ff",
                  align: "right",
                },
              },
            },
          },
        ],
        series: [
          {
            name: "项目数量",
            type: "pie",
            // clockWise: false, //顺时加载
            // hoverAnimation: false, //鼠标移入变大
            center: ["50%", "50%"],
            // radius: ["60%", "70%"],
            radius: [70, 80],
            labelLine: {
              show: true,
            },
            itemStyle: {
              borderWidth: 3,
              // borderColor: "#fff",
            },
            minAngle: 15, //最小角度
            startAngle: 270, //起始角度
            label: {
              // show: false,
              formatter: params => {
                if (params.percent > 10) {
                  return `{b|${params.name}} \n {per|${Math.ceil(
                    (params.value * 100) / count
                  )}%}`
                } else {
                  return `{b|${params.name}}`
                }
              },
              // backgroundColor: "#eee",
              // borderColor: "#aaa",
              // borderWidth: 1,
              // borderRadius: 3,
              // shadowBlur:3,
              // shadowOffsetX: 2,
              // shadowOffsetY: 2,
              // shadowColor: '#999',
              // padding: [0, 7],
              rich: {
                a: {
                  color: "#999",
                  lineHeight: 22,
                  align: "center",
                },
                // abg: {
                //     backgroundColor: '#333',
                //     width: '100%',
                //     align: 'right',
                //     height: 22,
                //     borderRadius: [4, 4, 0, 0]
                // },
                hr: {
                  borderColor: "#aaa",
                  width: "100%",
                  borderWidth: 0.5,
                  height: 0,
                },
                b: {
                  fontSize: 14,
                  lineHeight: 14,
                  color: '#fff'
 
                },
                per: {
                  color: "#eee",
                  backgroundColor: "#334455",
                  padding: [2, 4],
                  borderRadius: 2,
                },
              },
            },
 
            data: baseDataWrap,
          },
        ],
      }
      const chart = echarts.init(this.$refs.chart)
 
      chart.setOption(option)
      window.addEventListener("resize", function () {
        chart.resize()
      })
    },
 
  },
}
</script>
 
<style lang="scss" scoped>
.echart {
  width: 100%;
  height: 85%;
}
</style>