地区Geochart地区美国

时间:2015-01-03 19:22:34

标签: google-maps

我正在学习使用谷歌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,我确信这是一个非常基本的错误,但我找不到。

1 个答案:

答案 0 :(得分:0)

添加{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>