我是从网络服务器得到以下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