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:
我想使用jqPlot从JSON文件渲染图表。在一些例子的帮助下,我得到了以下可以正常工作的代码:
$(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:
JSON文件如下所示:
[
[
["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?
1 个解决方案
#1
3
you should use:
你应该使用:
xaxis: {
renderer:$.jqplot.DateAxisRenderer,
tickOptions: {
formatString:'%H:%M'
}
},
#1
3
you should use:
你应该使用:
xaxis: {
renderer:$.jqplot.DateAxisRenderer,
tickOptions: {
formatString:'%H:%M'
}
},