如何在dojo中使用json数据

时间:2012-03-27 16:36:47

标签: ajax json dojo

任何人都可以帮我理解我应该如何在js中访问json数据。 JSP-struts代码访问。我正在使用struts2,json,dojo。但是要问题是访问数据。

var chartData = dojo.xhrGet({
        url : "getJSONResult",
        handleAs : "json",
        preventCache : false,
        load : function(data) {
             //how to process

        }
    });

我的struts.xml

<package name="json" namespace="/" extends="json-default">
    <action name="getJSONResult" method="execute"

class="uk.co.bandc.businessmonitor.web.controller.ShowTransactionAction">
        <result type="json" />
    </action>
</package>

我的动作类

package uk.co.bandc.businessmonitor.web.controller;

import com.opensymphony.xwork2.ActionSupport;

public class ShowTransactionAction extends ActionSupport {
/**
 * 
 */
private static final long serialVersionUID = 1L;

int[] numberarray1 = { 10000, 9200, 11811, 12000, 7662, 13887, 14200, 12222, 12000,    
10009, 11288, 12099 };

public String execute() {

    return SUCCESS;
} // End execute()

public int[] getNumberarray1() {
    return numberarray1;
}

public void setNumberarray1(int[] numberarray1) {
    this.numberarray1 = numberarray1;
}

} // End class

1 个答案:

答案 0 :(得分:0)

您想绘制什么样的图表?你的数据似乎是一维的。通常对于笛卡尔图表(条形图,线条等),您将需要2维数据,例如:

var exampleData = 
[
{ time: 10, count: 7382 },
{ time: 20, count: 1852 },
{ time: 35, count: 2397 },
{ time: 50, count: 1442 },
{ time: 55, count: 1854 }
];

然后,您可以使用dojox.charting.Chart2D来渲染图表

有关示例,请参阅http://dojotoolkit.org/documentation/tutorials/1.6/charting/