Google Geocharts中的英国地区

时间:2013-02-06 06:41:10

标签: google-visualization

我们正在为我们的网站实施地理图表热图,但他们在显示英国地区方面有局限性,他们只能列出4个地区,英格兰,苏格兰,威尔士和北爱尔兰,而不仅仅是这些。任何人都可以帮助我知道我们是否可以列出英国的所有地区,以及我们是否可以显示英国以及普雷斯顿等地区的城市,县。

我们还可以传递3个以上的参数来显示鼠标悬停的更多数据。

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

     var chart; 
     var data;
     var options;   

     google.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() {
        data = google.visualization.arrayToDataTable([

          ['Region', 'Popularity', 'Total Votes'],


          ['England', 8, 6],
          ['Scotland', 8, 6],
          ['Wales ', 9, 7],
          ['Northern Ireland', 2, 5],

          ['United Kingdom', 2, 4]

        ]);

        var maxV = 5;  // to ensure scale is equal on both ends.
        var minV = maxV*-1;

        options =   { 
        colorAxis: {colors: ['blue', 'white', 'red'], minValue: minV, maxValue: maxV},
            };

        chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
        chart.draw(data, options);
    google.visualization.events.addListener(chart, 'regionClick', selectHandler);
    };

function selectHandler(e) {
    var selection = e['region'];
    //alert(selection);
        options['resolution'] = 'provinces';
        options['region'] = selection;
            chart.draw(data, options);
            document.getElementById('goback').style.display='block';
    };

    </script>

如您所见,只有3个参数,我们可以传递额外的参数吗?或任何工具提示。

提前致谢

1 个答案:

答案 0 :(得分:6)

简短回答:不,你不能展示比英格兰,威尔士,苏格兰和北爱尔兰更具体的部门。

Google地图目前没有更具体的地图,因此您无法使用地理地图进行地图制作。

如果您想要显示城市,可以使用marker mode来显示它们。如果您确实想要显示all the ISO-3166-2 regions for the UK,那么您唯一的选择是为每个人创建标记模式的坐标,然后将其编码为圆圈,而不是阴影区域。

就显示更多工具提示而言,您可以添加工具提示列以显示您的心愿(警告:不允许回车):

function drawVisualization() {
  data = new google.visualization.DataTable();
  data.addColumn('string', 'Region');
  data.addColumn('number', 'Popularity');
  data.addColumn('number', 'Total Votes');
  data.addColumn({type: 'string', role: 'tooltip'}, 'ToolTip');
  data.addRows([
    ['England', 8, 6, 'This is England'],
    ['Scotland', 8, 6, 'This is Scotland'],
    ['Wales ', 9, 7, 'This is Wales'],
    ['Northern Ireland', 2, 5, 'This is Northern Ireland'],
    ['United Kingdom', 2, 4, 'This is the UK']
  ]);

  var maxV = 5;  // to ensure scale is equal on both ends.
  var minV = maxV*-1;

  options =   {
    colorAxis: {colors: ['blue', 'white', 'red'], minValue: minV, maxValue: maxV},
  };

  chart = new google.visualization.GeoChart(document.getElementById('visualization'));
  chart.draw(data, options);
  google.visualization.events.addListener(chart, 'regionClick', selectHandler);
}

function selectHandler(e) {
  var selection = e['region'];
  //alert(selection);
  options['resolution'] = 'provinces';
  options['region'] = selection;
  chart.draw(data, options);
  //document.getElementById('goback').style.display='block';
};

将来,HTML ToolTips也可能会受到支持,但即使在实验1.1版本中,它们目前也未启用地理广告。

相关问题