NVD3, Clear svg before loading new chart
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();
This works for me:
var svg = d3.select("svg");
svg.selectAll("*").remove();
If you are developing a dashboard having multiple widget showing different d3 charts then use the following
d3.selectAll("#d3-donutChart > *").remove();
this will only clear the specific chart, not all the svg's in the webpage.
Add this line just after subscribing to data in angular 2.