Reputation: 99
I'd like to render a chart from a JSON
file with jqPlot
.
With the help of some examples I came to the following code that work fine:
$(document).ready(function(){
var ajaxDataRenderer = function(url, plot) {
var ret = null;
$.ajax({
// have to use synchronous here, else returns before data is fetched
async: false,
url: url,
dataType:'json',
success: function(data) {
ret = data;
}
});
return ret;
};
var jsonurl = "./json_3.json";
plo12 = $.jqplot('chart2', jsonurl,{
dataRenderer: ajaxDataRenderer,
title: 'User Activity Chart (AJAX JSON Data Renderer)',
legend: {show:true},
seriesDefaults: {
showMarker:true,
pointLabels: { show:true }
},
axes: {
xaxis: {
renderer:$.jqplot.DateAxisRenderer,
tickOptions: {
formatString:'%a %d %b %H:%M'
}
},
yaxis: {
tickOptions: {
show: false
},
}
}
});
});
And the JSON
file looks like this:
[
[
["2012-02-07 10:00", 10, "start"],
["2012-02-07 23:43" ,10, "end"]
],
[
["2012-02-07 01:45", 20, "start"],
["2012-02-07 08:18", 20, "end"]
]
]
This way I can draw as many series as I want. The only problem now is that the labels (start/end) are not printed on the chart and I can't understand why. I thought that this line of code was enough:
pointLabels: { show:true }
Any advice?
Upvotes: 3
Views: 1063
Reputation: 31
you should use:
xaxis: {
renderer:$.jqplot.DateAxisRenderer,
tickOptions: {
formatString:'%H:%M'
}
},
Upvotes: 3