我有一個簡單的線條圖,每5秒鐘檢查一次更新&如果需要,重新繪製線條/比例。除了數據點,這一切都很好。d3.js動畫/過渡圈更新
我在重畫中丟失了什麼以移動點?圖形第一次渲染時,點就在那裏。但是在更新時,當線條被重新繪製時它們不會移動。所以我在更新時選擇了一個新的數據源,舊的數據點保持不變。
上更新重繪
var svgAnimate = d3.select("#animateLine").transition();
svgAnimate.select(".line") // change the line
.duration(750)
.attr("d", valueline(data));
svgAnimate.selectAll(".circle") // change the circle
.duration(750)
.attr("d", valueline(data));
svgAnimate.select(".x.axis") // change the x axis
.duration(750)
.call(xAxis);
svgAnimate.select(".y.axis") // change the y axis
.duration(750)
.call(yAxis);
初始繪圖:
svgAnimate.selectAll("dot")
.data(data)
.enter().append("circle")
.attr("class", "circle")
.attr("r", 5)
.style("fill", function(d) {
if (d.close <= 400) {return "red"}
else { return "black" }
;})
.attr("cx", function(d) { return x(d.date); })
.attr("cy", function(d) { return y(d.close); })
這是我不想要的東西。
你可以設置一個jsFiddle嗎? –
@ChrisJamesC:這是[jsFiddle](http://jsfiddle.net/UZpHZ/4/)。雖然,我無法讓我的數據源在其中正確更新。在我的本地機器上,我使用csv作爲源類型。我認爲我做了必要的改變,以使其發揮作用。 – EnigmaRM
它不起作用。 –