ooo ooo - 1 year ago 212
Javascript Question

Initial Range selection in DC.js chart

I would like to make an initial range selection in some dc.js charts (bar and line).

So I add this for example:


And the range appears well on the chart, but apparently 0 observations are selected.

I expected a few thousands observations selected. Like it does when I select the range [7,10] manually with the brush.

Any hint on what I'm missing here?

Part of my code:

var chart_globalscore = dc.barChart('#chart_globalscore');
var ndx = crossfilter(data_movies)
,all = ndx.groupAll()
,GlobalScoreDimension = ndx.dimension(function(d) { if ( !isNaN(d.GlobalScore) ) {return Math.round(d.GlobalScore*10)/10 ;} else {return -1;} })
,GlobalScoreGroup =
.round(function(val){return Math.round(val*10)/10;})
.x(d3.scale.linear().domain([0, 10.1]))
.xUnits(function(){return 100;})

Answer Source

The filter code is a bit tricky in dc.js. If you specify an array of values, it will not interpret the array as a range. (It will either interpret the array as a single value, or if the array contains another array, it will filter on the values inside that array.)

Try specifying a ranged filter object instead:

    .filter(dc.filters.RangedFilter(7, 10))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download