如何在过滤图表后获取当前组大小

How to get current group size after filtering charts

我有 2 个图表。在过滤第二个图表时,如何获得过滤后的 firstchartGroup 大小,如过滤后的 firstchartDim

我试过了

chart2.on("filtered",function(chart)
{
    console.log(firstchartDim.top(Infinity).length);//including filters
    console.log(firstchartGroup.size());//independent of filters

});

有什么建议吗?

当 bin 变空时,Crossfilter 不会删除 bin,因此您在计算 bin 时必须手动忽略零。这是一种方法,adapted from the FAQ:

console.log(firstchartGroup.all().filter(function(d) { return d.value != 0; }).length);