New Method Google Chart

New method of loading libraries

by Darryl Gurganious

HTML

<script src="https://www.gstatic.com/charts/loader.js"></script>
<p><strong>New Method</strong>
</p>
<div id="chart_div" style="width: 900px; height: 500px;"></div>

JavaScript

// Load the Visualization API and the piechart package.
			google.charts.load('current', {packages: ['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.charts.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([
        ['a', 1],
        ['b', 2],
        ['c', 3],
        ['d', 4],
        ['e', 5]
      ]);

      // Set chart options
var thiswidth = $('#chart_div').width();
var thisheight =  thiswidth * 7/8;
      var options = {'title':'How Much Pizza Everyone Ate Last Night',
                     'width':thiswidth,
                     'height':thisheight};

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }