我有一个简单的线条图,每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
它不起作用。 –