我与“飞机”的数据来自该参考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
谢谢。
所以,是的,这是预期的行为。
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));