You have the JSON formatted incorrectly. It should represent 1 object with
"cols" and "rows" properties. "cols" is an array of objects with "type"
(string, mandatory), "label" (string, optional), "id" (string, optional),
and "p" (object, optional) parameters. Rows is an array of objects with
"c" (array, mandatory), and "p" (object, optional) parameters. The "c"
parameter of a row object is an array of objects with "v" (string/number,
mandatory), "f" (string, optional), and "p" (object, optional) parameters.
Your columns construction is correct, but you only need it once. Your rows
construction needs some work. Let's start with this row:
["1","2013-08-13 00:00:00"]
should be:
{"c":[{"v":"1"},{"v":"2013-08-13 00:00:00"}]}
and this row:
["2","2013-08-13 00:00:00"]
should be:
{"c":[{"v":"2"},{"v":"2013-08-13 00:00:00"}]}
Add them to your "rows" array like this:
"rows":[{"c":[{"v":"1"},{"v":"2013-08-13
00:00:00"}]},{"c":[{"v":"2"},{"v":"2013-08-13
00:00:00"}]}]
You can then combine the whole thing together to make the JSON string:
{"cols":[{"label":"id","type":"string"},{"label":"date","type":"string"}],
"rows":[{"c":[{"v":"1"},{"v":"2013-08-13
00:00:00"}]},{"c":[{"v":"2"},{"v":"2013-08-13
00:00:00"}]}]}
On Wednesday, August 14, 2013 5:53:54 AM UTC-4, soumya reubro wrote:
>
> Hi,
>
> I am trying to draw a line chart using *Google chart *in which data is
> retrieved from mysql table.But i get the error as follows
> Error: Invalid JSON string:
> {"cols":[{"label":"id","type":"string"},{"label":"date","type":"string"}],"rows":["1","2013-08-13
>
> 00:00:00"]}{"cols":[{"label":"id","type":"string"},{"label":"date","type":"string"}],"rows":["2","2013-08-13
>
> 00:00:00"]}
>
> the json encoded data looks as follows
> {"cols":[{"label":"id","type":"string"},{"label":"date","type":"string"}],"rows":["1","2013-08-13
>
> 00:00:00"]}{"cols":[{"label":"id","type":"string"},{"label":"date","type":"string"}],"rows":["2","2013-08-13
>
> 00:00:00"]}
>
>
>
> Here is the code which i used for line chart developement
>
> <html>
> <head>
> <script type="text/javascript" src="https://www.google.com/jsapi
> "></script>
> <script type="text/javascript" src="jquery.js"></script>
> <script type="text/javascript" src="jquery-1.6.2.min.js"></script>
> <script type="text/javascript">
> google.load("visualization", "1", {packages:["corechart"]});
> google.setOnLoadCallback(drawChart);
> function drawChart() {
> var jsonData = $.ajax({
> url: "graph1.php",
> dataType:"json",
> async: false
> }).responseText;
> var data = new google.visualization.DataTable(jsonData);
> var chart = new
> google.visualization.LineChart(document.getElementById('chart_div'));
> chart.draw(data, {width: 400, height: 240});
> }
> </script>
> </head>
> <body>
> <div id="chart_div" style="width: 900px; height: 500px;"></div>
> </body>
> </html>
>
>
> PHP part:
>
>
> $sql = mysql_query("SELECT * FROM `da_insulin_details` LIMIT 0,2 ");
> $rows['cols'] = array( array('label' => 'id', 'type' => 'string'),
> array('label' => 'date', 'type' => 'string'));
> while($row = mysql_fetch_array($sql))
> {
>
> $rows['rows'] [0] = $row['id'];
> $rows['rows'][1] = $row['date'];
> $jsonTable = json_encode($rows);
> echo $jsonTable;
>
> }
>
>
> I am new to this section..anybody pls help me to solve the issue
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.