Reputation: 144
I am new to dc.js. And I am trying to use it to filter my dataset by multiple conditions. I could use the following code to filter by one condition(type).
var psv = d3.dsvFormat("|");
var experiments = psv.parse("time|userId|type|version\n" + data);
var ndx = crossfilter(experiments);
var typeDim = ndx.dimension(function(d) { return d["type"]});
var result = typeDim.filter(targetType).top(GLOBAL.MAX_FEEDBACK_COUNT);
How could I apply another dimension filter condition to the result
? Like filtering by userId
?
Thanks in advance.
Upvotes: 3
Views: 683
Reputation: 20120
One frequent cause of confusion: .filter
does not return the filtered data. It applies a filter to the dimension, which is stateful. Then dimension.top()
and group.all()
are the functions which retrieve raw and aggregated data from the crossfilter.
If you want to apply another filter, you'll usually create another dimension for that, e.g. one keyed on userId
. Then the crossfilter instance will be filtered on both filters.
Beware, though: a crossfilter group (where you usually read aggregated data) does not observe its own dimension's filters. Confusingly, dimension.top does observe this dimension's filter.
Upvotes: 1