Google Chart API: Geo Charts boundary colour

后端 未结 1 1291
南旧
南旧 2021-01-16 12:54

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 b

相关标签:
1条回答
  • 2021-01-16 13:20

    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>

    0 讨论(0)
提交回复
热议问题