NVD3,在加载新图表之前清除svg [英] NVD3, Clear svg before loading new chart

查看:164
本文介绍了NVD3,在加载新图表之前清除svg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个不同的 NVD3 图表,我在同一个svg中调用。
我使用按钮来调用函数,每个函数都包含一个使用自己的数据的新图表。



有没有办法清除我的单个svg而不删除它?
我想按一个按钮来调用我的图表,但在加载新图表之前清除svg。



这不是一个问题,当使用图表...调用两个 multibarhorizo​​ntal 图表,例如,只是更新形状,这是好的。



提前感谢



p> EDIT - 答案必须是d 3.select(svg)。remove(),但只是删除svg。

解决方案

您可以使用选择SVG下方的所有元素svg> *选择器,即删除所有这些,

  d3.selectAll svg> *)。remove(); 


I have several different NVD3 charts that I call upon in the same svg. I use buttons to call functions, each containing a new chart that uses its own data.

Is there a way to clear my single svg without deleting it? I wish to press a button to call my chart, but clear the svg before the new chart is loaded.

It's not an issue when using the kind of chart... calling two multibarhorizontal charts, for example, just updates the shapes, which is fine. The problem is loading two different charts, like a line and a bar.

Thanks in advance

EDIT - The answers must be something like d3.select("svg").remove() but that just deletes the svg. I only want to clear it.

解决方案

You can select all the elements below the SVG with the "svg > *" selector, i.e. to remove all of those, do

d3.selectAll("svg > *").remove();

这篇关于NVD3,在加载新图表之前清除svg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆