本文介绍了我怎样才能取出或更换SVG内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一块创造(使用D3.js)的JavaScript code的 SVG 元素,其中包含一个图表。我想根据使用AJAX的新数据从Web服务来更新图表,问题是,每次我点击更新按钮,它会生成一个新的 SVG ,所以我想删除旧的或更新的内容。

I have a piece of JavaScript code which creates (using D3.js) an svg element which contains a chart. I want to update the chart based on new data coming from a web service using AJAX, the problem is that each time I click on the update button, it generates a new svg, so I want to remove the old one or update its content.

下面是从我创建JavaScript函数代码段的 SVG

Here is a snippet from the JavaScript function where I create the svg:

var svg = d3.select("body")
        .append("svg")
        .attr("width", w)
        .attr("height", h);

如何删除旧的 SVG 元素或至少替换现有的内容?

How can I remove the old svg element or at least replace its content?

推荐答案

下面是解决方案:

d3.select("svg").remove();

这是D3.js提供的删除的功能。

This is a remove function provided by D3.js.

这篇关于我怎样才能取出或更换SVG内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:16
查看更多