I have a highcharts chart running with ajax,
it gets the data and refreshes every 15 seconds which is perfectly fine
except, i need the chart to load striaght away and then refresh every 15seconds,
at the moment it waits 15 seconds before displaying on page load.
code below
function getLiveData() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: '/get-converted-data',
success: function(point) {
var x = (new Date()).getTime();
console.log(point);
var series = liveChart.series[0];
var series1 = liveChart.series[1];
var series2 = liveChart.series[2];
var series3 = liveChart.series[3];
shift = series.data.length > 20;
shift1 = series1.data.length > 20;
shift2 = series2.data.length > 20;
shift3 = series3.data.length > 20;
// add the points
liveChart.series[0].addPoint([x, point[0]], true, shift);
liveChart.series[1].addPoint([x, point[1]], true, shift1);
liveChart.series[2].addPoint([x, point[2]], true, shift2);
liveChart.series[3].addPoint([x, point[3]], true, shift3);
// call it again after 15 seconds,
//this is loading the actual chart every 15 seconds,
//i need the chart to load instantly then refresh every 15 seconds, any ideas?
setTimeout(getLiveData, 15000);
},
cache: false
});
}