Google GeoChart未与马来西亚地图合作

时间:2013-05-19 15:42:07

标签: google-visualization

我试图使用GeoChart for Malaysia Map显示一些数字,如果在世界地图中显示,它的工作正常。但是当钻进马来西亚地图时,GeoChart无法显示该州的价值。

我错过了什么吗?

<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
 google.load('visualization', '1', {'packages': ['geochart']});
 google.setOnLoadCallback(drawMarkersMap);

  function drawMarkersMap() {
  var data = google.visualization.arrayToDataTable([
    ['State', 'Data'],
    ['Kedah', 5],
  ]);

  var options = {
    region: 'MY',
    displayMode: 'regions',
    resolution: 'provinces',
  };

  var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
  chart.draw(data, options);
};
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>​

1 个答案:

答案 0 :(得分:2)

我对马来西亚各省的名字并不熟悉,以确切了解谷歌将如何渲染它们,但我能够使用以下代码为马来西亚各省着色:

function drawVisualization() {
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'State');
  data.addColumn('number', 'Data');
  data.addRows([
    [{v:'MY-14', f:' Wilayah Persekutuan Kuala Lumpur'}, 42],
    [{v:'MY-15', f:' Wilayah Persekutuan Labuan'}, 57],
    [{v:'MY-16', f:' Wilayah Persekutuan Putrajaya'}, 38],
    [{v:'MY-01', f:' Johor'}, 82],
    [{v:'MY-02', f:' Kedah'}, 46],
    [{v:'MY-03', f:' Kelantan'}, 51],
    [{v:'MY-04', f:' Melaka'}, 72],
    [{v:'MY-05', f:' Negeri Sembilan'}, 16],
    [{v:'MY-06', f:' Pahang'}, 2],
    [{v:'MY-08', f:' Perak'}, 87],
    [{v:'MY-09', f:' Perlis'}, 29],
    [{v:'MY-07', f:' Pulau Pinang'}, 49],
    [{v:'MY-12', f:' Sabah'}, 26],
    [{v:'MY-13', f:' Sarawak'}, 94],
    [{v:'MY-10', f:' Selangor'}, 35],
    [{v:'MY-11', f:' Terengganu'}, 79],
  ]);

  var options = {
    region: 'MY',
    displayMode: 'regions',
    resolution: 'provinces',
    height: 600,
    width: 800,
  };


  var geochart = new google.visualization.GeoChart(
    document.getElementById('visualization'));
  geochart.draw(data, options);
}

每当在省级使用Google GeoCharts时,我都喜欢使用ISO-3166 alpha-2 province codes for that country,因为它们始终有效,然后我使用{value: 'ISO 3166 alpha-2 code', format: 'human readable province name'}技巧让它正常显示。