地区 Geochart 地区 美国

Region Geochart region America

我正在学习使用 google Geochart 工具 我想重新创建这样的地图:

https://docs.google.com/spreadsheets/d/171U4NeI_49iacbhzlX0A8nT6aB9N4guc6VWsELmP6wI/pubchart?oid=1478243202&format=interactive

我的代码是这样的:

  google.setOnLoadCallback(drawRegionsMap);

  function drawRegionsMap() {

      var data = google.visualization.arrayToDataTable([
          ['States', 'Number of killings'],
          ['California', 292],
          ['Texas', 143],
          ['Washington', 120]
      ]);

      var options = {
          region: 'US'
      };

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

      chart.draw(data, options);
  }

我能看到地图,但我看不到州的划分,也看不到我使用的颜色http://jsfiddle.net,我确信这是一个非常基本的错误,但我找不到它。

添加{resolution: provinces}:

工作代码片段:

google.setOnLoadCallback(drawRegionsMap);
google.load('visualization', '1', {
  packages: ['map']
});

function drawRegionsMap() {

  var data = google.visualization.arrayToDataTable([
    ['States', 'Number of killings'],
    ['California', 292],
    ['Texas', 143],
    ['Washington', 120]
  ]);

  var options = {
    region: 'US',
    resolution: 'provinces'
  };

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

  chart.draw(data, options);
}
<script src="https://www.google.com/jsapi"></script>
<div>
  <div id="regions_div" style="width: 500px; height: 400px;"></div>
</div>