1

I was trying to use plotly graph library in Angular 6, the graph plotting is working fine but unable to identify how to use plotly JavaScript APIs using the angular component(https://github.com/plotly/angular-plotly.js/blob/master/README.md ).

So, I'm using following code in angular component to directly access plotly JavaScript APIs like deleteTrace, addTrace..

import * as Plotly from 'plotly.js';

But while accessing the Plotly object I'm getting this error:

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)
10
  • why do you import as this? this is not necessary i think. Commented Oct 10, 2018 at 16:15
  • I want to use: Plotly.plot(document.getElementById("anomaly-plot"), this.graph.data, this.graph.layout); Commented Oct 10, 2018 at 16:27
  • @Asanka, can you please suggest some examples how I can use Plotly APIs using angular component. Commented Oct 10, 2018 at 16:30
  • why you don't use it's in angular way? please tell me what you exactly want to do? Commented Oct 10, 2018 at 16:35
  • I mean in GitHub documentation there is not importing plot.js like this. Commented Oct 10, 2018 at 16:39

1 Answer 1

2

Add (window as any).global = window; in your polyfills.ts file. This should work in Chrome, Firefox and Edge. Not sure about IE browser.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.