The code below displays a pie chart using flot charts. It works perfectly but I need to place the data generated (abcdata) dynamically using PHP and then use a setInterval to refresh the data every 5 seconds. The data is not showing in index.php and the pie chart disappears. I believe it has got something to do with the var abdata variable being loaded via jQuery but I'm not sure how to solve it.
My intention is to load the data (abdata) via PHP and refresh the data every few seconds.
// Code in index.php
setInterval(function() {
$(".test").load("test.php");
}, 1000);
// Code in the test.php file:
var abdata = [
{ label: "B", data: 90}, // The data values are queried using PHP and SQL
{ label: "C", data: 112},
{ label: "A", data: 112}
];
if($("#chart").length)
{
$.plot($("#chart"), abdata,
{
series: {
pie: {
innerRadius: 0.5,
show: true
}
},
legend: {
show: false
},
colors: ["#f29020","#434343", "#3fbed3"]
});
}
I would be grateful if anyone could help out! Thanks in advance!