如何对numberDisplay的所有值求和,不包括类别 [英] How to sum all values for numberDisplay, excluding a category
问题描述
我有一组要在默认情况下将过滤器应用于numberDisplay的数据。数据是这样的。
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}]
我试图创建一个数字显示,该数字显示将显示类别'S'以外的其他值,我尝试使用伪造的组,但是它们失败了。达到此目的的最佳方法是什么?
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 ?
推荐答案
您不需要伪造的组,因为不尝试更改聚合的形状/结构。普通的交叉过滤器缩减可满足此目的。
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.
您可以轻松地
cf.groupAll().reduceSum(d => d.category === ‘S’ ? 0 : d.value);
这将对当前过滤器中包含的每一行的值求和,但如果该行的类别是S。
This will sum the value of every row included in the current filters, but will substitute zero if the row’s category is S.
这篇关于如何对numberDisplay的所有值求和,不包括类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!