Hello! Thank you, that's interesting that JSON is valid. Here is my code.
It consists of two files: getData.php is generating the JSON. It is called
by Javascript in nordwind.html
getData.php
<html>
<body>
<?php
$conn=odbc_connect('Nordwind','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT Artikelname, Listenpreis FROM Artikel WHERE Listenpreis >= 40";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
$json = '{"cols": [{"id":"","label":"Artikelname",
"type":"string"},{"id":"","label":"Listenpreis", "type":"number"}],"rows":
[';
$i = 0;
while (odbc_fetch_row($rs))
{
global $i;
if ($i > 0)
{
$json .= ',';
}
$artikelname=odbc_result($rs,"Artikelname");
$listenpreis=odbc_result($rs,"Listenpreis");
$json .= "{\"c\": [{\"v\":\"$artikelname\"}, {\"v\": $listenpreis}]}";
$i++;
}
$json .= ']';
$json .= '}';
odbc_close($conn);
echo $json;
?>
</body>
</html>
nordwind.html
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript"
src="https://www.google.com/jsapi"></script>
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
var chart = new
google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
--
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.