Javascript 交叉筛选-无法从其他组(非关联组)获取筛选记录

Javascript 交叉筛选-无法从其他组(非关联组)获取筛选记录,javascript,crossfilter,Javascript,Crossfilter,我正在使用这个参考资料中的“飞机”数据集 在Crossfilter之后,“组不观察其自身维度上的筛选器”=>我们可以从组中获得筛选记录,这些组的维度此时未被筛选,不是吗 我进行了一些测试,但这是不正确的: console.dir(date.group().all()); // 50895 records console.dir(distance.group().all()); // 297 records date.filter([new Date(2001, 1, 1), new

我正在使用这个参考资料中的“飞机”数据集

在Crossfilter之后,“组不观察其自身维度上的筛选器”=>我们可以从组中获得筛选记录,这些组的维度此时未被筛选,不是吗

我进行了一些测试,但这是不正确的:

  console.dir(date.group().all()); // 50895 records
  console.dir(distance.group().all()); // 297 records

  date.filter([new Date(2001, 1, 1), new Date(2001, 2, 1)]);

  console.dir(date.group().all()); // 50895 records => this number still the same because we are filtering on its dimension
  console.dir(distance.group().all()); // 297 records => but this number still the same too. I don't know why
  • 你能给我解释一下为什么“distance.group().all()”的数量仍然和我们执行过滤之前一样吗?我是不是遗漏了什么

  • 如果我们真的无法通过这种方式从“距离维度”中获得“过滤记录”,我如何才能做到这一点


  • 谢谢。

    所以,是的,这是预期的行为

    Crossfilter将通过应用维度键和组键函数,在组中为找到的每个值创建一个“bin”。然后,当应用过滤器时,它将应用reduce remove函数,默认情况下,该函数减去已删除的行数

    结果是空箱子仍然存在,但其值为0

    编辑:这里是

    如果您想删除零,可以使用“假组”来完成

    function remove_empty_bins(source_group) {
        return {
            all:function () {
                return source_group.all().filter(function(d) {
                    //return Math.abs(d.value) > 0.00001; // if using floating-point numbers
                    return d.value !== 0; // if integers only
                });
            }
        };
    }
    

    此函数通过调用
    source\u group.all()
    将组包装在一个实现
    .all()
    的对象中,然后过滤结果。因此,如果您使用的是dc.js,您可以向您的图表提供此假组,如下所示:

    chart.group(remove_empty_bins(yourGroup));
    

    你完全正确。过滤器已更改这些记录(297条记录)的“值”的值。不是记录数(将保留297条记录)。非常感谢您的帮助,很抱歉回复太晚!很高兴我能帮忙&谢谢你的跟进。我已经为此创建了一个交叉过滤器,并将其链接到上面。
    chart.group(remove_empty_bins(yourGroup));