Re: use google.chart libraries in a javascript file

198 views
Skip to first unread message

asgallant

unread,
Jul 11, 2012, 7:00:43 PM7/11/12
to google-visua...@googlegroups.com
Yes, it should be possible, but I haven't seen any successful implementations.  The API doesn't play very well with non-google AJAX loaders.

On Wednesday, July 11, 2012 6:26:00 PM UTC-4, Jose Miguel Ramírez Escobedo wrote:

Hello, I have one cuestion, ok in the exaples that I have seen in a html file you load the api libraries of google chart, but I want to know if it’s possible use them in a javascript file and if is possible how can i load the libraries

Jose Miguel Ramírez Escobedo

unread,
Jul 12, 2012, 11:12:35 AM7/12/12
to google-visua...@googlegroups.com
ok thank you, because i didn't know how to do it, well so is there a way to draw the chart when i click a link, this because i need to load the data that come from an a function with ajax request, so first need to wait until the ajax request finishes after that catch the values, but all this in click event and i said this because i saw that this is made with this code google.setOnLoadCallback draw the chart on load right?

asgallant

unread,
Jul 12, 2012, 1:07:21 PM7/12/12
to google-visua...@googlegroups.com
You are not required to draw the chart on page load, you just have to make sure that it doesn't start until after the API has finished loading.  You can do this with AJAX requests as long as you are loading something other than the API with the AJAX.  Here's a rough workup you could use (uses jQuery's AJAX function to fetch a json representation of a DataTable from a php script and draw a chart):

google.load('visualization''1'{packages['corechart']});
google.setOnLoadCallback(init);

function init ({
    $.ajax({
        url'path/to/data.php',
        type'json',
        successfunction (json{
            // do something with json
            // the draw the chart here, maybe:
            
            var data new google.visualization.DataTable(json);
            var chart new google.visualization.LineChart(document.getElementById('myChart'));
            chart.draw(data{
                title'My Chart'
            });
        }
    });
Reply all
Reply to author
Forward
0 new messages