jonchurch / tradingview-js-api-tutorial

308 stars 181 forks source link

TypeError: window.TradingView is undefined #10

Open AndriusDK opened 5 years ago

AndriusDK commented 5 years ago

Hello whenever I try to reuse the component TVChartContainer /> i get the following error TypeError: window.TradingView is undefined

jonchurch commented 5 years ago

The charting library isnt included, you need to download it separately from tradingview On Fri, Mar 22, 2019 at 9:50 AM AndriusDK notifications@github.com wrote:

Hello whenever I try to reuse the component i get the following error TypeError: window.TradingView is undefined

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jonchurch/tradingview-js-api-tutorial/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/AMUR2_QQaIDG9ZoE_QH5JwXaOBPaDPCpks5vZN-ggaJpZM4cDnOn .

AndriusDK commented 5 years ago

The charting library isnt included, you need to download it separately from tradingview On Fri, Mar 22, 2019 at 9:50 AM AndriusDK @.***> wrote: Hello whenever I try to reuse the component i get the following error TypeError: window.TradingView is undefined — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#10>, or mute the thread https://github.com/notifications/unsubscribe-auth/AMUR2_QQaIDG9ZoE_QH5JwXaOBPaDPCpks5vZN-ggaJpZM4cDnOn .

Hello again the thing is that I have the libraries included from the private repository. Just I have my webapp in react and I try to include your implementation files to my project.

jianqiangsong commented 5 years ago

TypeError: Cannot read property 'onready' of undefined TVChartContainer.componentDidMount C:/Users/Administrator/Desktop/test_tv/tradingview-js-api-tutorial/part2/src/components/TVChartContainer/index.jsx:58

nicqchen commented 5 years ago

same error

BStephenBB commented 5 years ago

Yes, I'm getting the same error as well, and I have included the charting library properly. I figured out the problem: in the repo nothing is ever imported from the charting library, so of course TradingView is undefined; it's never imported! I fixed and got it to work by importing { widget } from the trading view library, and then using

tvWidget = null;
const tvWidget = new widget(widgetOptions);
this.tvWidget = tvWidget;

in my code instead of this repo's window.TradingView.onready implementation. @AndriusDK @nicqchen @jianqiangsong let me know if this works for you guys and if you're still stuck I'd be happy to make a PR to the repo so you can see what to do. Good luck!

AndriusDK commented 5 years ago

Yes, I'm getting the same error as well, and I have included the charting library properly. I figured out the problem: in the repo nothing is ever imported from the charting library, so of course TradingView is undefined; it's never imported! I fixed and got it to work by importing { widget } from the trading view library, and then using

tvWidget = null;
const tvWidget = new widget(widgetOptions);
this.tvWidget = tvWidget;

in my code instead of this repo's window.TradingView.onready implementation. @AndriusDK @nicqchen @jianqiangsong let me know if this works for you guys and if you're still stuck I'd be happy to make a PR to the repo so you can see what to do. Good luck!

It works thanks!

vnsfin commented 5 years ago

@BStephenBB can you please provide complete code as i am unable to make this working

Albot15 commented 5 years ago

Does anybody have a solution on this? I am also getting the same error "TypeError: window.TradingView is undefined".

I have included charting library.

BStephenBB commented 5 years ago

@vnsfin @drajvat See my comment above on how to get this working, I put the important lines of code there. I'm very busy right now, but can provide a full file-example later when I get the time if it's still not working for you guys.

SatAndrei commented 5 years ago

Can anyone post the line of importing the Widget?

SatAndrei commented 5 years ago

@rokoz77

Failed to compile
./src/components/TVChartContainer/index.jsx
  Line 61:  'TradingView' is not defined  no-undef
  Line 94:  'widget' is not defined       no-undef

Hei. I've tried to insert your solution in my index.jsx but i get that error. Can you please provide the whole file?

My index.jsx file looks like this: https://pastebin.com/U6q2p8bw

rokoz77 commented 5 years ago

You already have a widgetOptions so you don't have to add it You only need to import tv.js lib Maybe you need to download it

https://s3.tradingview.com/tv.js

Edit : sorry i'm talking about somethink else

SatAndrei commented 5 years ago

@BStephenBB Hello. I've tried your solution and posted my index.jsx and errors above. I can't figure out where to export the {widget} from.

miky9585 commented 5 years ago

Yes, I'm getting the same error as well, and I have included the charting library properly. I figured out the problem: in the repo nothing is ever imported from the charting library, so of course TradingView is undefined; it's never imported! I fixed and got it to work by importing { widget } from the trading view library, and then using

tvWidget = null;
const tvWidget = new widget(widgetOptions);
this.tvWidget = tvWidget;

in my code instead of this repo's window.TradingView.onready implementation. @AndriusDK @nicqchen @jianqiangsong let me know if this works for you guys and if you're still stuck I'd be happy to make a PR to the repo so you can see what to do. Good luck!

It works thanks!

using this into /src/components/TVChartContainer/index.jsx import { widget } from '../../charting_library/charting_library.min.d.ts'; I have TypeError: __WEBPACK_IMPORTED_MODULE_3__charting_library_charting_library_min_d_ts__.widget is not a constructor

What is wrong with my import?

miky9585 commented 5 years ago

I've solved. Maybe is useful for someone else. Step 1) You need to copy charting_library into /src folder too (not only in public!) Step 2) Put / eslint-disable / at the top of /src/chrating_library/charting_library.min.js Step 3) Include widget with this code into /src/components/TVChartContainer/index.jsx import { widget } from '../../charting_library/charting_library.min'; without extension Step 4) put tvWidget = null; before componentDidMount() Step 5) Remove everything start with "window.TradingView" and paste with this

const tvWidget = new widget(widgetOptions); this.tvWidget = tvWidget; this.tvWidget.onChartReady(() => { console.log('Chart has loaded!') });

daveb1392 commented 5 years ago

@miky9585 Thank you soo much that fixed it

TholeThilis commented 5 years ago

Hi @miky9585 @daveb1392 I've been trying to follow the above steps but i don't seem to get it right, can you please. i'm definitely sure that my importing is not right. i need to get this charting library soon. i don't have experience in programming but i have learnt most of the things on the internet... we can even communicate through Skype or Teamviewer when necessary. Thank you.

joesmith34625 commented 4 years ago

I followed jonchurch's part1 instruction, I got this error. TypeError: window.TradingView.onready is not a function after I replaced below line, it works from window.TradingView.onready(() => { to window.addEventListener('DOMContentLoaded',() => {

amkamn commented 3 years ago

Maybe is useful for someone else.

  1. public folder -> paste charting_library folder

  2. Charting Component ->

    
    const widgetOptions = {
     //some Widget options
    };
    let widget = null;
    widget = window.tvWidget = new window.TradingView.widget(widgetOptions);
    }
sahilxjain commented 3 years ago

In the recent version of charting library, charting_library.min.js is missing. I solved it by using charting_library.js instead.