1. 程式人生 > 其它 >echarts legend自定義樣式文字

echarts legend自定義樣式文字

技術標籤:echartsvue.js

在這裡插入圖片描述

  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, }, }, }, },