|
|
|
@ -51,39 +51,47 @@ export default {
|
|
|
|
itemWidth: 8,
|
|
|
|
itemWidth: 8,
|
|
|
|
itemHeight: 5
|
|
|
|
itemHeight: 5
|
|
|
|
},
|
|
|
|
},
|
|
|
|
color: ['#446df6', '#f2a93f', '#56b7f9'],
|
|
|
|
color: ['#f2a93f', '#446df6', '#56b7f9'],
|
|
|
|
series: [
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
{
|
|
|
|
type: 'pie',
|
|
|
|
type: 'pie',
|
|
|
|
radius: ['50%', '70%'],
|
|
|
|
radius: ['50%', '70%'],
|
|
|
|
center: ['50%', '36%'],
|
|
|
|
center: ['50%', '36%'],
|
|
|
|
padAngle: 4,
|
|
|
|
selectedMode: 'single',
|
|
|
|
|
|
|
|
padAngle: 0,
|
|
|
|
|
|
|
|
selectedOffset: 0,
|
|
|
|
|
|
|
|
hoverOffset: 0,
|
|
|
|
itemStyle: {
|
|
|
|
itemStyle: {
|
|
|
|
borderRadius: 10,
|
|
|
|
borderRadius: 0,
|
|
|
|
padding: 10
|
|
|
|
borderWidth: 0,
|
|
|
|
|
|
|
|
borderColor: 'transparent'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
label: {
|
|
|
|
label: {
|
|
|
|
show: true,
|
|
|
|
show: false
|
|
|
|
position: 'center',
|
|
|
|
|
|
|
|
formatter: `{b}\n{d}%`
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
avoidLabelOverlap: true, // 是否启用防止标签重叠策略
|
|
|
|
avoidLabelOverlap: true, // 是否启用防止标签重叠策略
|
|
|
|
emphasis: { // 高亮,即鼠标经过时的样式
|
|
|
|
emphasis: { // 高亮,即鼠标经过时的样式
|
|
|
|
scale: true // 表示不放大item
|
|
|
|
scale: true, // 表示不放大item
|
|
|
|
|
|
|
|
label: {
|
|
|
|
|
|
|
|
show: true,
|
|
|
|
|
|
|
|
position: 'center',
|
|
|
|
|
|
|
|
formatter: `{b}\n{d}%`
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
labelLine: {
|
|
|
|
labelLine: {
|
|
|
|
show: false
|
|
|
|
show: false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data: (() => {
|
|
|
|
data: this.chartData.map((item, index) => ({ ...item, selected: index === 0 }))
|
|
|
|
if (this.percent || this.percent === 0) {
|
|
|
|
// (() => {
|
|
|
|
return [
|
|
|
|
// if (this.percent || this.percent === 0) {
|
|
|
|
{ value: parseFloat(this.percent), name: `${this.title}率` },
|
|
|
|
// return [
|
|
|
|
{ value: 100 - parseFloat(this.percent), name: `未${this.title}率` }
|
|
|
|
// { value: parseFloat(this.percent), name: `${this.title}率` },
|
|
|
|
]
|
|
|
|
// { value: 100 - parseFloat(this.percent), name: `未${this.title}率` }
|
|
|
|
} else {
|
|
|
|
// ]
|
|
|
|
return this.chartData
|
|
|
|
// } else {
|
|
|
|
}
|
|
|
|
// return this.chartData
|
|
|
|
})()
|
|
|
|
// }
|
|
|
|
|
|
|
|
// })()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
],
|
|
|
|
graphic: {
|
|
|
|
graphic: {
|
|
|
|
@ -109,6 +117,88 @@ export default {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setOptions() {
|
|
|
|
setOptions() {
|
|
|
|
this.chart?.setOption(this.options)
|
|
|
|
this.chart?.setOption(this.options)
|
|
|
|
|
|
|
|
if (this.chart && Array.isArray(this.chartData) && this.chartData.length > 0) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
this.chart.dispatchAction({ type: 'downplay', seriesIndex: 0 })
|
|
|
|
|
|
|
|
this.chart.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: 0 })
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
// ignore
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// persistent center label via graphic
|
|
|
|
|
|
|
|
const data = this.chartData
|
|
|
|
|
|
|
|
const total = data.reduce((s, it) => s + Number(it.value || 0), 0)
|
|
|
|
|
|
|
|
const first = data[0]
|
|
|
|
|
|
|
|
const percent = total > 0 ? Math.round((Number(first.value || 0) / total) * 10000) / 100 : 0
|
|
|
|
|
|
|
|
this.chart.setOption({
|
|
|
|
|
|
|
|
graphic: {
|
|
|
|
|
|
|
|
elements: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: 'text',
|
|
|
|
|
|
|
|
left: 'center',
|
|
|
|
|
|
|
|
top: '36%',
|
|
|
|
|
|
|
|
style: {
|
|
|
|
|
|
|
|
text: `${first.name}\n${percent}%`,
|
|
|
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
|
|
fill: '#333',
|
|
|
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
|
|
|
fontWeight: 500
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
z: 100
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// update on hover and restore on mouse out
|
|
|
|
|
|
|
|
this.chart.off('mouseover')
|
|
|
|
|
|
|
|
this.chart.off('globalout')
|
|
|
|
|
|
|
|
this.chart.on('mouseover', { seriesIndex: 0 }, (params) => {
|
|
|
|
|
|
|
|
if (!params || typeof params.dataIndex === 'undefined') return
|
|
|
|
|
|
|
|
const item = data[params.dataIndex]
|
|
|
|
|
|
|
|
const p = total > 0 ? Math.round((Number(item.value || 0) / total) * 10000) / 100 : 0
|
|
|
|
|
|
|
|
this.chart.setOption({
|
|
|
|
|
|
|
|
graphic: {
|
|
|
|
|
|
|
|
elements: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: 'text',
|
|
|
|
|
|
|
|
left: 'center',
|
|
|
|
|
|
|
|
top: '36%',
|
|
|
|
|
|
|
|
style: {
|
|
|
|
|
|
|
|
text: `${item.name}\n${p}%`,
|
|
|
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
|
|
fill: '#333',
|
|
|
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
|
|
|
fontWeight: 500
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
z: 100
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
this.chart.on('globalout', () => {
|
|
|
|
|
|
|
|
this.chart.setOption({
|
|
|
|
|
|
|
|
graphic: {
|
|
|
|
|
|
|
|
elements: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: 'text',
|
|
|
|
|
|
|
|
left: 'center',
|
|
|
|
|
|
|
|
top: '36%',
|
|
|
|
|
|
|
|
style: {
|
|
|
|
|
|
|
|
text: `${first.name}\n${percent}%`,
|
|
|
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
|
|
fill: '#333',
|
|
|
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
|
|
|
fontWeight: 500
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
z: 100
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
// this.setGraphics()
|
|
|
|
// this.setGraphics()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setGraphics() {
|
|
|
|
setGraphics() {
|
|
|
|
|