The alert never fires? That's odd...I would guess that there is either a
syntax error somewhere or there is an error fetching the data from the
server. Try replacing the drawChart function with this:
function drawChart () {
$.ajax({
url: 'getData.php',
dataType: 'json',
success: function (jsonData) {
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
});
},
error: function (e) {
alert(e.responseText);
}
});
}
Also, look in the developer's console in FF or Chrome for any error
messages.
On Monday, June 25, 2012 4:08:34 PM UTC-4, pj wrote:
>
> I am using the 3 files from
> https://google-developers.appspot.com/chart/interactive/docs/php_example.
> No chart is displayed.
> I have tried with and without
> jsonData = eval('(' + jsonData + ')');
> I do not get an alert.
>
> Here are the programs:
> examplesUsingPHP.html
> <html>
> <head>
> <!--Load the AJAX API-->
> <script type="text/javascript" src="https://www.google.com/jsapi
> "></script>
> <script type="text/javascript" src="jquery-1.6.2.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.
>
> alert(jsonData);
> jsonData = eval('(' + jsonData + ')');
> 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>
>
> ------------------
> getData.php
> <?php
>
> // This is just an example of reading server side data and sending it to
> the client.
> // It reads a json formatted text file and outputs it.
>
> $string = file_get_contents("sampleData.json");
> echo $string;
>
> // Instead you can query your database and parse into JSON etc etc
>
> ?>
> ----------------------
> sampleData.json
>
> {
> "cols": [
> {"id":"","label":"Topping","pattern":"","type":"string"},
> {"id":"","label":"Slices","pattern":"","type":"number"}
> ],
> "rows": [
> {"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]},
> {"c":[{"v":"Onions","f":null},{"v":1,"f":null}]},
> {"c":[{"v":"Olives","f":null},{"v":1,"f":null}]},
> {"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]},
> {"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]}
> ]
> }
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/jD7eZ23Z3qsJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.