javascript - Google Geochart 可视化库未加载
问题描述
前段时间,我使用较旧的 Google JS 库版本创建了一个 Google Geochart 小部件。现在谷歌建议升级以更新到加载器 api 而不是 jsapi。无论我如何加载库,对我来说,可视化库都无法正确加载,因此在尝试实例化 GeoChart 对象时我得到一个未定义的结果。其他人也遇到过这个问题吗?
(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);
});
推荐阅读
- python - django 写入外部设备时权限被拒绝
- spring - 无效的访问令牌 Spring Boot 资源服务器
- amazon-web-services - 在合理的时间内将 2tb(1.5 亿+)个项目从一个 s3 存储桶移动到另一个存储桶
- python-2.7 - 如何创建类型化的空 MapType?
- c# - 无法使用带有 Windows 身份验证的连接字符串连接到 SQL Server
- python - 我无法将我的 perlin 噪声图生成器变成我的游戏的 pygame tilemap
- c - LoadRunner 12.55 连接目标站点失败
- wpf - 当我更新标签的内容时,WPF 应用程序页面没有更新
- node.js - Node JS Promise.all 返回值
- tomcat - Tomcat 安全密钥警告