wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
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
<template>
    <div class="card">
        <div class="card__header">
            <span class="label">{{ $t('类别占比') }}</span>
        </div>
 
        <div class="card__container">
            <v-chart :option="chartOption" autoresize />
        </div>
    </div>
</template>
 
<script lang="ts" setup>
import { useDark } from '@vueuse/core';
import { computed, reactive } from 'vue';
 
const isDark = useDark();
 
const textColor = computed(() => (isDark.value ? '#f1f1f9' : '#000'));
 
const chartOption = reactive({
    legend: {
        top: 'bottom',
        textStyle: {
            color: textColor
        }
    },
    grid: {
        top: 0
    },
    tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b}: {c} ({d}%)'
    },
    series: [
        {
            type: 'pie',
            radius: ['35%', '50%'],
            avoidLabelOverlap: false,
            padAngle: 5,
            itemStyle: {
                borderRadius: 6
            },
            label: {
                color: textColor
            },
            data: [
                { value: 387, name: '电子产品' },
                { value: 314, name: '服装' },
                { value: 253, name: '家居用品' },
                { value: 198, name: '书籍' },
                { value: 123, name: '其他' }
            ]
        }
    ]
});
</script>
 
<style lang="scss" scoped>
.card {
    &__container {
        height: 456px;
    }
 
    .echarts {
        height: calc(100% - 50px);
    }
}
</style>