I posted a code snippet I use for transforming database output from PHP
into JSON that the charts can understand:
https://groups.google.com/d/msg/google-visualization-api/Gy18YdVSSfQ/tKdtzSfqKlcJ
You can either echo that output into the constructor of the DataTable - ie:
var data = new google.visualization.DataTable(<?php echo $json_encoded_data
; ?>);
or you can use that code as a data source and make AJAX calls to it,
putting the returned json into the DataTable constructor, ie:
google.load('visualization', '1.0', {'packages': ['corechart']});
google.setOnLoadCallback(init);
function init () {
// get parameters to submit to data source
var params;
// get data w/ AJAX call
$.ajax({
url: '/path/to/data_query.php',
data: params,
type: json,
success: function (json) {
var data = new google.visualization.DataTable(json);
var chart = new google.visualization.ChartType(document.
getElementById('chart_div'));
chart.draw(data, {/*options*/});
}
});
}
On Sunday, May 6, 2012 4:13:17 PM UTC-4, maxweb59 wrote:
>
> Hello ! I would like to use the google charts API for my website, but
> i've one enormous problem: my data (these who i need to make a chart)
> are found in my DataBase (MySQL) by PHP, and are in PHP vars, but the
> API want the vars directly in the javascript function. How can I put
> my PHP vars into the javascript function of the API ?
> Thanks for your help.
>
> (and sorry for my english, i'm french :) )
--
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/-/jrYRqUvYN3IJ.
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.