简体   繁体   English

未加载 Google Geochart 可视化库

[英]Google Geochart visualization library not loaded

I have created a Google Geochart widget some time ago with an older Google JS library version.前段时间我用旧的 Google JS 库版本创建了一个 Google Geochart 小部件。 Nowadays Google advised to upgrade to update to the loader api instead of the jsapi.现在谷歌建议升级更新到 loader api 而不是 jsapi。 No matter how I load the libraries, for me the visualization library doesn't load properly, hence I get an undefined when trying to instantiate a GeoChart object.无论我如何加载库,对我来说,可视化库都无法正确加载,因此在尝试实例化 GeoChart 对象时会得到一个 undefined 。 Did anybody else encounter this issue as well?有没有其他人也遇到过这个问题?

(The JS code is in the form of Dojo widget functions) (JS代码为Dojo小部件函数形式)

update : function(obj, callback){
        
        this._contextObj = obj;
        this._resetSubscriptions(); 
        if (this.apiAccessKey && this.apiAccessKey !== "") {
            google.charts.load('current', {
                'packages':['geochart'],
                // Note: you will need to get a mapsApiKey for your project.
                // See: https://developers.google.com/chart/interactive/docs/basic_load_libs#load-settings
                'mapsApiKey': this.apiAccessKey
                });
                google.charts.setOnLoadCallback(this.drawChart(callback));
        } else {
            var message = " Google Geochart needs an active API key to work!";
            console.error(this._logNode + message);
            alert(message);
        }           

    },  
    drawChart : function (callback) {
        
        // Run this as soon as google charts is loaded.
        // Create map and its container.

        if (!this.geoMap) {

            this.geoMap = new google.visualization.GeoChart(this.geoMapContainer);  
                            
        }
        
        if (this._contextObj){
            this._getObjects(this._contextObj.getGuid,callback);
        } else {
            this._getObjects(null,callback);
        }
        
        this._executeCallback(callback);
                    
    },

setOnLoadCallback expects a reference to a function --> this.drawChart setOnLoadCallback需要对函数的引用 --> this.drawChart

not the result of a function --> this.drawChart(callback)不是函数的结果 --> this.drawChart(callback)

try as follows...尝试如下...

google.charts.setOnLoadCallback(function () {
  this.drawChart(callback);
});

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

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