2017-12-27 203 views
1

如果elasticY(true)使得散点图能够在重绘事件触发时重新计算y轴范围?dc.js散点图和弹性行为

我已经使用了Scatter Brushing示例来演示。以下属性添加到各图表:

.yAxisPadding('5%') // Allow the max values to be brushed 
.elasticY(true)  // Allow the chart to recalculate the Y axis range 

这里是一个例子jsFiddle

我认为通过刷新左散点图,在图表中间选择一对点会导致右散点图重新计算其Y轴范围。但这似乎并不正确。这是一个错误还是我错过了什么?

回答

1

一如既往与elasticXelasticY,dc.js在看所有的垃圾箱,他们是否是空的。

你可能会争辩说,它忠实地显示所有的数据,只是发生一些数据为零。 :-)

,以消除那些零,使用remove_empty_bins从常见问题:

function remove_empty_bins(source_group) { 
     return { 
      all: function() { 
       return source_group.all().filter(function(d) { 
        //return Math.abs(d.value) > 0.00001; // if using floating-point numbers 
        return d.value !== 0; // if integers only 
       }); 
      } 
     }; 
    } 
    chart1 
     .group(remove_empty_bins(group1)) 
    chart2 
     .group(remove_empty_bins(group2)) 

Fork of your fiddle.

注意散点图joins the data in a naive way它并没有提供很好的动画过渡。我通常建议只关闭散点图的转换.transitionDuration(0),因为它们没有用处。

+0

完美。感谢您的解释和代码。 –

+0

与elasticY相关的问题可以在[BrushY值绑定的ElasticY]中找到(https://stackoverflow.com/questions/48079293/dc-js-elasticy-range-bound-by-brush-y-values) –