【发布时间】: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。