ball-chart.vue
1.87 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
<template>
<div class="container">
<div class="chartRef"></div>
<div class="my-tooltip">
<a-tooltip content="This is tooltip content" >
<icon-question-circle-fill size="18"/>
</a-tooltip>
</div>
</div>
</template>
<script setup lang="ts">
import * as echarts from 'echarts' //引入echarts
import 'echarts-liquidfill'
import {onMounted, ref, watch} from "vue";
import {useWindowSize} from "@vueuse/core";
// echarts实例
const chartInstance = ref<any>(null)
const initEchart = () => {
//获取对应的dom元素
const el = document.querySelector('.chartRef') as HTMLDivElement
// 初始化
chartInstance.value = echarts.init(el)
const option:any = {
series: [{
type: 'liquidFill',
radius: '100px',
data: [0.6],
label: {
normal: {
color: '#fff',
insideColor: 'transparent',
textStyle: {
fontSize: 26,
fontWeight: 'bold',
}
}
},
color: [{
type: 'linear',
x: 0,
y: 1,
x2: 0,
y2: 0,
colorStops: [{
offset: 1,
color: ['#7595F7'], // 0% 处的颜色
}, {
offset: 0,
color: ['#D0DCFD'], // 100% 处的颜色
}],
global: false // 缺省为 false
}],
outline: {
show: true,
borderDistance: 5,
itemStyle: {
borderColor: 'rgba(67,209,100,1)',
borderWidth: 0
}
}
}]
}
chartInstance.value.setOption(option)
}
const { width,height } = useWindowSize()
watch(width,() => {
chartInstance.value.resize()
})
onMounted(() => {
initEchart()
})
</script>
<style scoped>
.container{
width: 100%;
height: 100%;
position: relative;
}
.chartRef {
width: 100%;
height: 100%;
}
.my-tooltip{
position: absolute;
right: calc(50% - 60px);
top: 10px;
}
</style>