我需要有关此功能的帮助:
var ListFruits = Enumerable.From(data)
.GroupBy("$.Fruits", "", "d,v => { Fruits:d,NumberFruits:v.Sum('$.NumberFruits|0')}")
.Select(" $.Fruits+ ': ' + $.NumberFruits")
.ToArray();
// result is [apple: 2 , banana:5 , orange: 3]
我希望每种水果占总数的百分比
执行此类操作的函数(total
所有水果的总和在哪里):
var ListFruits = Enumerable.From(data)
.GroupBy("$.Fruits", "", "d,v => { Fruits:d,NumberFruits:v.Sum('$.NumberFruits|0')}")
.Select(" $.Fruits+ ': ' + $.NumberFruits + 'is' + ($.NumberFruits/total)*100 ")
.ToArray();
// result is [apple: 2 is 20% , banana: 5 is 50% , orange: 3 is 30%]