Home forums Using CanvasJS Cant update Dynamic Chart via AJax JSON for Candle Stick Reply To: Cant update Dynamic Chart via AJax JSON for Candle Stick

#17216

Indranil Deo
Member

@tandemco,

1. Should we clear the chart? right now it plots the data right on top of the last data?

You should empty the dataPoints on ecah AJAX call.

2. I tried (and it didn’t work) in the ajax
chart.options.data[0].dps = data;
chart.render();

It should be chart.option.data[0].dataPoints = data instead of chart.options.data[0].dps = data;

3. I also tried to set dps to [] reset the array to clear the chart to no avail.

You can render chart initially with JSON data. Then you can update the chart dynamically from JSON data.
Soon after every AJAX call emptying dps & updating dataPoints accordingly will work fine in your case.

Please take a look at this jsfiddle. Also have a look at Live Updating Charts from JSON API & AJAX.

__________
Indranil Deo,
Team CanvasJS