I am trying to draw a flot chart using some Ajax data which is as follows when I console.log
it :
[{ label:"series1",
data : [[1459555200000,200],[1459987200000,440]],last:true}]
but when I use it as data in flot chart, the chart is blank , whereas if I hardcode it it runs great.
My code is:
$.get('chartgadmin.php',
function (d) {
console.log(d);
var data = [d];
var labelColor = chart.css('color');
var options = {
colors: chart.data('color').split(','),
series: {
shadowSize: 0,
lines: {
show: true,
lineWidth: false,
fill: true
},
curvedLines: {
apply: true,
active: true,
monotonicFit: false
}
},
legend: {
container: $('#flot-visitors-legend')
},
xaxis: {
mode: "time",
timeformat: "%d %b",
font: {color: labelColor}
},
yaxis: {
font: {color: labelColor}
},
grid: {
borderWidth: 0,
color: labelColor,
hoverable: true
}
};
chart.width('100%');
// Create chart
var plot = $.plot(chart, data, options);
});
Any help will be appreciated.
Thanks
It seems you are not parsing your argument " d " in chart readable format,so whenever you are passing hardcode data it works fine,but the object which you are passing directly will get by the chart datasource,so you have to use,
JSON.parse(d);