在DC.js图表​​中选择初始范围 [英] Initial Range selection in DC.js chart

查看:101
本文介绍了在DC.js图表​​中选择初始范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一些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.

这里有什么提示?

我的代码的一部分:

    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.)

尝试指定 ranged filter object

    .filter(dc.filters.RangedFilter(7, 10))

这篇关于在DC.js图表​​中选择初始范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆