I have to to draw a chart from the following json string:
{
"d":{
"results":[
{
"_metadata":{
"uri": "http://www.something.com/hi",
"type" : "something.preview.hi"
}, "Period", "1988", "Age": 20, "Size" : 80
},
"_metadata":{
"uri": "http://www.something.com/hi",
"type" : "something.preview.hi"
}, "Period", "1989", "Age": 25, "Size" : 90
}
] }}
I use jquery.flot.js library to draw the chart. Here is the example to draw the chart and it works fine:
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
myChart.setDataArray(d1);
myChart.setDataArray(d2);
According to example I have converted the json to an array of object:
var results = $.parseJSON(responseText)["d"]["results"];
var sampleData = [];
for (var i = 0, len = results.length; i < len; i++) {
var result = results[i];
sampleData.push({ Perioden: result.Perioden,
Size: result.Size,
Age: result.Age});
}
var myData = [];
for (var i in sampleData) {
myData.push([sampleData[i].Period, sampleData[i].Age]);
}
var myData1 = [];
for (var i in sampleData) {
myData1.push([sampleData[i].Period, sampleData[i].Size]);
}
myChart.setDataArray(myData);
myChart.setDataArray(myData1);
but I get the error that the data format is wrong for the data chart. Can anyody see what is the different between my code and the example?