dl_site_system/dl_vue/src/views/dashboard/PieCusChart.vue
2025-07-17 17:22:57 +08:00

79 lines
1.5 KiB
Vue

<template>
<div :class="className" :style="{height:height,width:width}"/>
</template>
<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
export default {
mixins: [resize],
props: {
className: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '600px'
}
},
data() {
return {
chart: null,
// 示例数据,你可以替换为实际数据
}
},
mounted() {
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
initChart(data) {
this.chart = echarts.init(this.$el, 'macarons')
const option = {
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
// legend: {
// orient: 'vertical',
// left: 'left',
// data: data.map(item => item.name)
// },
series: [
{
name: '国家分布',
type: 'pie',
radius: '50%',
data: data,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
label: {
formatter: '{b}: {c} ({d}%)'
}
}
]
};
this.chart.setOption(option);
}
}
}
</script>