Java 使用ajax加载Highchart数据时显示空白图表
我对海查特有意见 我正试图使用ajax从struts操作填充数据 这是我的密码 JqueryJava 使用ajax加载Highchart数据时显示空白图表,java,ajax,json,highcharts,struts,Java,Ajax,Json,Highcharts,Struts,我对海查特有意见 我正试图使用ajax从struts操作填充数据 这是我的密码 Jquery $.getJSON("<%=request.getContextPath()%>/c/MonthlyGraphAjax?method=monthlyGraph&selectionList=${selectionList}&reportDateMonth=${reportDateMonth}", function(data){ /*manual insert*/
$.getJSON("<%=request.getContextPath()%>/c/MonthlyGraphAjax?method=monthlyGraph&selectionList=${selectionList}&reportDateMonth=${reportDateMonth}", function(data){
/*manual insert*/
dchart.xAxis.categories.push(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30)
dchart.series.push({name:'John',data:[99,155,148,136,121,0,0,153,173,161,128,128,0,0,45,109,164,150,98,0,0,165,114,151,108,0,0,0,0,0]},{name:'Doe',data:[1,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,2,0,0,0,0,1,0,0,0,0,0,0,0,0]})
/*end manual insert*/
/*capture to input field*/
$('#categories').val(data.Graph.Categories)
$('#series').val(data.Graph.Series)
/*JSON from struts*/
//dchart.xAxis.categories.push(data.Graph.Categories)
//dchart.series.push(data.Graph.Series)
$('#graphContainer').highcharts(dchart);
})
从action类中检索JSON结构,如下所示(从firebug控制台)
问题是,当我手动插入JSON时,它工作正常,但action类中的JSON显示空白图表。我还从输入字段中的action类捕获json,其值与我手动硬编码的值完全相同
有人能帮我一下吗,我的代码遗漏了什么。问题在于您的action类,其中
系列
和类别
不是JSON的一部分,而只是string.Thanx@PawełFus,请给出建议。是的,我的动作课有问题。JSON无效。现在,我的图表运行良好,动作类和javascript中几乎没有修改。
PrintWriter out = response.getWriter();
out.print("{\"Graph\":");
out.print("{");
out.print("\"Series\":\""+series+"\",\"Categories\":\""+categories+"\"");
out.print("}");
out.print("}");
response.setContentType("application/json");
{"Graph":
{
"Series":
"{name:'John',data:[99,155,148,136,121,0,0,153,173,161,128,128,0,0,45,109,164,150,98,0,0,165,114,151,108,0,0,0,0,0]},
{name:'Doe',data:[1,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,2,0,0,0,0,1,0,0,0,0,0,0,0,0]}"
,
"Categories":"1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30"
}
}