javascript - Google GeoChart 忽略宽度/高度

标签 javascript google-maps google-visualization

直到昨天,当谷歌地理图表停止收听我时,这一切都很好!

宽度和高度被忽略, map 已返回到其全宽 div 右上角的小版本。

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


    function drawMap() {

        var data = new google.visualization.DataTable();
        data.addColumn('string', 'City'); 
        data.addColumn('number', 'Visits'); 
        data.addColumn({type:'string', role:'tooltip', 'p': {'html': true}}); 
        data.addRows(#{GuideEditController.getCitiesData()});

  var options = {
        sizeAxis: { minValue: 0, maxValue: 100 },       
        displayMode: 'markers',
        colorAxis: {colors: ['#33ADFF', '#003D66']},
        width : '100%',
        height : '600px',
        enableRegionInteractivity: false,
        keepAspectRatio: true,
        legend : 'none',
        tooltip: {isHtml: true}
      };

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


      ....
     <div class="map" id='map_canvas'></div>
       <script type='text/javascript'>
       drawMap();
       </script>

image

这个 DIV 似乎是我的罪魁祸首。我不知道它来自哪里,但假设它是谷歌的东西。

在 DIV 之后进行调用的原因是 map 加载在主页之后加载的选项卡上。

昨天还好好的。。。

最佳答案

Google GeoChart 似乎忽略了宽度和高度选项(尽管他们在 https://developers.google.com/chart/interactive/docs/gallery/geochart 中提到了它们)。

我有一个类似的问题,这对我有用:

var options = {
    sizeAxis: { minValue: 0, maxValue: 100 },       
    displayMode: 'markers',
    colorAxis: {colors: ['#33ADFF', '#003D66']},
    enableRegionInteractivity: false,
    keepAspectRatio: true,
    legend : 'none',
    tooltip: {isHtml: true}
};

...

<div id="map_canvas" class="map" style="width: 100%; height: 600px;"></div>

关于javascript - Google GeoChart 忽略宽度/高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30795153/

相关文章:

javascript - 将 JQuery ajax GET 转换为 POST

javascript - 我在 javascript 中读取 cookie 时遇到问题

javascript - 如果还有其他故障排除

javascript - JQuery 不删除添加的元素

jquery - 如何在带有 mask 的 div 中插入谷歌地图

google-maps - html5 移动应用程序的多点触控支持?专用于 map 缩放/显示

java - 将 JSON 数据解析为 map 标记,所有标记显示相同的信息,我该如何解决这个问题?

javascript - 获取点击柱形图的图例

javascript - 如何创建过去二十四小时的 Google 面积图

javascript - 谷歌图表 - 绘制后运行功能