DC.js 图表中的初始范围选择 [英] Initial Range selection in DC.js chart
问题描述
我想在一些 dc.js 图表(条形图和折线图)中进行初始范围选择.
所以我添加这个,例如:
I would like to make an initial range selection in some dc.js charts (bar and line).
So I add this for example:
.filter([7,10])
范围在图表上显示得很好,但显然选择了 0 个观测值.
我预计会选择几千个观察结果.就像我用画笔手动选择范围 [7,10] 一样.
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?
我的部分代码:
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 中的过滤器代码有点棘手.如果您指定一个值数组,它不会将该数组解释为一个范围.(它将数组解释为单个值,或者如果数组包含另一个数组,它将过滤该数组内的值.)
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))
这篇关于DC.js 图表中的初始范围选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!