定义饼图数据和颜色数据
sensorOpts: {
tooltip: {
trigger: 'item',
formatter: '{b}: {c} ({d}%)',
},
legend: {
icon: 'circle',
orient: 'horizontal',
left: 10,
bottom: 0,
data: [],
textStyle: {
color: '#909ABF',
fontSize: 12
}
},
series: [
{
type: 'pie',
radius: ['30%', '50%'],
avoidLabelOverlap: true,
center: ['50%', '50%'],
hoverAnimation: false,
label: {
formatter: function (data) {
const { name, value, percent } = data
let str = ''
str = name + value + '\n' + '(' + percent + '%)'
return str
},
position: 'outer',
alignTo: 'none',
bleedMargin: 5,
},
data: [
],
emphasis: {
show: false
}
}
]
},
color: {
'suoli': '#7CFFFA',
'gangyingbian': '#599DFF',
'wendu': '#FF546E',
'xianxing': '#FFE922',
'shensuo': '#24DA67',
},
处理数据
getData(params).then(response => {
const { data } = response
const warnNameArr = Object.keys(self.color)
let seriesDataObj = {}
data.map((item) => {
item.monitorName = item.monitorName.split('监测')[0]
if (warnNameArr.includes(item.monitorName)) {
seriesDataObj = {
value: item.pointsNum,
name: item.monitorName,
itemStyle: { color: self.color[item.monitorName] },
}
self.sensorOpts.series[0].data.push(seriesDataObj)
self.sensorOpts.legend.data.push(item.monitorName)
}
})