dl_site_system/dl_vue/src/views/dashboard/PieChart.vue

86 lines
1.6 KiB
Vue
Raw Normal View History

2025-06-19 09:43:36 +08:00
<template>
2025-07-04 17:29:32 +08:00
<div :class="className" :style="{height:height,width:width}"/>
2025-06-19 09:43:36 +08:00
</template>
<script>
import * as echarts from 'echarts'
2025-07-04 17:29:32 +08:00
2025-06-19 09:43:36 +08:00
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: '300px'
}
},
data() {
return {
chart: null
}
},
mounted() {
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
2025-07-16 18:00:12 +08:00
initChart(data) {
2025-06-19 09:43:36 +08:00
this.chart = echarts.init(this.$el, 'macarons')
2025-07-16 18:00:12 +08:00
let titleArray = []
let dataArray = []
let colorArray = ['#017EFA','#51CBFF']
data.map((item,index)=>{
titleArray.push(item.name)
dataArray.push(
{
value: item.value,
name:item.name,
itemStyle: {
color: colorArray[index]
}
}
)
})
2025-06-19 09:43:36 +08:00
this.chart.setOption({
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
left: 'center',
bottom: '10',
2025-07-16 18:00:12 +08:00
data: titleArray
2025-06-19 09:43:36 +08:00
},
series: [
{
2025-07-04 17:29:32 +08:00
name: '',
2025-06-19 09:43:36 +08:00
type: 'pie',
roseType: 'radius',
radius: [15, 95],
center: ['50%', '38%'],
2025-07-16 18:00:12 +08:00
data:dataArray,
2025-06-19 09:43:36 +08:00
animationEasing: 'cubicInOut',
animationDuration: 2600
}
]
})
}
}
}
</script>