I am putting a highcharts dynamic chart, however I am having a problem, I need to get a value from a PHP page and put in the point y of the graph, for that use a javascript function called a priori of "test" follows the code of the chart:
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
Highcharts.chart('container', {
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = teste();//FUNÇÃO PARA PEGAR VALOR DA PAGINA PHP
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Ligacoes Online'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Valor'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Data da ligacao',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
}())
}]
});
});
The function " test " has to put a value in the graph, (for example: 2), follows the code of the test function, where it takes a value from a SELECT in the database , it is worth mentioning that it is working ( seen by console.log ), but when I use return json it does not return:
function teste() {
$.ajax({
type: 'POST',
url: 'file_get_value.php',
cache: false,
dataType: 'json',
success: function (json) {
console.log(json);
return json;
}
});
}
As I am still in the process of improving my programming in javascript I came across this problem that apparently is simple, but it is giving me a headache.