Home forums Using CanvasJS clearing or redrawing graph Reply To: clearing or redrawing graph

#8645

Anjali
Participant

Palli,

We just looked into your code and it turns out you are not clearing/resetting the dataPoints before assigning new values to it. You can do so by assigning a new empty array as shown below.

chart.options.data[0].dataPoints = [];
for(var i = 1 ; i < xtmax; i++) {
  xtime += 1;
  kt = Ratek1*xtime;
  Aconct=Aconct0*Math.exp(-kt);
  chart.options.data[0].dataPoints[i-1] = {x:xtime, y:Aconct};
};
chart.render();
chart.options.data[1].dataPoints = [];
for(var i = 1 ; i < xtmax; i++) {
        xtime += 1;

   Aconct0kt1 = 1+(Aconct0*Ratek2*xtime);
   Aconct2=Aconct0/Aconct0kt1;
	chart.options.data[1].dataPoints[i-1] = {x:xtime, y:Aconct2}
};

chart.render();
});