How to update elements of D3 force layout when the underlying data changes

后端 未结 2 1199
慢半拍i
慢半拍i 2020-12-29 05:15

I\'m using one of the force layout examples (http://bl.ocks.org/1153292) to show a network on my web site.

I allow the user to choose which type of links to see at a

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 06:11

    I've found the answer in this post

    var circle = svg.selectAll("circle")
        .data(data);
    
    circle.enter().append("circle")
        .attr("r", 2.5);
    
    circle
        .attr("cx", function(d) { return d.x; })
        .attr("cy", function(d) { return d.y; });
    
    circle.exit().remove();
    

    The answer is that I need to call attr operator on the result of selectAll.data and not on the result of the append operator.

提交回复
热议问题