【问题标题】:Uncaught ReferenceError: global is not defined while using plotly in angular 6未捕获的 ReferenceError:在角度 6 中使用 plotly 时未定义全局
【发布时间】:2019-04-25 17:18:15
【问题描述】:

我尝试在 Angular 6 中使用 plotly 图形库,图形绘制工作正常,但无法确定如何使用 angular 组件 (https://github.com/plotly/angular-plotly.js/blob/master/README.md) 使用 plotly JavaScript API。

所以,我在 angular 组件中使用以下代码来直接访问 plotly JavaScript API,例如 deleteTrace、addTrace..

import * as Plotly from 'plotly.js';

但在访问 Plotly 对象时出现此错误:

index.js:6 Uncaught ReferenceError: global is not defined
    at Object../node_modules/has-hover/index.js (index.js:6)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/plotly.js/src/plot_api/plot_api.js (plot_api.js:15)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/plotly.js/src/plot_api/index.js (index.js:11)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/plotly.js/src/core.js (core.js:28)
    at __webpack_require__ (bootstrap:76)
    at Object../node_modules/plotly.js/lib/core.js (core.js:11)
    at __webpack_require__ (bootstrap:76)

【问题讨论】:

  • 为什么要这样导入?我认为这没有必要。
  • 我要使用:Plotly.plot(document.getElementById("anomaly-plot"), this.graph.data, this.graph.layout);
  • @Asanka,您能否建议一些示例,如何使用 Angular 组件使用 Plotly API。
  • 为什么你不以有角度的方式使用它?请告诉我你到底想做什么?
  • 我的意思是在 GitHub 文档中没有像这样导入 plot.js。

标签: angular angular6 plotly


【解决方案1】:

在您的 polyfills.ts 文件中添加 (window as any).global = window;。这应该适用于 Chrome、Firefox 和 Edge。不知道IE浏览器。

【讨论】:

    猜你喜欢
    • 2017-12-23
    • 1970-01-01
    • 2014-06-17
    • 1970-01-01
    • 2018-12-16
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    相关资源
    最近更新 更多