ballChart.vue
2.38 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
<!-- 球形echarts -->
<template>
<div
:id="id"
style="height: 208px; margin: 0 auto"
></div>
</template>
<script>
import echarts from 'echarts'
import 'echarts-liquidfill'
export default {
name: 'BallChart',
props: {
// 数据
data: {
type: Array,
required: true
},
// 选择器
id: {
type: String,
required: true
},
// 球和球之间的横向间隔距离
xDistance: {
type: Number,
required: true
}
},
methods: {
// color: '', // 链群颜色值
// labelColor: '', // 文本字体颜色
// otherColer: ''// 波浪其他地方填充色
// 初始化列表
initial() {
const { data, id, xDistance } = this._props
const myChart = echarts.init(document.getElementById(id))
const series = []
data.forEach((item, index) => {
series.push(
{
type: 'liquidFill',
radius: '60%',
center: [`${xDistance * (index + 0.5)}%`, '45%'],
data: [
{
// NOTE 为了扩大鼠标悬浮热区 tooltip展示
value: 1,
itemStyle: {
color: 'transparent'
}
},
item.value / 100
],
backgroundStyle: {
color: [item.otherColor]
},
color: [item.color],
itemStyle: {
shadowColor: 'transparent'
},
outline: {
borderDistance: 5,
itemStyle: {
borderWidth: 1,
borderColor: item.color
}
},
label: {
position: ['50%', '50%'],
formatter: function () {
return `${item.value}%`
},
fontSize: 16,
color: [item.labelColor],
insideColor: [item.labelColor],
fontWeight: 'normal'
}
}
)
})
const option = {
series: series,
backgroundColor: 'white'
}
myChart.setOption(option)
window.addEventListener('resize', function () {
myChart.resize()
})
}
}
}
</script>
<style lang="scss" scoped>
#ballChart{
/deep/ div{
cursor: default !important;
}
}
#ballChartIng{
/deep/ div{
cursor: default !important;
}
}
</style>