1
我想通过Ajax xml获取数据来渲染jqplot图形。JQPlot Ajax图形渲染问题
$.ajax({
type: "POST",
url: "/ajaxXML.jsp",
data: ({cmd: "report"}),
dataType: "xml",
success: function(xml) {
var data= new Array();
$(xml).find('graph').each(function(){
var points = new Array()
var x = $(this).attr('x');
var y = $(this).attr('y');
points.push(x);
points.push(y);
data.push(points);
});
plotGraph(data);
}
});
function plotGraph(data){
var line1=[['11-01-11',2052], ['11-02-11',2205], ['11-03-11',1910], ['11-04-11',2085], ['11-05-11',2261], ['11-06-11',1714], ['11-07-11',3123], ['11-08-11',3369], ['11-09-11',3515], ['11-10-11',3380], ['11-11-11',3476], ['11-12-11',3954], ['11-13-11',2799], ['11-14-11',3166], ['11-15-11',2932] ,['11-16-11',3289]];
alert(data);
alert(line1);
$.jqplot('chart1', [data], {
title:'Margin vs Date',
axes:{
xaxis:{
renderer:$.jqplot.DateAxisRenderer
},
yaxis:{autoscale:true}
},
series:[{lineWidth:4}]
});
}
的XML是什么样子
<graphs>
<graph x="11-28-2011" y="48973"></graph>
<graph x="11-29-2011" y="41981"></graph>
<graph x="11-30-2011" y="45562"></graph>
<graph x="12-01-2011" y="82437"></graph>
<graph x="12-02-2011" y="83979"></graph>
<graph x="12-03-2011" y="64444"></graph>
</graphs>
但一些如何这个策略是行不通的只有X轴填充了没有数据点或图表Y轴。
然而,当我尝试看看样本数据即一号线它的工作原理,即使当你分析你的y值推入数组作为字符串不是整数的XML通过Ajax调用fetchced数据几乎是相似
谢谢马克你让我的一天:) – dpsdce 2011-12-15 15:39:36