显示没有数据的选定国家

时间:2015-05-21 22:08:31

标签: javascript google-maps

我想突出显示特定国家/地区,但是当您将鼠标悬停在该国家/地区时,不会显示数据。实际上,这需要是true / false类型的数据。

var data = google.visualization.arrayToDataTable([
  ['Country','Active'],
  ['Germany',1],
  ['United States',1],
  ['Brazil',1],
  ['Canada',1],
  ['France',1],
  ['Russia',1]
]);

如何让它不显示" Active"悬停数据?如果我没有在该数据数组中包含第二列,则不显示任何内容。

示例:



google.setOnLoadCallback(drawRegionsMap);

function drawRegionsMap() {
    var data = google.visualization.arrayToDataTable([
      ['Country','Active'],
      ['Germany',1],
      ['United States',1],
      ['Brazil',1],
      ['Canada',1],
      ['France',1],
      ['Russia',1]
    ]);

    var options = {
        legend: 'none',
        backgroundColor: '#f1f1f1',
        colorAxis: {colors: ['#052c60']},
        datalessRegionColor: '#FFFFFF'
    };

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

    chart.draw(data, options);
}

<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['geochart']}]}"></script>
<div id="regions_div" style="width: 1600px; height: 500px;"></div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

the documentation,将tooltip.trigger设置为&#39; none&#39;

    var options = {
        legend: 'none',
        backgroundColor: '#f1f1f1',
        colorAxis: {colors: ['#052c60']},
        datalessRegionColor: '#FFFFFF',
        tooltip: {trigger:'none'}
    };

fiddle

代码段:

&#13;
&#13;
      google.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() {

        var data = google.visualization.arrayToDataTable([
          ['Country', 'Active'],
          ['Germany', 1],
          ['United States', 1],
          ['Brazil', 1],
          ['Canada', 1],
          ['France', 1],
          ['Russia', 1]
        ]);

        var options = {
          legend: 'none',
          backgroundColor: '#f1f1f1',
          colorAxis: {
            colors: ['#052c60']
          },
          datalessRegionColor: '#FFFFFF',
          tooltip: {
            trigger: 'none'
          }
        };

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

        chart.draw(data, options);
      }
&#13;
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['geochart']}]}"></script>
<div id="regions_div" style="width: 1600px; height: 500px;"></div>
&#13;
&#13;
&#13;