Using D3 transition method with data for scatter plot

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 10:57:29

First, before addressing the transition issue, you need to refactor things a bit. You're going to want to call an update(newData) function every time your data changes, and have this function do all the necessary updates.

This tutorial by mbostock describes exactly the "general update pattern" you'll need.

Parts II and III then go on to explaining how to work transitions into this pattern.

They're very short. And once you understand them, you'll have just about all the info you need to do this.

otayeby

I guess you just have to specify .transition() function after .data(newData) function

In the following example Y2 is a node in a JSON file, where Y1 was the previous one used

Example:

//Creating the button
var button = d3.select("body")
.append("input")
.attr("type","button")
.attr("value", "A button");

//Transitioning process
button.on("click", function()
{   circles
    .data(data.Y2)
    .transition()
    .attr("cx", function(d)
    {
        return d[0];
    }
    )
    .attr("cy", 300);
}
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!