使用ajax加载Highchart数据时显示空白图表

时间:2014-09-30 12:24:27

标签: java ajax json highcharts struts

我遇到了问题问题。

我正在尝试使用ajax来填充struts动作中的数据。

这是我的代码

Jquery的

$.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);

})

行动类的回应

PrintWriter out = response.getWriter();
        out.print("{\"Graph\":");
            out.print("{");
                out.print("\"Series\":\""+series+"\",\"Categories\":\""+categories+"\"");
            out.print("}");
        out.print("}");

        response.setContentType("application/json");

从动作类中检索JSON结构,如下所示(来自firebug控制台)

{"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"
    }
}

问题是当我手动插入JSON时工作正常,但是动作类中的json显示空白图表。我还从输入字段中的动作类中捕获json,其值与我手动硬编码完全相同。

有人可以帮助我,我的代码中缺少什么。

0 个答案:

没有答案