I’m using the HighCharts library to create a chart and then update it via the jQuery getJSON() function. However, I’m stuck as to how to update the chart when I receive the updated information. I have a call to setInterval(function() { update_chart(chart); }, 2500); which updates the chart object by first destroying the chart at chart, getting new data via the getJSON() call, and then redrawing the chart in the anonymous function fired on success. The problem is, after I update once, redrawing the chart, I lose the reference to the new chart. Is there a way to pass it back?
An alternate approach would be to pass the reference of the chart to the success function and simply update the data series that are there. However, I can’t seem to get the success function to take the chart parameter. Is there a way to do that?
You need to declare your chart as a global variable. That way you can access it from anywhere in javascript. Have look at the instructions provided by highcharts team http://www.highcharts.com/documentation/how-to-use#live-charts