I fetch data from an API, and then store the data in localstorage.
e.g:
This fetches data from an API for use with Highcharts, and stores/updates it in localstorage (jStorage).
updateLocalStorage: function(id) {
//Check if local storage needs updating
if (isNaN($.jStorage.get(id))) {
//Data exists in Localstorage, merge data
//Query API for highstock data
return $.post('api/', {
data_id: id
}, function(data) {
if (data) {
var merged = $.extend($.jStorage.get(id), data);
$.jStorage.set(id, merged);
}
});
//return true;
}
}
Once this data has been fetched I then render highcharts from the data that is stored in localstorage.
$.when(updateLocalStorage(id)).then(function(response){
if(response){
//Local storage is up to date. Render chart
}
});
I can also fetch data from the API using a timer and update localstorage, when I want to re-render the chart I can just use the highcharts setData method, e.g:
var json = $.jStorage.get(id);
for(i =0; i < json.data; i++) {
chart_object.series[i].setData(json.data[i]);
}