我想在一些dc.js图表(条形和直线)中进行初始范围选择.
所以我添加这个例子:
所以我添加这个例子:
- .filter([7,10])
并且该范围在图表上显示良好,但显然选择了0个观察值.
我预计会选择几千个观测值.就像我用刷子手动选择范围[7,10]时那样.
我在这里缺少的任何暗示?
我的部分代码:
- 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 = GlobalscoreDimension.group()
- (...)
- ;
- (...)
- chart_globalscore
- .width(width001)
- .height(height001)
- .margins(margins)
- .dimension(GlobalscoreDimension)
- .group(GlobalscoreGroup)
- .round(function(val){return Math.round(val*10)/10;})
- .x(d3.scale.linear().domain([0,10.1]))
- .filter([7,10])
- .centerBar(false)
- .transitionDuration(transitionDuration)
- .elasticY(true)
- .gap(1)
- .xUnits(function(){return 100;})
- .renderHorizontalGridLines(true)
- .yAxis().ticks(2)
- ;
解决方法
dc.js中的过滤器代码有点棘手.如果指定值数组,则不会将数组解释为范围. (它将数组解释为单个值,或者如果数组包含另一个数组,则为
it will filter on the values inside that array.)
请尝试指定ranged filter object:
- .filter(dc.filters.RangedFilter(7,10))