Here's a post with some example code that I used to generate a a JSON
representation of a DataTable:
https://groups.google.com/forum/#!msg/google-visualization-api/Gy18YdVSSfQ/tKdtzSfqKlcJ
You can then draw the chart using something like this:
google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart () {
$.ajax({
dataType: 'json',
url: '/path/to/data/source.php',
success: function (json) {
// convert json into DataTable object
var data = new google.visualization.DataTable(json);
// create and draw chart
var chart = new google.visualization.LineChart(document.
getElementById('chart_div'));
chart.draw(data, {/*options*/});
}
});
}
On Tuesday, July 31, 2012 10:09:25 AM UTC-4, Shaowen Hu wrote:
>
> Can anybody post an example code on how to do this? I am new to Ajax and
> PHP, and Google Chart.
>
> Thanks a lot in advance,
> Shaowen
>
> On Wednesday, January 25, 2012 11:16:29 AM UTC-6, Ricardo Viana Barreto
> wrote:
>>
>> asgallant,
>> That suggestion was awesome! That feature is exactly what I was
>> looking for.
>> Very very nice.
>> I made an array in a PHP script, in the format documented at the link
>> you sent, then I used json_encode() and echoed the results.
>> Then I made an Ajax request to the PHP script, and loaded it when
>> creating the chart object. Work's perfectly.
>>
>> Thank you all.
>>
>> On Jan 25, 12:37 pm, asgallant <[email protected]> wrote:
>> > If you're feeling a bit more ambitious, the DataTable constructor can
>> > accept a JSON representation of the data (
>> http://code.google.com/apis/chart/interactive/docs/reference.html#Dat...),
>>
>> > which PHP can output rather easily via the json_encode() function.
>> This
>> > would be the first step in implementing compatibility with the API
>> query
>> > functions, if you choose to do so.
>
>
--
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/-/3cHoVPchBIwJ.
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.