I'm still pretty new to JS, JQuery and Highcharts.
From the "dynamic-update" example in HighStock:
chart: {
events: {
load: function() {
var series = this.series[0];
var y = 1;
setInterval(function() {
var x = (new Date()).getTime();
$.get('get_most_recent_point_from_database.php',function(data){
alert( data);
var y = data;
// y = 10;
alert( y);
series.addPoint([x, y], true, true);
});
}, 1000);
}
}
},
"get_most_recent_point_from_database.php" produces an integer.
The alerts show the integer, but series.addPoint doesn't add the integer to the chart. The chart just goes blank.
The "y = 10;" (commented out in the code) will update the chart with 10.
I set y to integer by "var y = 1;" thinking that might help.
Any thoughts? I can put it all in JSFiddle if it helps.
THE FIX ======================
setInterval(function() {
var x = (new Date()).getTime(), y;
$.get('get_most_recent_point_from_database.php',function(data){
y = parseFloat(data).toFixed(1);
series.addPoint([x, y], true, true);
});
}, 1000);
How your data looks like? probably it is string, so try to convert it by parseFloat(data) (if it is single point) or use json_encode() in php. (All depends how your php file looks like)