// Load the Visualization API and the corechart package. google.charts.load('current', {'packages':['corechart','geochart']}); // Set a callback to run the bar chart for States when the Google Visualization API is loaded. google.charts.setOnLoadCallback(drawStatesChart); // Set a callback to run the bar chart for Cities when the Google Visualization API is loaded. google.charts.setOnLoadCallback(drawCitiesChart); // Set a callback to run the geochart google.charts.setOnLoadCallback(drawRegionsMap); // Callback that creates and populates a data table, // instantiates the States chart, passes in the data and // draws it. function drawStatesChart() { // Create the data table for States chart. var data = new google.visualization.DataTable(); data.addColumn('string', 'State'); data.addColumn('number', 'Customers'); data.addRows([ ['CA', 100], ['TX', 65.8], ['FL', 48.7], ['NY', 29], ['OH', 29], ['PA', 27.9], ['AZ', 26.8], ['IL', 21.3], ['GA', 21.1], ['MI', 16.4], ['VA', 16], ['NC', 15.8], ['WA', 13.5], ['IN', 13.2], ['TN', 13], ['NV', 12.4], ['SC', 11.8], ['MO', 11.4], ['CO', 11], ['NJ', 10.5], ['KY', 10.3], ['MA', 8.6], ['KS', 8], ['WI', 7.4], ['AL', 6.9], ['MN', 6.4], ['OR', 6], ['UT', 5.7], ['IA', 5.2], ['CT', 4.9], ['NE', 3.3], ['MD', 3.2], ['OK', 2.5], ['HI', 2.5], ['ME', 2.3], ['MT', 2.3], ['RI', 1.9], ['WY', 1.5], ['DC', 1], ['NM', 0.9], ['ID', 0.9], ['VT', 0.8], ['LA', 0.7], ['NH', 0.6], ['SD', 0.4], ['WV', 0.4], ['AR', 0.4], ['MS', 0.3], ['ND', 0.3], ['DE', 0.2], ['AK', 0.2] ]); // Set chart options for States chart. var options = {title:'The States With the Most and Least Online Birth Control Customers (ranked from 0-100)', width:400, height:1200}; // Instantiate and draw our chart, passing in some options. var chart = new google.visualization.BarChart(document.getElementById('States_chart_div')); chart.draw(data, options); } // Callback that creates and populates a data table, // instantiates the Cities chart, passes in the data and // draws it. function drawCitiesChart() { // Create the data table for Cities chart. var data = new google.visualization.DataTable(); data.addColumn('string', 'City'); data.addColumn('number', 'Customers'); data.addRows([ ['Los Angeles', 100], ['Houston', 74.6], ['Las Vegas', 72.9], ['Phoenix', 70.4], ['San Antonio', 62.4], ['Chicago', 58.1], ['Philadelphia', 49.9], ['Brooklyn', 43.8], ['San Diego', 42.1], ['Orlando', 40], ['Tuscon', 37.5], ['New York', 37], ['Austin', 36.9], ['Dallas', 34.1], ['Miami', 30.7], ['Bronx', 29], ['Jacksonville', 29], ['Mesa', 27.8], ['Columbus', 27], ['Fresno', 26.8], ['Sacramento', 25.4], ['Tampa', 25.4], ['Indianapolis', 25], ['Fort Worth', 24.7], ['San Jose', 22.5], ['Atlanta', 21.9], ['Denver', 21.7], ['Louisville', 20.6], ['Cincinnati', 20.5], ['Reno', 20], ['El Paso', 19.8], ['Charlotte', 19.7], ['Long Beach', 18.5], ['Pittsburgh', 18.4], ['Seattle', 18], ['Tempe', 17.9], ['Riverside', 17.5], ['Nashville', 17.5], ['Bakersfield', 17.3], ['Colorado Springs', 16.6], ['Henderson', 16.3], ['Glendale', 15], ['Boston', 14.7], ['San Francisco', 14.7], ['Portland', 14.3], ['Wichita', 14.3], ['Chandler', 13.5], ['Knoxville', 12.9], ['Tallahassee', 12.9], ['Lubbock', 12.8], ]); // Set chart options var options = {title:'The 50 Cities With the Most Online Birth Control Customers (ranked from 0-100)', width:400, height:1600}; // Instantiate and draw our chart, passing in some options. var chart = new google.visualization.BarChart(document.getElementById('Cities_chart_div')); chart.draw(data, options); } // Create the data table for the geochart function drawRegionsMap() { var data = google.visualization.arrayToDataTable([ ['State', 'Customers'], ['CA', 100 ], ['TX', 74], ['FL', 60] ]); var options = { region: 'US', }; var chart = new google.visualization.GeoChart(document.getElementById('regions_div')); chart.draw(data, options); }