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

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

问题描述

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

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.

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

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.

使用这种图表时,这不是问题……例如,调用两个 multibarhorizo​​ntal 图表,只需更新形状,这很好.问题是加载两个不同的图表,例如折线和条形图.

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.

提前致谢

EDIT - 答案必须类似于 d3.select("svg").remove() 但这只会删除 svg.我只想清除它.

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

推荐答案

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

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天全站免登陆