score:308
Here is the solution:
d3.select("svg").remove();
This is a remove
function provided by D3.js.
score:2
I follow the code from https://www.d3-graph-gallery.com/graph/line_basic.html and had this code:
svg.append("path")
.datum(filteredData)
.attr("fill", "none")
.attr("stroke", "blue")
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x(function(k) { return x(k.date) })
.y(function(k) { return y(k.value) })
)
So for me it turned out to be that I slap this right before the generation of new line:
d3.selectAll("path").remove()
score:4
You should use append("svg:svg")
, not append("svg")
so that D3 makes the element with the correct 'namespace' if you're using xhtml.
score:5
You could also just use jQuery to remove the contents of the div that contains your svg.
$("#container_div_id").html("");
score:8
I am using the SVG using D3.js and i had the same issue.
I used this code for removing the previous svg but the linear gradient inside SVG were not coming in IE
$("#container_div_id").html("");
then I wrote the below code to resolve the issue
$('container_div_id g').remove();
$('#container_div_id path').remove();
here i am removing the previous g and path inside the SVG, replacing with the new one.
Keeping my linear gradient inside SVG tags in the static content and then I called the above code, This works in IE
score:34
I had two charts.
<div id="barChart"></div>
<div id="bubbleChart"></div>
This removed all charts.
d3.select("svg").remove();
This worked for removing the existing bar chart, but then I couldn't re-add the bar chart after
d3.select("#barChart").remove();
Tried this. It not only let me remove the existing bar chart, but also let me re-add a new bar chart.
d3.select("#barChart").select("svg").remove();
var svg = d3.select('#barChart')
.append('svg')
.attr('width', width + margins.left + margins.right)
.attr('height', height + margins.top + margins.bottom)
.append('g')
.attr('transform', 'translate(' + margins.left + ',' + margins.top + ')');
Not sure if this is the correct way to remove, and re-add a chart in d3. It worked in Chrome, but have not tested in IE.
score:65
Setting the id attribute when appending the svg element can also let d3 select so remove() later on this element by id :
var svg = d3.select("theParentElement").append("svg")
.attr("id","the_SVG_ID")
.attr("width",...
...
d3.select("#the_SVG_ID").remove();
score:170
If you want to get rid of all children,
svg.selectAll("*").remove();
will remove all content associated with the svg.
Source: stackoverflow.com
Related Query
- How can I remove or replace SVG content?
- How can I copy the content of my SVG and append it to another SVG frame?
- How can I scale an SVG so that the content drawn in it to fit the container size?
- D3 How can i replace a SVG element
- d3.js - How can I set the cursor to hand when mouseover these elements on SVG container?
- How can I dynamically resize an SVG rect based on text width?
- How can I set the each line color or width in SVG path
- How can I animate infinite marker movement down an SVG path without very high CPU usage?
- How can I center text on a D3.js SVG grid rect?
- How can I display a placeholder image in my SVG until the real image is loaded?
- How to remove shapes from filled SVG path
- How can I convert SVG coordinates (x,y) defined relatively to an element into absolute coordinates/position?
- How can I remove a line from the 110m TopoJson world map?
- How can I find the translated co-ordinates of an SVG element?
- How can I get the natural width and height of an svg image element?
- How can I pass attributes of an SVG element to a new event in D3?
- How can I use a leaflet layer control to toggle a d3 svg overlay?
- How can I remove Decimals in nvd3.js graphs?
- How can I remove non-integer ticks while zooming in with D3.js?
- How can I use SVG translate to center a d3.js projection to given latitude and longitude values?
- How can I change style class & content of text for ancestors in this d3.js tree?
- How can I make a SVG group follow a gradient in a circle
- D3 renders SVG. How can I get that SVG programmatically?
- How can I add an external group to an existing svg with d3.js?
- How to remove svg inside a div
- How can I convert an svg to d3.js code?
- How can the elements in SVG can't be dragged out of the scope of SVG?
- How can I remove spurious line on zoomable sunburst?
- How can I put the Germany map on a svg in HTML? D3js
- How can I scale my map to fit my svg size with d3 and geojson path data
More Query from same tag
- D3: Create a grouped bar chart from json objects
- Display CSS image sprite in SVG without using foreignObject
- D3.js: How to keep marker and text on same position when zooming in and out
- How can I find the frequency of each member in my data set
- Swap a D3.js created drop down menu into a HTML created drop down menu
- Why do I get an error on `SimulationNodeDatum` when using D3 on Angular 10 for force directed graph?
- D3js: Dragging a group by using one of it's children
- Setting static number of ticks for a chart in NVD3 and ClojureScript
- D3 Zoom Settings
- D3 seemingly updating wrong SVG element
- How to avoid labels overlapping in a D3.js pie chart?
- d3.js switch json map depending on year
- How to achieve dimensional charting on large dataset?
- inverting a stacked bar chart in d3.js
- Select element with specific properties d3.js
- local host to open html file
- Installing rubygem d3js into a Rails 5 app, receiving railties compatibility issues
- d3.js - Change value for Tooltip with radio button
- Tooltip gives wrong values in my heatmap diagram
- reading SVG icon files from disk compared to caching the SVG data?
- Selecting duplicate id's from an SVG exported from Illustrator in d3.js
- Crossbrowser svg donut chart
- How do I disable my zoom functionality in D3.js?
- Graph Not Working: Stacked Bar Chart - Date versus Values
- how to disable sorting data in x axis in d3 line chart?
- Strange D3 pan/zoom behaviour - accelerating pan
- Chart is not showing the data array of objects
- How to properly add FontAwesome icons on d3 nodes?
- Is it possible to set a border or linear gradient to an SVG element - line
- D3 - Unable to get data parameter on click event