Flot and PHP
Flot and PHP
Hello I am trying to populate a flot chart using PHP but things do not seem to be working. If I put in the numbers manually for the chart everything is working fine but if I pass them via ajax from a php script nothing displays.
here is my php:
-
$array = array();
$array[] = array(strtotime($result[0][1] ."UTC") * 1000,round($result[0][0],1));
$array[] = array(strtotime($result[1][1] ."UTC") * 1000,round($result[1][0],1));
$array[] = array(strtotime($result[2][1] ."UTC") * 1000,round($result[2][0],1));
$array[] = array(strtotime($result[3][1] ."UTC") * 1000,round($result[3][0],1));
$array[] = array(strtotime($result[4][1] ."UTC") * 1000,round($result[4][0],1));
$array[] = array(strtotime($result[5][1] ."UTC") * 1000,round($result[5][0],1));
$array[] = array(strtotime($result[6][1] ."UTC") * 1000,round($result[6][0],1));
$array[] = array(strtotime($result[7][1] ."UTC") * 1000,round($result[7][0],1));
$array[] = array(strtotime($result[8][1] ."UTC") * 1000,round($result[8][0],1));
$array[] = array(strtotime($result[9][1] ."UTC") * 1000,round($result[9][0],1));
$array[] = array(strtotime($result[10][1] ."UTC") * 1000,round($result[10][0],1));
print_r(json_encode($array));
and here is my javascript:
-
$(function () {
var q1;
$(document).ready(function() {
//Question 1
$.get("http://w3.sono-tek.com/modules/it_tickets/jQuery.php", { type: "s_result", value: "Q1" },
function(c_data) {
//q1 = eval("("+data+")").data;
q1 = c_data;
alert(q1);
});
});
var data = [
{ label: "Q1",
data: q1 }];
var options = {
legend: {
show: true,
margin: 10,
backgroundOpacity: 0.5
},
points: {
show: true,
radius: 3
},
lines: {
show: true
},
xaxis: {
mode: "time",
timeformat: "%b"
//ticks: 6,
//tickDecimals: 0
},
yaxis: {
min: 7,
max: 10,
tickDecimals: 0
}
};
var plotarea = $("#plotarea");
plotarea.css("height", "450px");
plotarea.css("width", "700px");
$.plot( plotarea , data, options );
});
The background of the chart appears but no data. I suspect that its because the json_encode returns a string. but any help would be greatly appreciated. Thanks.