How to sum all values for numberDisplay, excluding a category

谁说我不能喝 提交于 2019-12-23 23:24:04

问题


I have set of data where I want to apply filters by default to a numberDisplay. The data is something like this.

data = [{category:'A',value:10},
{category:'B',value:10},
{category:'C',value:10},
{category:'S',value:10},
{category:'C',value:10},
{category:'A',value:10}]

I am trying to create a number display which will show sum of values other than category 'S', I tried using fake groups but they are failing. What would be the best method to achieve this ?


回答1:


You don’t need a fake group for this, since you’re not trying to change the shape/structure of the aggregation. Ordinary crossfilter reductions cover this purpose.

You can simply do

cf.groupAll().reduceSum(d => d.category === ‘S’ ? 0 : d.value);

This will sum the value of every row included in the current filters, but will substitute zero if the row’s category is S.



来源:https://stackoverflow.com/questions/59242279/how-to-sum-all-values-for-numberdisplay-excluding-a-category

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!