今天我创建了一个简单的条形图与enter-update-exit逻辑 - 一切工作正常。现在我将使用折线图 - 图表的整个数据集可以随时更改,因此我将平滑更新图表。我找不到一个好的例子与折线图和enter-update-exit逻辑(或我看错了)。目前,我必须记住,如果图表被第一次调用或数据更新(数据已更改) - 这是我的脏版本:
today I created a simple Bar Chart with the enter-update-exit logic - everything works fine. Now I will do the same with a line chart - the whole dataset for the chart can change at any time, so I will update the chart smoothly. I can't find a good example with a line chart and the enter-update-exit logic (or I'm looking wrong). Currently I have to remember that if the chart is called for the first time or the data to be updated (data has changed) - This is my dirty version:
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); });
}
我怎么能以一种很好的方式实现这一点? / p>
how can I realize this in a good manner?... thx!