score:9

Accepted answer

you are creating a new chart, that's why you end up with the old chart behind the new one.

one simple option that i've used: remove the old chart from the canvas that you are using for the chart:

$('#canvas').replacewith('<canvas id="canvas"></canvas>');

and now create the chart with the new data in the same canvas

var ctxchart = document.getelementbyid("canvas").getcontext("2d");
window.mychart = new chart(ctxchart).line(newdata, options);

hope it helps!

score:1

for those of you wondering the same thing with pie charts, doesn't look like there's a given public method that works but you can use an easy workaround by removing the data yourself:

var piechart = new chart(ctx).doughnut(undefined, piechartoptions);
piechart.segments.splice(0, piechart.segments.length);

seems to work ok, wish they would just add a remove all method or make the clear actually work.


Related Query

More Query from same tag