JSFiddle - React, Tailwind, and code Playground

by Laurie

HTML

<script src="http://www.google.com/jsapi?fake=.js"></script>
<select id="state">
    <option value="" selected="selected">Select a state to highlight</option>
    <option value="US-AK">Alaska</option>
    <option value="US-AZ">Arizona</option>
    <option value="US-HI">Hawaii</option>
</select>
<div id="chart_div"></div>

JavaScript

function drawChart () {
    var data = google.visualization.arrayToDataTable([
        ['State', ''],
        ['US-AK', 0],
        ['US-AZ', 0],
        ['US-HI', 0]
    ]);
    
    var geochart = new google.visualization.GeoChart(document.getElementById('chart_div'));
    var options = {
        region:"US",
        legend:"none",
        width: 556,
        height: 347,
        resolution: 'provinces',
        colorAxis: {
            minValue: 0,
            maxValue: 1,
            colors: ['green', 'red']
        }
    };
    
    var stateSelector = document.querySelector('#state');    
    function updateChart () {
        var index = this.selectedIndex;
        var selectedState = this.options[index].value;
        
        var view = new google.visualization.DataView(data);
        view.setColumns([0, {
            type: 'number',
            calc: function (dt, row) {
                return (dt.getValue(row, 0) == selectedState) ? 1 : 0;
            }
        }]);
        
        geochart.draw(view, options);
    }
    
    if (document.addEventListener) {
        stateSelector.addEventListener('change', updateChart, false);
    }
    else if (document.attachEvent) {
        stateSelector.attachEvent('onchange', updateChart);
    }
    else {
        stateSelector.onchange = updateChart;
    }
    
    geochart.draw(data, options);
}
google.load('visualization', '1', {packages:['geochart'], callback: drawChart});