Google Chart API: Geo Charts boundary colour

I am using a GEO chart from the google API. I needed to know if the colour of the country boundaries can be changed or not?, which might help me distinguish the countries better depending on the fill colour i selected for the graph.

Answers:

Answer

there are no config options for changing the border color,
but you can change manually, on the chart's 'ready' event.

each country will be drawn with a <path> element.
each <path> element will have a stroke attribute,
which is the border color.

var countries = container.getElementsByTagName('path');
Array.prototype.forEach.call(countries, function(path) {
  path.setAttribute('stroke', 'red');
});

see following working snippet...

google.charts.load('current', {
  packages: ['geochart'],
  mapsApiKey: 'AIzaSyD-9tSrke72PouQMnMX-a7eZSW0jkFMBWY'
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ['Country', 'Popularity'],
    ['Germany', 200],
    ['United States', 300],
    ['Brazil', 400],
    ['Canada', 500],
    ['France', 600],
    ['RU', 700]
  ]);

  var container = document.getElementById('chart_div');
  var chart = new google.visualization.GeoChart(container);

  google.visualization.events.addListener(chart, 'ready', function () {
    var countries = container.getElementsByTagName('path');
    Array.prototype.forEach.call(countries, function(path) {
      path.setAttribute('stroke', 'red');
    });
  });

  chart.draw(data, {
    legend: 'none'
  });
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.