Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dc.js: multiple dimension filters

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.

like image 402
Yi Chai Avatar asked Sep 17 '26 16:09

Yi Chai


1 Answers

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.

like image 55
Gordon Avatar answered Sep 20 '26 06:09

Gordon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!