var data = [
{label: "a Organinzation",data: 1},
{label: "b pvt Ltd.",data: 2},
{label: "d Organization",data: 10},
{label: "Completed Organization",data: 15},
{label: "Running Organization",data: 34}
];
I have one piechart of jqplot in my jsp page and that takes the data with the above format..now my problem is its worked fine with static data. But when I want to include some dynamic data. Its shows blank chart because of this data variable cant parse the string am providing...
Am generating the same string as specified in above code snippet with the following
var total = rawdata.split(";");
var txt = null;
for (var i = 1; i < total.length - 1; i++) {
if (i == 1) {
txt = "{ label: \"" + total[i] + "\", data: " + total[i + 1] + "}";
} else {
txt = txt + ", { label: \"" + total[i] + "\", data: " + total[i + 1] + "}";
}
i++;
}
alert(txt);
elem = $('#fl_3');
var data = [JSON.parse(txt)];
when i alert the txt varibale its giving me following pattern which is same as the code snippet i gave at first...
{ label: "Abc LTd.", data: 42},
{ label: "A org", data: 2},
{ label: "B Org", data: 6},
{ label: "c Org", data: 1},
{ label: "dbc comp ltd", data: 1},
{ label: "avc comp pvt. ltd", data: 1}
Then why it cant parse it as json? In my browser, I got this error:
Error: SyntaxError: JSON.parse: expected property name or '}'
If I write data=[txt];, nothing appears.
If I write data = [JSON.parse(txt)]; then I get the error..
Can anybody please help me? How can I make this run?
rawdatalooks like. So far I can only see the output you want indatabut it would be good to see what it is you start with.