Reputation: 61
How to remove or clear previously drawn dimple bar chart.
I did the following to redraw chart with new data:
chart.data = newData; chart.draw();
This will redraw if data is not empty. If new data is empty, previously drawn chart remains and is not getting erased. How to clear the previously drawn chart?
Upvotes: 3
Views: 4412
Reputation: 61
Thank you. I could get it from series.shapes.remove(), below is the code snippet:
if (0 === total_records) {
chart.series[0].shapes.remove();
chart.draw(2000);
}
else {
chart.series[0].shapes.remove();
chart.series.splice(0, 1);
chart.addSeries("Name", dimple.plot.bar);
chart.data = p_data;
chart.draw(2000);
}
Upvotes: 0
Reputation: 2427
If you are trying to remove the entire chart (shapes and axis and all), you could do:
chart.svg.selectAll('*').remove();
If you are just trying to remove the bars/lines/shapes and leave the axes and legend intact, you can do :
chart.series.forEach(function(series){
series.shapes.remove();
});
I think this may actually be a bug related to this one : https://github.com/PMSI-AlignAlytics/dimple/issues/29 to clear out old series if you set chart.data to an empty array.
Upvotes: 4