Hi,
I am using a JSON object to create graphs with Google visualization. I am trying to design the data source. For this i am creating a JSON object on my browser.
var JSONObject = {
cols: [{id: 'date', label: 'Date', type: 'date'},
{id: 'soldpencils', label: 'Sold Pencils', type: 'number'},
{id: 'soldpens', label: 'Sold Pens', type: 'number'}],
rows: [{c:[{v: new Date(2008,1,1),f:'2/1/2008'},{v: 30000}, {v: 40645}]},
{c:[{v: new Date(2008,1,2),f:'2/2/2008'},{v: 14045}, {v: 20374}]},
{c:[{v: new Date(2008,1,3),f:'2/3/2008'},{v: 55022}, {v: 50766}]}]
};
var data = new google.visualization.DataTable(JSONObject, 0.5);
Now i need to fetch the data dynamically. So i am placing a ajax request to a function which is returning me the string
"cols: [{id: 'date', label: 'Date', type: 'date'},
{id: 'soldpencils', label: 'Sold Pencils', type: 'number'},
{id: 'soldpens', label: 'Sold Pens', type: 'number'}],
rows: [{c:[{v: new Date(2008,1,1),f:'2/1/2008'},{v: 30000}, {v: 40645}]},
{c:[{v: new Date(2008,1,2),f:'2/2/2008'},{v: 14045}, {v: 20374}]},
{c:[{v: new Date(2008,1,3),f:'2/3/2008'},{v: 55022}, {v: 50766}]}"
This i a m able to save into a variable
var var1 = "cols: [{i ....... 66}]}"
and show as
alert(var1);
Now my task is to create a JSON object with this string. This is not working fine. Please help me out with this. When i give a hardcoded string the JSON object works fine and i am able to get my required graph. Now if i try putting the same value of string from ajax request which i confirmed from a alert message into a JSON object. The object is not getting created correctly. Please let me know your opinion and any correction or advices. Thanks in advance.
Thanks Vinod T.