I was dealing today with Flot and when I try to get the data from PHP (with json_encode()) I can’t get it work properly.
I could display labels but no chart is created.
PHP
$newData = array();
$newData[0] = array();
$newData[1] = array();
$newData[2] = array();
$newData[0]['label'] = 'Slice 1';
$newData[1]['label'] = 'Slice 2';
$newData[2]['label'] = 'Slice 3';
$newData[0]['color'] = '#122b45';
$newData[1]['color'] = '#064792';
$newData[2]['color'] = '#9e253b';
$newData[0]['data'] = array();
$newData[0]['data'][0] = 1;
$newData[0]['data'][1] = 1000;
$newData[1]['data'] = array();
$newData[1]['data'][0] = 1;
$newData[1]['data'][1] = 500;
$newData[2]['data'] = array();
$newData[2]['data'][0] = 1;
$newData[2]['data'][1] = 100;
echo json_encode($newData);
jQuery
$.ajax({
url: "get-stats.php",
type: "POST",
async: false,
dataType : 'JSON',
data: {section: section, endDate: endDate, startDate: startDate},
success: function(data){
$.plot($("#flot"), data,{
series: {
pie: {
show: true
},
grid: {
hoverable: true,
clickable: true
}
}
}
});
Can anyone tell me where I’m doing wrong?
Labels and colors are ok but it seems I can’t get the data.
Thank you for your time and concern in advance.
I found the problem and solution. I had to do following for the data;
This saved my day.