1.拿到总数 sum
let sum = 0;
let OrderCountData = data.map(item => {
let obj = {};
obj.name = item.servicetype;
obj.num = item.num;
sum += item.num;
return obj;
});
2.用总数sum/单个数量num
let arr = [];
OrderCountData.map(item => {
item.percent = Math.round((item.num / sum) * 10000) / 100+"%";
item.a = "1";
arr.push(item);
});
3,化为%: Math.round((item.num / sum) * 10000) / 100+"%";
Math.round((item.num / sum) * 10000) / 100+"%";
网友评论