我是從網絡服務器得到以下JSON對象響應對象:動態更改標籤中的折線圖表
(JSON Array :[{"JUL":"5"},{"AUG":"7"},{"SEP":"9"},{"OCT":"11"},{"NOV":"13"}, {"DEC":"15"},{"JAN":"17"},{"FEB":"19"},{"MAR":"21"},{"APR":"23"},{"MAY":"25"},{"JUN":"27"}])
我正在JSON對象的鍵陣列中的
var al_key = [];
//For loop for x axis dispaly.
alert("al_key.length --------->"+al_key.length);
var jsonObj = []; //declare array
for (var i = 0; i < al_key.length; i++) {
jsonObj.push({value: i, text: al_key[i].value});
}
// Add axes
chart.addAxis("x", {min:1, max: 12 ,labels: jsonObj , fixLower: "major", microTicks: true, majorTickStep: 1});
chart.addAxis("y", { min: 0, max: 50, vertical: true, fixLower: "major", fixUpper: "major", includeZero: true });
然而,它不按我期望的方式工作。任何建議,我在哪裏得到這個錯誤?或者動態地在x軸上顯示月份的替代方法?預先感謝您的幫助。
粘貼響應的問題編輯:
含有單一的JSONObject包含了像
//服務器端的編碼值,其實我得到JSONArray對象..
JSONObject object=new JSONObject();
object.put("JAN":"17");
object.put("FEB":"19");
object.put("MAR":"21");
object.put("APR":"23");
object.put("MAY":"24");
object.put("JUN":"27");
JSONArray arrayObj=new JSONArray();
arrayObj.add(object);
On System.out.println(arrayObj); // our json appears like {"JAN":"17"},{"FEB":"19"},{"MAR":"21"},{"APR":"23"}, //{"MAY":"24"},{"JUN":"27"}];
On jsp:
//Call to the database to fetch the desired value
dojo.xhrGet({ url : "/POC/Action.do",
handleAs : "json",
sync: true,
load : function(response, ioArgs) {
alert("retrived response ------"+response);
for(var i in response)
for(var x in response[i])
output.push(response[i][x]);
alert("Get value to draw line chart---------------------->"+output);
},
error: function(response, ioArgs){
dojo.byId("grid").innerHTML = "An error occurred, with response: " + response;
return response;
},
handleAs: "json" });
響應對象包含返回值(JSONArray對象);
現在這個鍵需要顯示在圖表的x軸上。我是否需要再次拿到鑰匙,並準備通過你上面說的這是在形式形成的JSON對象..
正如SLaks所說,請回複評論或編輯原始問題。我甚至沒有注意到你現在寫的東西。所有的信息現在在這裏,所以請考慮刪除下面的答案。 – Aleadam 2011-05-03 01:28:39