Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to make a trading view widget in lwc from an external site?

Asked by Dipesh Bhardwaj May 11, 2023 1.4K views 1 answer
Share

About this question

I have a problem making a widget in  from an external site. My code from external site is:


<html>
  
 
    
 
     
    [removed][removed] 
    [removed] 
      new TradingView.widget( 
        { 
        //"autosize": true, 
        "height": 423, 
        "width": 600, 
        "symbol": "NYMEX:TTF1!", 
        "timezone": "Europe/Warsaw", 
        "theme": "dark", 
        "style": "3", 
        "locale": "pl", 
        "toolbar_bg": "#f1f3f6", 
        "enable_publishing": false, 
        "hide_top_toolbar": true, 
        "withdateranges": true, 
        "range": "YTD", 
        "details": true, 
        "container_id": 
        "tradingview_04149"
        } 
      ); 
    [removed]
  

</html>
I downloaded the script tv.js and took it to the static resources as myLib. I make a new lwc component tradeGaz. My html file is:

My js file is:

import { LightningElement } from 'lwc';
import myLib from '@salesforce/resourceUrl/myLib';
import { loadScript } from 'lightning/platformResourceLoader';
export default class GasTrade extends LightningElement {
    connectedCallback(){
        loadScript(this, myLib).then(() => { 
            console.log('yes it is working'); 
            new TradingView.widget({  
            "height": 423, 
            "width": 600, 
            "symbol": "NYMEX:TTF1!", 
            "timezone": "Europe/Warsaw", 
            "theme": "dark", 
            "style": "3", 
            "locale": "pl", 
            "toolbar_bg": "#f1f3f6", 
            "enable_publishing": false, 
            "hide_top_toolbar": true, 
            "withdateranges": true, 
            "range": "YTD", 
            "details": true, 
            "container_id": 
            "tradingview_04149" });
        }); 
    }
}

But the chart is not working. Please help me, what I have to do to fix this problem.

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.