Radar.vue
2.89 KB
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
<template>
<div class='radar'>
<div
ref='radar'
class='radar-canvas'
></div>
<div class="radar-title">{{title}}</div>
</div>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'Radar',
data () {
return {
title: ''
}
},
props: {
listData: {
type: Object,
default: () => {
return {}
}
},
isRowIndex: {
type: Array,
default: []
},
itemColor: {
type: String,
default: '#00e0b3'
}
},
mounted () {
},
watch: {
'listData' (n, o) {
if (n) {
this.draw()
}
}
},
methods: {
draw () {
this.title = this.listData.data[0].name
let canvas = echarts.init(this.$refs.radar)
let obj = this.listData
let indicator = obj.indicator
let data = obj.data
data[0].value.forEach((e, i) => {
indicator[i].value = e
indicator[i].index = i
})
let options = {
radar: {
radius: '50%',
splitNumber: 5,
center: ['50%', '40%'],
name: {
formatter: (value, indicator) => {
let row_column = true
let val = `{a|${value}}\n{b|${indicator.value}}`
this.isRowIndex.forEach(e => {
if (e == indicator.index) val = `{a|${value}}\t{b|${indicator.value}}`
})
return val
},
rich: {
a: {
color: '#fff',
fontSize: 16,
align: 'center'
},
b: {
color: '#fff',
fontSize: 16,
lineHeight: 25,
align: 'right'
},
},
},
axisLine: false,
splitLine: {
lineStyle: {
width: 3,
color: 'rgba(45,153,186,0.2)'
}
},
splitArea: false,
indicator: indicator
},
series: [{
type: 'radar',
symbolSize: 0,
areaStyle: {
color: {
type: 'radial',
x: 0.5,
y: 0.5,
r: 0.8,
colorStops: [{
offset: 0, color: 'rgba(0,0,0,0)' // 0% 处的颜色
}, {
offset: 1, color: this.itemColor // 100% 处的颜色
}],
globalCoord: false
},
},
lineStyle: {
color: this.itemColor
},
data: data
}],
}
canvas.setOption(options)
}
}
}
</script>
<style scoped lang='scss'>
.radar {
width: 100%;
height: 100%;
position: relative;
&-canvas {
width: 100%;
height: 100%;
}
&-title {
position: absolute;
left: 0;
bottom: 20px;
width: 100%;
text-align: center;
font-size: 24px;
color: #8e99a6;
}
}
</style>