RadarChart.vue
3.34 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
<template>
<view >
<template v-if="hasData">
<qiun-data-charts type="radar" :opts="opts" :tooltipShow="false" :chartData="chartData" :class="['charts-box', heightClass]" />
</template>
<template v-else>
<view class="nothing flex" :class="['big-height']">
<image class="icon" src="../../../../assets/images/boutique/nothing.webp" />
暂无数据
</view>
</template>
</view>
</template>
<script>
export default {
name: 'RadarChart',
props: {
chartData: {
type: Object,
default: () => ({})
},
heightClass: {
type: String
},
labelColors: {
type: Array,
default: () => ['#666666', '#666666', '#666666', '#666666', '#666666', '#666666', '#666666', '#666666', '#666666']
}
},
computed: {
hasData () {
const c = this.chartData && Array.isArray(this.chartData.categories) ? this.chartData.categories : []
const s0 = this.chartData && Array.isArray(this.chartData.series) ? this.chartData.series[0] : null
const d = s0 && Array.isArray(s0.data) ? s0.data : []
return c.length > 0 && d.length > 0
}
},
watch: {
labelColors: {
handler(newVal) {
console.log(newVal, 'newVal')
if (Array.isArray(newVal) && newVal.length) {
this.opts.labelColors = newVal
} else {
const len = (this.chartData && Array.isArray(this.chartData.categories)) ? this.chartData.categories.length : 0
this.opts.labelColors = len ? Array.from({ length: len }, () => '#666666') : []
}
},
}
},
data() {
return {
opts: {
color: ["#3B73FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
padding: [0, 5, 0, 5],
dataLabel: false,
enableScroll: false,
// labelColors: ['#666666', '#666666', '#666666', '#666666', '#666666', '#EB4E4E', '#666666', '#EB4E4E', '#666666'],
fontSize: 12,
legend: {
show: false
},
extra: {
radar: {
gridType: "radar",
gridColor: "#dae8fd",
gridCount: 3,
opacity: 0.2,
max: 3,
labelShow: true,
dataPointShape: false,
axisLabelTofix: 1, // 保留一位小数
labelFormatter: function (val) {
// 精确到小数点后一位
return typeof val === 'number' ? val.toFixed(1) : val;
}
}
}
},
}
},
mounted() {
console.log(this.chartData, ' 详情')
// 首次进入时父组件可能还没算出 labelColors,这里做一次兜底
if (!Array.isArray(this.opts.labelColors) || !this.opts.labelColors.length) {
const len = (this.chartData && Array.isArray(this.chartData.categories)) ? this.chartData.categories.length : 0
if (len) this.opts.labelColors = Array.from({ length: len }, () => '#666666')
}
}
}
</script>
<style lang="scss" scoped>
.charts-box {
width: 100%;
height: toRpx(272);
&.big-height {
height: toRpx(300);
}
}
.nothing {
width: 100%;
height: toRpx(228);
flex-direction: column;
margin-top: toRpx(76);
font-size: toRpx(24);
color: #999999;
box-sizing: border-box;
&.big-height {
height: toRpx(234);
}
.icon {
width: toRpx(288);
height: toRpx(144);
margin-bottom: toRpx(4);
}
}
</style>