Fake group filtering in Crossfilter / dc.js

I am trying to understand the "fake group" filtering method as described in the dc.js FAQ How do I filter the data before it's charted?

Please see my example here: dc.js jsfiddle

I want to filter my data by TYPE before the charts are drawn (the TYPE to filter on will come from another part of my application). Basically it should have the same effect as clicking on one of the four bars (A,B,C,D) in the row chart, but I want to be able to control it from elsewhere in my code, and it should happen before the charts are drawn.

I think I need to use the Filter out bins by predicate function on the values approach on my group named "type" eg

function filter_bins(source_group, f) {
return {
    all:function () {
        return source_group.all().filter(function(d) {
            return f(d.value);
        });
    }
};

}

But I'm unclear on what function I should be passing in as f, or what a predicate function is.

I would appreciate any help! Thanks.


If you want it to truly behave as if the type was clicked in the typeRowChart (this is probably what you want), then do this anywhere you want:

typeRowChart.filter("A");

If you want the typeRowChart to remain as-is (unfiltered) for some reason but you want to filter on the typeDim, then filter directly on the dimension and call dc.redrawAll() :

typeDim.filter("A");
dc.redrawAll();

If you want typeRowChart to be filtered by the new selection as well, then create a new type dimension and filter on that:

var typeDim2 = cf.dimension(function (d) {return d.TYPE;});
typeDim2.filter("A");
dc.redrawAll();

I don't think there is a need for the fake-group pattern in this scenario, fortunately. :-)

链接地址: http://www.djcxy.com/p/32740.html

上一篇: 使用DC.js数据表按年创建汇总数据表

下一篇: 在Crossfilter / dc.js中伪造群组过滤