DC.js图表​​中的初始范围选择

sta*_*One 7 javascript filter d3.js crossfilter dc.js

我想在一些dc.js图表​​(条形图和线条图)中进行初始范围选择.
所以我添加这个例子:

.filter([7,10])
Run Code Online (Sandbox Code Playgroud)

并且该范围在图表上显示良好,但显然选择了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)
        ;
Run Code Online (Sandbox Code Playgroud)

Gor*_*don 11

dc.js中的过滤器代码有点棘手.如果指定值数组,则不会将数组解释为范围.(它会将数组解释为单个值,或者如果数组包含另一个数组,它将过滤该数组内的值.)

请尝试指定范围过滤器对象:

    .filter(dc.filters.RangedFilter(7, 10))
Run Code Online (Sandbox Code Playgroud)