[英]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.