您好我使用servlet
响应为jqplot
提供barchart
的参数
servlet
响应语句是这样的:
out.println("725,759,2032,171,2761,133175,166163,409,28630,3754@0,375,1482,0,2051,125857,167524,0,125406,4022@0,0,0,1,0,125406,0,0,0,0");
如果是成功响应,ajax
将使用dataRenderer: dataRenderer(dataArr)
作为数组参数调用绘图函数。
但是,错误表示"没有指定数据"找到了。
我尝试记录dataRenderer返回
"725,759,2032,171,2761,133175,166163,409,28630,3754,0,375,1482,0,2051,125857,167524,0,125406,4022,0,0,0,1,0,125406,0,0,0,0"
但预期的答案应该是
[725,759,2032,171,2761,133175,166163,409,28630,3754],[0,375,1482,0,2051,125857,167524,0,125406,4022],[0,0,0,1,0,125406,0,0,0,0]
非常感谢任何帮助!感谢
function log(msg) {
setTimeout(function() {
throw new Error(msg);
}, 0);
}
var form = $('#form1');
var storedData = [3, 7];
var plot1;
//$( "#plot" ).click(function(){
form.submit(function(){
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: {n1:n1.value,n2:n2.value},
success: function (data) {
var result=data;
//$('#result').attr("value",result);
renderGraph(result);
}
});
return false;
});
var dataRenderer = function(userData){
var result = new Array();
var seperator1 = /\s*@\s*/;
var seperator2 = /\s*,\s*/;
storedData = userData.split(seperator1);
result.push(storedData[0].split(seperator2));
result.push(storedData[1].split(seperator2));
result.push(storedData[2].split(seperator2));
return result;
};
function renderGraph(dataArr) {
if (plot1) {
plot1.destroy();
}
log(dataRenderer(dataArr));
var ticks = ['Pub1', 'Pub101', 'Pub121', 'Pub141', 'Pub161', 'Pub2', 'Pub3', 'Pub61', 'Pub81', 'Pub82'];
var plot1 = $.jqplot('chart1', [], {
dataRenderer: dataRenderer(dataArr),
seriesColors : ['#1cbd17', '#e44e23', '#23b9e4', '#C7754C', '#17BDB8', '#b817bd'],
seriesDefaults : {
renderer : $.jqplot.BarRenderer,
rendererOptions : {
fillToZero : true
}
},
series : [{
label : 'delivered'
}, {
label : 'filtered out'
}, {
label : 'incomplete'
}, {
label : ''
}
],
legend : {
show : true,
placement : 'outsideGrid'
},
axes : {
xaxis : {
renderer : $.jqplot.CategoryAxisRenderer,
ticks : ticks
},
yaxis : {
pad : 1.05,
tickOptions : {
formatString : '%d'
}
}
}
});
plot1.resetAxesScale();
plot1.replot();
}
</script>
答案 0 :(得分:0)
这是修复:
result.push(storedData[0].split(seperator2).map(Number));
result.push(storedData[1].split(seperator2).map(Number));
result.push(storedData[2].split(seperator2).map(Number));
希望如果其他人遇到同样的问题,这会有所帮助。