Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove existing nodes in d3.js
    primarykey
    data
    text
    <p><br /> I have already visit <a href="https://stackoverflow.com/questions/11606214/add-and-remove-nodes-in-d3js?lq=1">add and remove nodes in D3js</a> but it don't solve my problem.</p> <p>There are some nodes at first time, then I want to add nodes dynamically and want if node is already exists it update that nodes and don't do duplicate.</p> <p>now it is making duplicate not updating existing ones.<br /> Here is main code and full code and working fiddle is <a href="http://jsfiddle.net/qYStf/1/" rel="nofollow noreferrer">here</a></p> <pre><code>//handles node elements var circles = svg.selectAll('g'); //update graph (called when needed) function restart() { /*************************************** Draw circles (nodes) ****************************************/ circles = circles.data(data.nodes); var g = circles.enter() .append("g") .attr("class", "gNode") .attr("cursor", "pointer") .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }) .call(force.drag); g.append("circle") .attr({ "class": "node", "cx": function(d) { return rScale(d.NumOccurrences); }, "cy": function(d) { return rScale(d.NumOccurrences); }, "r": function(d) { return rScale(d.NumOccurrences); } }) .style("fill", function(d, i) { return colors(i); }) .style("stroke", "#000"); g.append("text") .attr({ "x": function(d) { return rScale(d.NumOccurrences); }, "y": function(d) { return rScale(d.NumOccurrences); }, "font-family": "sans-serif", "font-size": "20px", "fill": "black", "text-anchor": "middle" }) .text( function (d) { return d.name; }); g.append("title") .text(function(d) { return d.name; }); // remove old nodes circles.exit().remove(); // set the graph in motion force.start(); } // app starts here restart(); function dynamicAddNodes() { var updatedata = {"name":"ios","NumOccurrences":"500","color":"green","x":0,"y":1} data.nodes.push(updatedata); restart(); } setInterval(dynamicAddNodes, 10000); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload