You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Charts于2020年7月9日起无法在IE11运行,是否终止IE11支持?

解决Google Charts在IE11中出现object doesn't support object or method assign错误

我上周刚帮客户处理了完全一样的问题!2020年7月Google Charts的current分支悄悄做了更新,引入了IE11原生不支持的ES6特性Object.assign——这就是你看到报错的核心原因。有意思的是官方没发终止IE11支持的公开通知,但实际代码已经移除了兼容处理,连他们自己的Chart Gallery和新加坡地铁仪表板示例都中招了,那段时间不少开发者都踩了这个坑。

给你两个亲测有效的解决方案:

方案一:添加Object.assign Polyfill

在加载Google Charts的代码之前,先插入一段兼容IE11的补丁代码,手动实现Object.assign功能:

if (typeof Object.assign !== 'function') {
  Object.assign = function(target) {
    'use strict';
    if (target == null) {
      throw new TypeError('Cannot convert undefined or null to object');
    }
    target = Object(target);
    for (var index = 1; index < arguments.length; index++) {
      var source = arguments[index];
      if (source != null) {
        for (var key in source) {
          if (Object.prototype.hasOwnProperty.call(source, key)) {
            target[key] = source[key];
          }
        }
      }
    }
    return target;
  };
}

插完这段代码再执行你的loadGoogle函数,IE11就能正常加载图表了。

方案二:指定加载Google Charts的旧版本

如果不想额外加补丁,可以把加载代码里的"current"换成最后一批支持IE11的稳定版本号,比如"45":

function loadGoogle() { // define callback in load statement
    try {
        google.charts.load("45", {packages:["corechart","timeline"],'callback': loadcomplete});
    } catch(err) {
        cdpAlert("Google Charts Could not be loaded. Please check your internet connection. Error: " + err);
    }
}

这个方法更直接,不用额外引入代码,但缺点是没法用到Google Charts后续更新的新特性。

你可以根据自己的需求选一个方案,应该能立刻解决问题。

内容的提问来源于stack exchange,提问作者Mike Cooper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 12:33:14