<html>
<head>
<title>TradingView Charting Library demo</title>
<!-- Fix for iOS Safari zooming bug -->
<meta
name="viewport"
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"
/>
<script
type="text/javascript"
src="https://charting-library.tradingview-widget.com/charting_library/charting_library.standalone.js"
></script>
<script
type="text/javascript"
src="https://charting-library.tradingview-widget.com/datafeeds/udf/dist/bundle.js"
></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body style="margin: 0px">
<div id="tv_chart_container"></div>
</body>
</html>
xxxxxxxxxx
let isOffline = true;
function initOnReady() {
class TestDatafeed extends Datafeeds.UDFCompatibleDatafeed {
resolveSymbol(symbolName, onResolve, onError, extension) {
console.log({ symbolName });
if (isOffline) {
setTimeout(() => {
onError('Currently Offline')
},0);
return;
}
let actualSymbolName = symbolName;
if (actualSymbolName.includes('_reload')) {
actualSymbolName = actualSymbolName.replace(/_reload\d*/, '');
console.log({ actualSymbolName });
}
super.resolveSymbol(actualSymbolName, onResolve, onError, extension)
}
getBars(symbolInfo, resolution, periodParams, onResult, onError) {
if (isOffline) {
setTimeout(() => {
onError('Currently Offline')
},0);
return;
}
super.getBars(symbolInfo, resolution, periodParams, onResult, onError);
}
}
var widget = (window.tvWidget = new TradingView.widget({
library_path:
"https://charting-library.tradingview-widget.com/charting_library/",
// debug: true, // uncomment this line to see Library errors and warnings in the console
fullscreen: true,
symbol: "AAPL",
interval: "1D",
container: "tv_chart_container",
datafeed: new TestDatafeed(
"https://demo-feed-data.tradingview.com"
),
locale: "en",
disabled_features: [],
enabled_features: [],
}));
setTimeout(() => {
console.log('Put back online');
isOffline = false;
widget.activeChart().resetData();
// if the symbol info or no data was ever loaded
// then you can reset everything by switching the symbol
const currentSymbol = widget.activeChart().symbol();
widget.activeChart().setSymbol(currentSymbol + '_reload' + Math.round(Math.random() * 1000));
}, 5000);
}
window.addEventListener("DOMContentLoaded", initOnReady, false);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.