javascript - 使用forcegraph D3 清除SVG

标签 javascript d3.js svg

我正在尝试清除我的 d3 力图,并将其绘制为 SVG,如下所示:

enter image description here

我尝试用以下方法清除我的 svg:

graph["links"] = [];
      graph["nodes"] = [];
      queryWords = [];
      update();

但只有节点被删除,链接仍然显示,即使我的force.links为空:

enter image description here

有人有办法解决这个问题吗? 谢谢。

最佳答案

您可以使用以下方式删除/清除:

d3.select("svg").remove();//Removes the whole svg
d3.selectAll("g").remove();//Removes the DOM and data of all g appended to svg
d3.select(".class").remove();//Removes any particular class attr added to svg or subelements.
d3.select("#id").remove();//Removes any particular id attr added to svg or subelements.

关于javascript - 使用forcegraph D3 清除SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37168960/

相关文章:

javascript - 动态加载表格主体内容,无需更改表格标题

javascript - 使用 Function.apply() 构造具有原型(prototype)的对象

javascript - 使用 jquery 将整个文件作为字符串分配给 var

javascript - 更改D3 geoCircle的大小和 Angular

javascript - 用于 HTML-JavaScript 动画的简单 SVG 绘图

javascript - 如何使用javascript逐字反转字符串中的单词?

javascript - 如何用一个值函数设置多个属性?

javascript - 如何将数据从指令传递到 Controller

javascript - 错误 : Invalid value for <rect> attribute width ="NaN" 6d3. v3.min.js:1 错误:<text> 属性 x ="NaN"的值无效

javascript - 旋转图像的 SVG 低性能