2022-08-25 14:17:31 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="j-ring-chart" ref="jRingChart"></div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import echarts from 'echarts4'
|
|
|
|
|
export default {
|
|
|
|
|
props: {
|
|
|
|
|
data: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => [{ value: 1, name: '' }]
|
|
|
|
|
},
|
|
|
|
|
color: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => ['#5181F6', '#61D2B9', '#F67F51', '#7851F6']
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => ({
|
|
|
|
|
text: '',
|
|
|
|
|
subTitle: '',
|
|
|
|
|
x: '48%',
|
2022-08-29 09:24:29 +08:00
|
|
|
y: '36%',
|
|
|
|
|
fontSize: 20
|
2022-08-25 14:17:31 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
radius: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => ['65%', '80%']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.createRingChart()
|
|
|
|
|
},
|
2022-08-29 09:24:29 +08:00
|
|
|
watch: {
|
|
|
|
|
data: {
|
|
|
|
|
handler(newVal, oldVal) {
|
|
|
|
|
if (newVal != oldVal) {
|
|
|
|
|
this.createRingChart()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true
|
2022-08-25 14:17:31 +08:00
|
|
|
},
|
2022-08-29 09:24:29 +08:00
|
|
|
title: {
|
|
|
|
|
handler(newVal, oldVal) {
|
|
|
|
|
if (newVal != oldVal) {
|
|
|
|
|
this.createRingChart()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true
|
2022-08-25 14:17:31 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
createRingChart() {
|
|
|
|
|
const jRingChart = echarts.init(this.$refs.jRingChart)
|
|
|
|
|
const { title } = this
|
|
|
|
|
const option = {
|
|
|
|
|
color: this.color,
|
|
|
|
|
title: {
|
|
|
|
|
show: true,
|
|
|
|
|
text: title.text,
|
|
|
|
|
x: title.x || '48%',
|
|
|
|
|
y: title.y || '36%',
|
|
|
|
|
z: 5,
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
textStyle: {
|
|
|
|
|
color: 'rgba(255, 255, 255, 1)',
|
2022-08-29 09:24:29 +08:00
|
|
|
fontSize: title.fontSize || 20
|
2022-08-25 14:17:31 +08:00
|
|
|
},
|
|
|
|
|
subtext: title.subTitle,
|
|
|
|
|
subtextStyle: {
|
|
|
|
|
color: 'rgba(255, 255, 255, 0.8)',
|
|
|
|
|
fontSize: 13
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
right: 0
|
|
|
|
|
},
|
|
|
|
|
legend: {
|
|
|
|
|
show: false
|
|
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
name: '',
|
|
|
|
|
type: 'pie',
|
|
|
|
|
radius: this.radius,
|
|
|
|
|
avoidLabelOverlap: false,
|
|
|
|
|
hoverAnimation: false,
|
|
|
|
|
label: {
|
|
|
|
|
show: false,
|
|
|
|
|
position: 'center'
|
|
|
|
|
},
|
|
|
|
|
labelLine: {
|
|
|
|
|
show: false
|
|
|
|
|
},
|
|
|
|
|
data: this.data
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(option, '草')
|
|
|
|
|
jRingChart.setOption(option)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.j-ring-chart {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|