Chandru
Chandru

Reputation: 61

Remove or clear previously drawn dimple chart

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

Answers (2)

Chandru
Chandru

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

ne8il
ne8il

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

Related Questions