2017-12-27 198 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) –