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
| <template>
| <div>
| <PanelHeader title="人员分布" />
| <div class="main-panel panel-item-customers">
| <Echarts
| :chartStyle="chartStyle"
| :legend="pieLegend"
| :series="pieSeries"
| :tooltip="pieTooltip"
| :color="pieColors"
| :options="pieOptions"
| style="height: 320px"
| />
| </div>
| </div>
| </template>
|
| <script setup>
| import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue'
| import { getProgressStatistics } from '@/api/viewIndex.js'
| import PanelHeader from '../PanelHeader.vue'
| import Echarts from '@/components/Echarts/echarts.vue'
|
| /**
| * @introduction 把数组中key值相同的那一项提取出来,组成一个对象
| * @description 详细描述
| * @param {参数类型} array 传入的数组 [{a:"1",b:"2"},{a:"2",b:"3"}]
| * @param {参数类型} key 属性名 a
| * @return {返回类型说明}
| * @exception [违例类型] [违例类型说明]
| */
| function array2obj(array, key) {
| const resObj = {}
| for (let i = 0; i < array.length; i++) {
| resObj[array[i][key]] = array[i]
| }
| return resObj
| }
|
| const chartStyle = {
| width: '100%',
| height: '100%',
| }
|
| // 饼图数据(示例)
| const pieDatas = [
| { value: 335, name: '进入区域', percent: '10' },
| { value: 310, name: '区域入侵', percent: '40' },
| { value: 274, name: '人员聚集', percent: '30' },
| { value: 235, name: '越界侦测', percent: '20' },
| ]
|
| const pieColors = ['#D1E4F5', '#5782F7', '#2F67EF', '#82BAFF']
| const pieLegendData = pieDatas.map((d, idx) => ({
| name: d.name,
| icon: 'circle',
| textStyle: {
| fontSize: 18,
| color: pieColors[idx],
| },
| }))
| const pieObjData = array2obj(pieDatas, 'name')
|
| const pieLegend = {
| orient: 'vertical',
| top: 'center',
| left: '50%',
| itemGap: 30,
| data: pieLegendData,
| formatter: function (name) {
| return `{title|${name}}{value|${pieObjData[name].value}}{unit|人}{percent|${pieObjData[name].percent}}{unit|%}`
| },
| textStyle: {
| rich: {
| value: {
| color: '#43e8fc',
| fontSize: 18,
| fontWeight: 600,
| padding: [0, 10, 0, 30],
| },
| unit: {
| color: '#82baff',
| fontSize: 14,
| fontWeight: 600,
| padding: [0, 50, 0, 0],
| },
| percent: {
| color: '#43e8fc',
| fontSize: 18,
| fontWeight: 600,
| padding: [0, 10, 0, 0],
| },
| title: {
| fontSize: 18,
| padding: [0, 0, 0, 0],
| },
| },
| },
| }
|
| const pieTooltip = {
| trigger: 'item',
| formatter: '{a} <br/>{b} : {c} ({d}%)',
| }
|
| const pieSeries = ref([
| {
| name: '访问来源',
| type: 'pie',
| radius: '70%',
| center: ['20%', '50%'],
| itemStyle: {
| // 给每个扇区加分隔缝隙,颜色取深色背景
| borderColor: '#0a1c3a',
| borderWidth: 4,
| },
| label: {
| show: false
| },
| data: pieDatas,
| roseType: 'radius',
| animationType: 'scale',
| animationEasing: 'elasticOut',
| animationDelay: function () {
| return Math.random() * 200
| },
| },
| ])
|
| const pieOptions = {
| backgroundColor: 'transparent',
| textStyle: { color: '#B8C8E0' },
| }
| </script>
|
| <style scoped>
| .main-panel {
| display: flex;
| flex-direction: column;
| gap: 20px;
| }
|
| .panel-item-customers {
| border: 1px solid #1a58b0;
| padding: 18px;
| width: 100%;
| height: 370px;
| }
| </style>
|
|