jonchurch / tradingview-js-api-tutorial

308 stars 181 forks source link

TypeError: window.TradingView.onready is not a function #16

Open ExchangeAssetsGraphs opened 4 years ago

ExchangeAssetsGraphs commented 4 years ago

I did it according to the instructions (https://medium.com/@jonchurch/tradingview-charting-library-js-api-setup-for-crypto-part-1-57e37f5b3d5a), but I get an error: TypeError: window.TradingView.onready is not a function

http://joxi.ru/BA0GE1VSMLgkQ2

norasteria commented 4 years ago

I did it according to the instructions (https://medium.com/@jonchurch/tradingview-charting-library-js-api-setup-for-crypto-part-1-57e37f5b3d5a), but I get an error: TypeError: window.TradingView.onready is not a function

http://joxi.ru/BA0GE1VSMLgkQ2

got same issue

norasteria commented 4 years ago

I did it according to the instructions (https://medium.com/@jonchurch/tradingview-charting-library-js-api-setup-for-crypto-part-1-57e37f5b3d5a), but I get an error: TypeError: window.TradingView.onready is not a function

http://joxi.ru/BA0GE1VSMLgkQ2

Hi !

I got the same problem, I'm using tradingview v1.14 and I solved that by putting tvWidget configuration outside of window.TradingView.widget.onready() function . I assumed this is because of there's no function called onready(). I found this after I print console.log of window.Tradingview.widget, therefore I putted the configuration outside of that function. Here my code at componentDidMount() method:

  componentDidMount() {
    const widgetOptions = {
      debug: false,
      symbol: this.props.symbol,
      datafeed: Datafeed,
      interval: this.props.interval,
      container_id: this.props.containerId,
      library_path: this.props.libraryPath,
      locale: getLanguageFromURL() || "en",
      disabled_features: ["use_localstorage_for_settings"],
      enabled_features: ["study_templates"],
      charts_storage_url: this.props.chartsStorageUrl,
      charts_storage_api_version: this.props.chartsStorageApiVersion,
      client_id: this.props.clientId,
      user_id: this.props.userId,
      fullscreen: this.props.fullscreen,
      autosize: this.props.autosize,
      studies_overrides: this.props.studiesOverrides,
      overrides: {
        // "mainSeriesProperties.showCountdown": true,
        "paneProperties.background": "#131722",
        "paneProperties.vertGridProperties.color": "#363c4e",
        "paneProperties.horzGridProperties.color": "#363c4e",
        "symbolWatermarkProperties.transparency": 90,
        "scalesProperties.textColor": "#AAA",
        "mainSeriesProperties.candleStyle.wickUpColor": "#336854",
        "mainSeriesProperties.candleStyle.wickDownColor": "#7f323f"
      }
    };

    const widget = (window.tvWidget = new window.TradingView.widget(
      widgetOptions
    ));

    widget.onChartReady(() => {
      console.log("Chart has loaded!");
    });
  }