繁体   English   中英

未加载 Google Geochart 可视化库

[英]Google Geochart visualization library not loaded

前段时间我用旧的 Google JS 库版本创建了一个 Google Geochart 小部件。 现在谷歌建议升级更新到 loader api 而不是 jsapi。 无论我如何加载库,对我来说,可视化库都无法正确加载,因此在尝试实例化 GeoChart 对象时会得到一个 undefined 。 有没有其他人也遇到过这个问题?

(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需要对函数的引用 --> this.drawChart

不是函数的结果 --> this.drawChart(callback)

尝试如下...

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

暂无
暂无

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

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