Ferguson Ferguson - 2 months ago 16
Ajax Question

Amcharts add value to dataset from external source (temperatue)

I have a temperature sensor connected over http and I would like to add temperature to the Amcharts every 5 seconds. Have someone some example how to add new value to the current dataset? I will use line chart to represent temperature on y axis and datetime on x

thank you


The general idea behind dynamically updating a chart is to add a new element to your chart's dataProvider then call its validateData method. While it doesn't use AJAX, this demo basically has the framework laid out for you in the function that is called in the setInterval call:

setInterval( function() {
  // make your ajax call here, then on a successful callback:
  // add data item to the array
  chart.dataProvider.push( {
    /* new data */
  } );

}, 5000 );

It also shifts the old data off the chart, which you may want to consider if you have a lot of data points added to the chart. A regular serial chart's performance will degrade after several hundred to a thousand points or so.