今天我用enter-update-exit邏輯創建了一個簡單的條形圖 - 一切正常。現在我將使用折線圖來做同樣的事情 - 圖表的整個數據集可以隨時更改,所以我會平滑地更新圖表。我無法找到一個線形圖和enter-update-exit邏輯的好例子(或者我看錯了)。目前,我一定要記住,如果圖表被稱爲首次或數據進行更新(數據已經改變) - 這是我的髒版:d3折線圖與輸入更新退出邏輯
var channelGroup = d3.select(".ch1");
// init. Line Chart
if (firstLoad) {
channelGroup
.append('path')
.attr("class", "line")
.style("stroke", channel.Color)
.transition()
.ease("linear")
.duration(animChart/2)
.attr('d', line(channel.DataRows));
}
// update Line Chart
else {
channelGroup
.selectAll("path")
.data([channel.DataRows])
.transition()
.ease("linear")
.duration(animChart/2)
.attr("d", function (d) { return line(d); });
}
我怎麼能在一個良好的方式實現這一點? ... 謝謝!
你見過[此教程](http://www.d3noob.org/2013/02/update-d3js-data-dynamically-button.html)? –
不,謝謝你! – Kollisionskurs