简体   繁体   English

Crossfilter / dc.js中的伪造组过滤

[英]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? 我试图了解dc.js常见问题解答中所述的“伪造组”过滤方法, 如何在绘制图表之前过滤数据?

Please see my example here: dc.js jsfiddle 请在这里查看我的示例: 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. 基本上,它应该与单击行图中的四个条形图(A,B,C,D)之一具有相同的效果,但是我希望能够从代码的其他位置进行控制,并且它应该在图表绘制。

I think I need to use the Filter out bins by predicate function on the values approach on my group named "type" eg 我想我需要在名为“ type”的组的值方法上使用按谓词过滤容器功能,例如

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. 但是我不清楚我应该以f传递什么函数,或者谓词函数是什么。

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中单击该类型typeRowChart (这可能是您想要的),则可以在任何需要的地方进行此操作:

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() : 如果您出于某种原因希望typeRowChart保持原样(未过滤),但又想对typeDim进行过滤,请直接在尺寸上进行过滤并调用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: 如果您还希望通过新选择过滤typeRowChart ,则创建一个新的类型维度并对其进行过滤:

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. 幸运的是,我认为在这种情况下不需要伪造组模式。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM