I’m adding a TradingView chart to my website, using Javascript.
I want to know when the chart is loaded and the data was loaded successfully, and print the success status in a dedicated textbox.
My code doesn’t work, I added a onChartReady callback, but it never get there, even when the chart is loaded successfully.
Here is the relevant code I created:
widget = new TradingView.widget({
"width": "100%",
"height": 500,
"symbol": symbol,
"interval": "D",
"timezone": "Etc/UTC",
"theme": "light",
"style": "1",
"locale": "en",
"datafeed": "Datafeed",
"toolbar_bg": "#f1f3f6",
"enable_publishing": false,
"allow_symbol_change": true,
"container_id": "tradingview_widget",
});
widget.onChartReady(function () {
chartLoaded = true;
document.getElementById('result').textContent = "Chart loaded successfully!";
});
I also tried to put the onChartReady inside the new TradingView.widget block, but it still doesn’t work.
Any ideas what should I change in order to make it work?
Thank you