John Fred John Fred - 3 months ago 12
Javascript Question

Highstock - Replace data set every min

I'm trying to have my Highstock chart update every minute, by replacing its existing data set with one that is extracted from a url request (which would have different data at different times).

So far I'm not even able to get the data to refresh based on manual changes.

Work so far: https://jsfiddle.net/Lz8gLw8j/

I'm trying to test changing data and then updating it with:

varData = [[0,0],[1,2]]
$('#chart2').highcharts().redraw();


Which does nothing.

Answer

You can set the new data to highchart in following way:

     var newData = [
       [1251763200000, 23.61],
       [1251849600000, 23.60],
       [1251936000000, 23.79]
     ]

     var chart = $('#chart2').highcharts();
     chart.series[0].setData(newData);

     $('#chart2').highcharts().redraw();

Updated fiddler:

https://jsfiddle.net/Lz8gLw8j/5/