简体   繁体   English

使用Google图表库制作未显示的GeoChart

[英]Use Google Charting library to make a GeoChart which isn't showing

everyone. 大家。 I have a problem. 我有个问题。 I am making a web page and I want to include a GeoChart in it. 我正在制作一个网页,并且要在其中包含一个GeoChart。 The problem is that even when I directly copy-paste from the Google developer's website and incorporate the code into the pre-existing one, the map doesn't show. 问题是,即使我直接从Google开发人员的网站复制粘贴并将代码合并到现有的代码中,地图也不会显示。 I don't know what I am doing wrong. 我不知道我在做什么错。

This is the JavaScript portion:- 这是JavaScript部分:-

<script>
google.charts.load('current', {'packages':['geochart']});
        google.charts.setOnLoadCallback(drawRegionsMap);

        function drawRegionsMap()
        {
            var data = google.visualization.arrayToDataTable([
            ['Country', 'Popularity'],
            ['Germany', 200],
            ['United States', 300],
            ['Brazil', 400],
            ['Canada', 500],
            ['France', 600],
            ['RU', 700]
            ]);

            var options = {};

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

            chart.draw(data, options);
        }
</script>

This is the HTML portion:- 这是HTML部分:-

<div=id='regions_div' style="width: 600px; height: 500px;"></div>

looks like the main problem is the extra = in the div definition, here... 似乎主要问题是div定义中的extra = ,在这里...
<div=id='regions_div' style="width: 600px; height: 500px;"></div>

as such, the chart cannot find the container, which is being reported in the browser console. 因此,图表无法找到在浏览器控制台中报告的容器。

change to... 改成...
<div id='regions_div' style="width: 600px; height: 500px;"></div>

also, be sure to load both libraries -- loader.js & jsapi 另外,请确保同时加载两个库loader.jsjsapi

following is a working snippet... 以下是有效的代码段...

 google.charts.load('current', { callback: function () { var data = google.visualization.arrayToDataTable([ ['Country', 'Popularity'], ['Germany', 200], ['United States', 300], ['Brazil', 400], ['Canada', 500], ['France', 600], ['RU', 700] ]); var options = {}; var chart = new google.visualization.GeoChart(document.getElementById('regions_div')); chart.draw(data, options); }, packages:['geochart'] }); 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <script src="https://www.google.com/jsapi"></script> <div id='regions_div' style="width: 600px; height: 500px;"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM