我試圖通過html滑塊修改直方圖佈局的bin,但沒有成功。
我試圖運行滑塊的代碼是:使用HTML範圍滑塊更新直方圖bin
<div id = "range">
<input type="range" min="1" max="50" step="1" value="25">
</div>
然後我設置了直方圖的bins
至var bin
。
JS的與範圍滑塊的值來更新箱代碼:
d3.select("#range")
.select("input")
.on("change", function() {
this.value == bin;
//The two histogram variables, line and path generators
histogSans = d3 .layout.histogram()
.bins(bin)
.value(function (d) { return d.Peso; })
(FontSans);
histogSerif = d3 .layout.histogram()
.bins(bin)
.value(function (d) { return d.Peso; })
(FontSans);
line = d3.svg.line()
.x(function (d) { return x(d.x); })
.y(function (d) { return y(d.y); });
SansPath = svg
.transition()
.duration(1500)
.attr("d", line(histogSans));
});
其中histogSans
& histogSerif
是直方圖值的發電機,line
是線發生器和SansPath
& SerifPath
是路徑生成器,遵循直方圖值。
編輯:感謝cuckovic我現在能得到正確的價值出來的滑塊,與bin = this.value;
,但直方圖的控制檯日誌現在返回一個錯誤的陣列中,只包含所有的數組數據集中的值,所以這些值沒有正確繪製!任何人都知道這是爲什麼發生? 全部代碼在這裏:http://dl.dropboxusercontent.com/u/37967455/confronto_pesi.html
確定這確實是正確的更新變種斌,現在我需要弄清楚爲什麼直方圖不更新 – tomtomtom
它看起來像你的例子缺少一些代碼。 – cuckovic
完整的代碼在這裏,如果你想看看:http://dl.dropboxusercontent.com/u/37967455/confronto_pesi.html – tomtomtom