我正在尝试清除我的 d3 力图,并将其绘制为 SVG,如下所示:
我尝试用以下方法清除我的 svg:
graph["links"] = [];
graph["nodes"] = [];
queryWords = [];
update();
但只有节点被删除,链接仍然显示,即使我的force.links为空:
有人有办法解决这个问题吗? 谢谢。
最佳答案
您可以使用以下方式删除/清除
:
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/