PieChart.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
<script setup lang="ts">
import { ref, Ref, onMounted, computed, watch } from 'vue';
import { useECharts } from '/@/hooks/web/useECharts';
import { useAppStore } from '/@/store/modules/app';
import { useI18n } from '/@/hooks/web/useI18n';
const props = defineProps({
seriesData: {
type: Array,
default: () => [],
},
});
const { t } = useI18n();
const appStore = useAppStore();
const skinName = computed(() => {
return appStore.getDarkMode === 'light' ? '#ffffff' : '#151515';
});
const chartRef = ref<HTMLDivElement | null>(null);
const { setOptions, resize } = useECharts(chartRef as Ref<HTMLDivElement>);
const getOptions: any = () => {
return {
backgroundColor: skinName.value,
grid: {
left: '10%',
right: '20%',
bottom: '10%',
top: '0%',
},
tooltip: {
trigger: 'item',
formatter: '{b} : {c}%',
},
legend: {
top: 'bottom',
type: 'scroll',
},
title: [
{
text: t('application.record.text.pieShowTitle'),
textStyle: {
color: '#333',
fontWeight: 'bold',
fontSize: 14,
},
left: '49.5%',
top: '45%',
textAlign: 'center',
},
],
series: [
{
type: 'pie',
radius: ['40%', '70%'],
data: props.seriesData,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
},
label: {
normal: {
show: true,
textStyle: {
fontSize: 13,
},
formatter: (params) => {
return params.value + '%';
},
},
},
},
],
};
};
watch(
() => appStore.getDarkMode,
(target) => {
const backgroundColor = target === 'light' ? '#ffffff' : '#151515';
setOptions &&
setOptions({
...getOptions(),
backgroundColor,
});
}
);
onMounted(() => {
setOptions(getOptions());
//自适应
window.addEventListener('resize', () => resize());
});
</script>
<template>
<div class="h-70">
<div ref="chartRef" class="w-full h-full"></div>
</div>
</template>
<style scoped></style>