Creating charts using the ChartWrapper
There are two ways to create charts with Google Charts. One is the way we did it in the recipe Getting started with a pie chart and the second will be covered in this recipe. The goal of the ChartWrapper object is to enable you to cut down the amount of code needed to create a chart.
Its main advantages are less code and more flexibility of data sources. Its disadvantage is less control over the steps of graph creation.
Getting ready
Grab the HTML file from the last recipe (Getting started with pie charts). We will only modify the file path of the external JavaScript file and the rest of the code will remain the same.
How to do it...
After changing the path of the HTML file source to the JavaScript file, it's time to go into the JavaScript file and start over:
Load Google API (you do not need to mention what you want to load any more) and add a callback:
google.load('visualization', '1.0'); google.setOnLoadCallback(init);
Create the
init
function:function init...