echarts柱状图计算每个柱子的类型总和

记录下

每个单位对应四种项目类型,求出每个单位的项目总分

这是后台返回的数据

     let arrData = [
           [714.29,999.52, 999, 712.82, 0, 997, 996, 0, 0, 995],
           [285.43, 0, 0, 285.64, 997, 0, 0, 995.9, 995.8,0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        ]
        /*
            竖着求总分数
        */
        let a = arrData[0];
        arrData.forEach((item, index) => {
            sum(item, index)
        })
        function sum(data, index) {
            if(index > 0) {
                a = a.map((item, index) => {
                    return item + data[index]
                })
            }
            return a
        }
        console.log(sum(), '总分数')

  

  

原文地址:https://www.cnblogs.com/theblogs/p/14057560.html