0
I’m putting together a chart highcharts dynamic, but I have a problem, I need to take a value of a PHP page and put in the point y of the graph, for this I use a function javascript called a priori "test" follows the code of the graph:
$(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" have to put a value in the graph, (for example: 2), follow the code of the test function, where it takes a value of a SELECT in the database, it is valid to emphasize 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 javascript programming I came across this problem that is apparently simple, but is giving me a headache.