tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow"
},
formatter: function (params: any) {
// 获取各项总数值
const totalValue = params.reduce((sum: any, item: any) => sum + item.value, 0);
let obj = params.map((item: any, index: any) => {
if (item.value == undefined || item.value !== item.value) {
item.value = 0;
}
let percent = ((item.value / totalValue) * 100).toFixed(2);
// 小圆点显示
let dotColor =
'<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' +
item.color +
'"></span>';
dotColor += item.seriesName + ":" + item.value + "(" + percent + "%" + ")" + "</br>";
if (index == params.length - 1) {
dotColor += `总电量 : ${Number(totalValue.toFixed(2))}`;
}
return dotColor;
});
// console.log(params);
// console.log("总数值=" + totalValue);
return obj.join(""); // 去除','
}
},