Crossfilter - 来自其他团体无法得到过滤记录(而不是从联想集团)

问题描述 投票:2回答:1

我与“飞机”的数据来自该参考http://square.github.io/crossfilter/设置工作

date,delay,distance,origin,destination
01010001,14,405,MCI,MDW
01010530,-11,370,LAX,PHX
...

  // Create the crossfilter for the relevant dimensions and groups.
  var flight = crossfilter(flights),
      all = flight.groupAll(),
      date = flight.dimension(function(d) { return d.date; }),
      dates = date.group(d3.time.day),
      hour = flight.dimension(function(d) { return d.date.getHours() + d.date.getMinutes() / 60; }),
      hours = hour.group(Math.floor),
      delay = flight.dimension(function(d) { return Math.max(-60, Math.min(149, d.delay)); }),
      delays = delay.group(function(d) { return Math.floor(d / 10) * 10; }),
      distance = flight.dimension(function(d) { return Math.min(1999, d.distance); }),
      distances = distance.group(function(d) { return Math.floor(d / 50) * 50; });

继Crossfilter的document,从他们的尺寸并不在这一刻过滤组“的群体不遵守自己的尺寸过滤器” =>我们可以得到过滤记录,我们不能?

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

  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
  1. 能否请您给我解释一下为什么数“)distance.group(所有()”还是和以前一样,我们执行的过滤器?我失去了一些东西在这里?
  2. 如果我们真的不能用这种方式得到“距离尺寸”,“过滤记录”,我怎么能做到这一点?

谢谢。

javascript crossfilter
1个回答
1
投票

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

Crossfilter将创建组中的“仓”,每发现通过应用维度键和组密钥的功能价值。然后当施加滤波器,它将应用减少去除的功能,默认情况下减去除去行的计数。

其结果是,空箱仍然存在,但他们有一个0值。

编辑:这里是the Crossfilter Gotchas entry with further explanation

如果你想删除的零,您可以使用“假团”要做到这一点。

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
            });
        }
    };
}

https://github.com/dc-js/dc.js/wiki/FAQ#remove-empty-bins

此函数包装了基团,其中通过调用.all()实现source_group.all()然后过滤结果的对象。所以,如果你正在使用dc.js你能提供这个假组到您的图表所示:

chart.group(remove_empty_bins(yourGroup));
© www.soinside.com 2019 - 2024. All rights reserved.