Amr H. Abd Elmajeed
Amr H. Abd Elmajeed

Reputation: 1521

dc.js clear all charts

I have a html page with 5 dc.js charts.

I would like to clear all the charts (completely remove them from the page) given a certain event.

something like:

dc.clearAll();

I checked the API's and such a method does not exist.

I implemented a workaround with jquery:

$('#chart1').empty();
$('#chart2').empty();
$('#chart3').empty();
$('#chart4').empty();
$('#chart5').empty();

The workaround works but i was wondering if there was a cleaner way to do it, preferably with the API.

Upvotes: 2

Views: 3334

Answers (2)

Krunal Shah
Krunal Shah

Reputation: 673

d3.selectAll("svg").remove() worked for me.

Upvotes: 2

elsherbini
elsherbini

Reputation: 1616

If when you create the charts you name them, you can use the api like so:

chartOne.resetSvg()
chartTwo.resetSvg()

etc. This will leave behind an empty <svg> tag in the div.

Upvotes: 5

Related Questions