Load the API first, then assign the chart drawing function to a handler for
the button click:
function drawChart () {
// create and draw the chart
}
function init () {
// create "click" event handler for button that calls drawChart
}
google.load('visualization', '1', {packages:['corechart'], callback: init});
On Tuesday, September 16, 2014 6:20:37 AM UTC-4, Sebastian Klute wrote:
>
> Hello,
>
> I am trying to display some charts in a tabbed Window in Joomla. That
> works fine. Here is the code of one of the example-Charts:
>
> <script type="text/javascript">
>
>
>
> // Load the Visualization API and the piechart package.
> google.load('visualization', '1.0', {'packages':['corechart']});
>
> // Set a callback to run when the Google Visualization API is
> loaded.
> google.setOnLoadCallback(drawChart);
>
> // Callback that creates and populates a data table,
> // instantiates the pie chart, passes in the data and
> // draws it.
>
> function drawChart() {
>
> // Create the data table.
> var data = new google.visualization.DataTable();
> data.addColumn('string', 'Topping');
> data.addColumn('number', 'Slices');
> data.addRows([
> ['Mushrooms', 3],
> ['Onions', 1],
> ['Olives', 1],
> ['Zucchini', 1],
> ['Pepperoni', 2]
> ]);
>
> // Set chart options
> var options = {'title':'Verteilung',
> 'width':600,
> 'height':450, is3D: true};
>
> // Instantiate and draw our chart, passing in some options.
> var chart = new google.visualization.PieChart(document.
> getElementById('chart_div'));
> chart.draw(data, options);
> }
> </script>
>
> It works fine this way. But I want the chart to be displayed after a
> button was clicked. I tried it this way:
>
>
> <script type="text/javascript">
>
> function chart1() {
>
>
>
> // Load the Visualization API and the piechart package.
> google.load('visualization', '1.0', {'packages':['corechart']});
>
> // Set a callback to run when the Google Visualization API is
> loaded.
> google.setOnLoadCallback(drawChart);
>
> // Callback that creates and populates a data table,
> // instantiates the pie chart, passes in the data and
> // draws it.
> }
>
> --->>>...anything else stays like before
>
>
> But it doesn´t work. Where is the mistake?
>
> Thanks for your help.
>
> Sebastian
>
>
>
>
--
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/d/optout.