Google地理位置不会显示大洲 [英] Google geochart doesn't show continents

查看:99
本文介绍了Google地理位置不会显示大洲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用google geochart显示数据。



我的代码:

 < script type ='text / javascript'src ='https://www.google.com/jsapi'>< / script> 
< script type ='text / javascript'>

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

函数drawRegionsMap(){

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

var options = {region:'world',resolution:'continents',width:556,height:347};
var data = google.visualization.arrayToDataTable([
['continents','Aircrafts'],
['Asia',700]
]);

geochart.draw(data,options);

};
< / script>
< div id =visualizationstyle =width:800px; height:400px;>< / div>

在图表中不显示 asia 作为数据。

解决方案

尽管'continents'解决方案选项不在官方文档中,但确实有效。您需要更改数据表以包含一列大陆区域代码,例如:

  var data = google.visualization.arrayToDataTable ([
['Region code','Continent','Aircraft'],
['142','Asia',700]
]);

geochart.draw(data,options);

区域代码是必需的,但不会在工具提示中呈现。与各大洲相匹配的代码在此处进行说明,位于该部分称为大陆层次和代码。它实际上并没有说你需要在你的数据表中使用它们(这太简单了...)



唯一的警告是我还没有找到了一种方法让它认识到将允许将美洲分成北部和南部的次区域代码。南。如果你坚持使用大陆代码,那么他们应该工作 - 他们为我做。请注意,这些代码需要作为字符串存在数据表中。



请参阅这里查看一个工作示例: http://jsfiddle.net/6hrhj9qs/


I'm using google geochart to display data.

My code:

<script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>

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

        function drawRegionsMap() {

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

     var options = {region: 'world', resolution: 'continents', width: 556, height: 347};
     var data = google.visualization.arrayToDataTable([
            ['continents', 'Aircrafts'],
            ['Asia', 700]
          ]);

      geochart.draw(data, options);

        };
    </script>
     <div id="visualization" style="width: 800px; height: 400px;"></div>

In chart it doesn't show asia as data.

解决方案

Although the 'continents' resolution option isn't in the official docs it does work. You need to change your data table to include a column of continent region codes, e.g.:

 var data = google.visualization.arrayToDataTable([
        ['Region code', 'Continent', 'Aircraft'],
        ['142', 'Asia', 700]
      ]);

  geochart.draw(data, options);

The region codes are required but don't get rendered in the tooltips. The codes matching each continent are explained here, beneath the options in the section called 'Continent Hierarchy and Codes'. It doesn't actually say you need to use them in your data table (that would be too easy...)

The only caveat is that I haven't yet found a way to get it to recognise the subregion codes that will allow separating 'Americas' into North & South. If you stick to using the continent codes then they should work - they do for me. Note that the codes need to be in the data table as strings.

See here for a working example : http://jsfiddle.net/6hrhj9qs/

这篇关于Google地理位置不会显示大洲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆