I want to input JSONObject from jquery.post() to a a simple JS chart(bar chart)?
Posted
by ann-stack
on Stack Overflow
See other posts from Stack Overflow
or by ann-stack
Published on 2010-04-14T21:13:31Z
Indexed on
2010/04/14
21:23 UTC
Read the original article
Hit count: 268
HI I am very new to both json and js charts.
In the example of bar chart, they are giving a hard coded array like this,
var myData = new Array(['U.S.A.', 69.5], ['Canada', 2.8], ['Japan & SE.Asia', 5.6] );
var myChart = new JSChart('graph', 'bar');
myChart.setDataArray(myData);
Instead of that I want to use the response of $.post() method which is in json. Here is the piece of code.
var myData=[];
$.post("JSONServlet", function(data) {
$.each(data.Userdetails, function(i, data) {
myData[i] = [];
myData[i]['text'] = data['firstname'];
myData[i]['id'] = data['ssn'];
alert("first name " +myData[i]['text']+ " salary " +myData[i]['id']);
// I am getting correct data here, but how to assign this myData to barchart
});
}, "json");
is this the logic to use or how else can i get username and salary from the response and pass it to the barchart. Please help. I am stuck with this.
thanks in advance.
© Stack Overflow or respective owner