echarts legend自定義樣式文字
阿新 • • 發佈:2020-12-13
this.dataVal: any = [
{ name: "參與人數", value: 0 },
{ name: "未參與人數", value: 0 },
];
legend: {
formatter: function (name: any) {
var total = 0;
var target;
for (let item of that.dataVal) {
total += Number (item.value);
if (item.name == name) {
target = Number(item.value);
}
}
var arr;
if (!total || !target) {
arr = ["{a|" + name + "} {b| 0%}"];
return arr;
}
arr = ["{a|" + name + "} {b|" + ((target / total) * 100).toFixed(2) + "%}"];
return arr;
},
textStyle: {
rich: {
b: {
color: "#B6B6B6",
verticalAlign: "right",
},
a: {
align: "left",
width: 100,
},
},
},
},