0
我有3个jqplot图表的布局,我需要用ajax调用填充这些数据。用Ajax调用的数据填充jqplot图表
如果我将数据硬编码到我的变量中,图表呈现正常,但是当我使用从ajax调用返回的数据时,图表不显示。
这是为什么?
我呈现的jqplots完整的代码如下:
var url = "ajax_loadplotdata.php";
var result;
$.ajaxSetup({ async: false });
$.ajax({
cache: false,
url: url,
dataType: 'json',
success: function(data) {
result = data;
},
});
var options = {
height: 200, width: 300,
axesDefaults: { labelRenderer: $.jqplot.CanvasAxisLabelRenderer },
seriesDefaults: { rendererOptions: { smooth: true } },
axes: { xaxis: { min:1, max:30, tickInterval:1, pad:0, tickOptions:{fontFamily:'Arial', fontSize:'10px'} }, yaxis: { tickOptions:{show:false} } }
};
var dayplot = result.daydata;
var weekplot = [2,2,2,2,4,4,4,6,6,6,8,8,8,4,2];
var monthplot = [2,2,2,2,4,4,4,6,6,6,8,8,8,4,2];
var plot1 = $.jqplot('graph_day', [dayplot], options);
var plot2 = $.jqplot('graph_week', [weekplot], options);
var plot3 = $.jqplot('graph_month', [monthplot], options);
plot1.replot({ resetAxes:false });
plot2.replot({ resetAxes:false });
plot3.replot({ resetAxes:false });
有了这个代码,周和月图显示,但一天的情节没有。我将样本数据硬编码为周和月变量作为测试。
从我的Ajax调用返回的数据是这样的:
{"daydata":"[2.08E-8,2.08E-8,3.358E-7,3.258E-7,3.258E-7,3.308E-7,3.358E-7,3.408E-7,3.408E-7,1.808E-7,1.708E-7,3.158E-7,3.158E-7,3.158E-7,3.158E-7,3.158E-7,3.158E-7,3.158E-7,3.308E-7,1.108E-7,1.108E-7,1.108E-7,1.108E-7,1.158E-7]","weekdata":"[-2.304E-7,-2.304E-7,-2.304E-7,-2.304E-7,-2.304E-7,-2.304E-7,-2.304E-7]","monthdata":"[6.6E-7,2.55E-7,2.4E-7,4.7E-7,4.4E-7,5.8E-7,6.7E-7,6.3E-7,6.7E-7,7.75E-7,7.4E-7,7.5E-7,1.13E-6,7.2E-7,1.25E-6,1.42E-6,9.15E-7,2.2E-7,1.005E-6,2.06E-6,2.09E-6,1.59E-6,1.43E-6,1.19E-6,2.45E-6,2.49E-6,2.575E-6,2.755E-6,3.05E-6,2.84E-6]"}
我无法理解为什么图显示如果我手动填写的数据,而不是当我使用AJAX的变量。