JSFiddle - React, Tailwind, and code Playground
by blindmonkey
HTML
<script src="http://www.google.com/jsapi?dummy=.js"></script>
<div id="chart_div"></div>
JavaScript
google.load('visualization', '1.1', {
'packages': ['geochart']
});
google.setOnLoadCallback(drawStuff);
function drawStuff() {
var data = google.visualization.arrayToDataTable([
['Country', 'Popularity'],
['US', 4],
['CA', 22]
]);
// Set chart options
var options = {
region: 'world'
};
var links = {
'US': 'http://google.com',
'CA': 'http://jsfiddle.net'
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
google.visualization.events.addListener(chart, 'select', function() {
var sel = chart.getSelection();
if (sel.length > 0) {
var country = data.getValue(sel[0].row, 0);
var link = links[country];
if (link) {
window.open(link);
// Instead of opening the link in a new window, we could open in in this one by commenting out the line above, and uncommenting the line below.
//window.location.href = link;
}
}
});
};