36
我想創建一個實時圖,使用nvd3.js將定期更新,並有數據實時處理的印象。與nvd3.js實時線圖
現在我已經能夠創建一個函數來定期更新圖形,但是我無法像在向左轉換的線那樣在「狀態」之間進行平滑過渡。
Here是我使用的是什麼nvd3.js,這裏的有趣的代碼是:
d3.select('#chart svg')
.datum(data)
.transition().duration(duration)
.call(chart);
現在,我已經能夠生產我想用d3.js什麼,但我更希望能夠使用nvd3.js提供的所有工具。 Here是我想生產什麼用nvd3
使用d3.js過渡有趣的代碼是:
function tick() {
// update the domains
now = new Date();
x.domain([now - (n - 2) * duration, now - duration]);
y.domain([0, d3.max(data)]);
// push the accumulated count onto the back, and reset the count
data.push(Math.random()*10);
count = 0;
// redraw the line
svg.select(".line")
.attr("d", line)
.attr("transform", null);
// slide the x-axis left
axis.transition()
.duration(duration)
.ease("linear")
.call(x.axis);
// slide the line left
path.transition()
.duration(duration)
.ease("linear")
.attr("transform", "translate(" + x(now - (n - 1) * duration) + ")")
.each("end", tick);
// pop the old data point off the front
data.shift();
}
我同意你所說的。不過我的問題是使用nvd3而不是d3。我的問題中的第一個鏈接顯示了我現在在nvd3中的內容,第二個鏈接顯示了我使用d3.js完全運行的版本。您的第二種方法是我用於d3解決方案的方法。 – 2013-05-16 23:40:31
好吧,我的不好...你的解決方案已經在用d3來完成了 – 2013-05-17 04:17:34