gpt4 book ai didi

java - JQPlot Ajax图形渲染问题

转载 作者:行者123 更新时间:2023-11-30 04:56:05 24 4
gpt4 key购买 nike

我正在尝试通过 Ajax xml 获取数据来渲染 jqplot 图表。

  $.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 轴也没有填充。

但是,当我尝试查看示例数据(即 line1)时,即使 ajax 调用获取的数据几乎相似,它仍然可以工作

最佳答案

当您解析 xml 时,您的 y 值将作为字符串而不是整数推送到数组中。尝试:

$(xml).find('graph').each(function(){
var points = new Array()
var x = $(this).attr('x');
var y = $(this).attr('y');
points.push(x);
points.push(parseInt(y)); //modified line!
data.push(points);
});

关于java - JQPlot Ajax图形渲染问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8508442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com