echarts实现legend添加数据显示(百分比)功能

核心代码

    
        childOption.legend.formatter = (name) => {
            const itemValueArr = ChildSeruesData.filter(el => el.variable == name)
            const itemValueAll = ChildSeruesData.reduce((total, num) => {
                return total + Math.round(num.value);
            }, 0)
            return `${name}(${(itemValueArr[0].value / itemValueAll * 100).toFixed(2)}%)`
        }

效果

 

原文地址:https://www.cnblogs.com/art-poet/p/12929209.html