Using D3 transition method with data for scatter plot

前端 未结 2 352
清歌不尽
清歌不尽 2020-12-10 12:53

So I\'m new to D3 and have little exp with JavaScript in general. So I have been following some tutorials am currently using source code that creates a basic scatter plot.

2条回答
  •  醉梦人生
    2020-12-10 13:28

    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);
    }
    )
    

提交回复
热议问题