I have embedded a stock chart from Tradingview into my site, but I cannot make it responsive (especially the width). When the page shrinks the chart begin to move outside the screen. Here is the code:
<div class="tradingview-widget-container">
<div id="tradingview_8e656"></div>
<div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/SP-SPX/" rel="noopener" target="_blank"><span class="blue-text">SPX chart</span></a> by TradingView</div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
new TradingView.widget({
"height": 610,
"symbol": "SP:SPX",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "Light",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": false,
"hide_side_toolbar": false,
"allow_symbol_change": true,
"container_id": "tradingview_8e656"
});
</script>
</div>
I tried changing the units in width to rem
and %
(because I suppose they use px
) but it didn't work. I also tried erasing height and width completly and adding "autosize": true
instead. Then I thought that maybe I'm not editing it correctly, so I started learning about JavaScript objects in W3Schools. Couldn't find the information there either.
The best solution that I could come with is to set the overflow
to hidden
, but you can understand it's not right. What I need is something like "shrink to fit" property or simply edit the javascript somehow.
Other links I read (which also didn't help):
Here is my entire code- what I wanted to achieve is to open the chart from the navbar (I am using bootstrap):
<div class="container-fluid sticky-top">
<nav class="navbar navbar-expand-lg" style="background-color:#1B2034">
<img src="media/a1.jpg" style="height:4rem;width:8rem">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon mb-2"><i class="fa fa-bars fa-2x" style="color:#0040ff"></i></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">home page<span class="sr-only">את/ה כאן</span></a>
</li>
<li class="nav-item">
**<a class="nav-link" data-toggle="collapse" href="#graphs">chart page</a>**
</li>
<!-- other nav items -->
<li class="nav-item mt-2">
<input class="form-control" type="search" placeholder="חיפוש" aria-label="Search">
</li>
<li class="nav-item mt-2">
<button class="btn btn-outline-info mr-2" type="submit">חיפוש</button>
</li>
</ul>
</div>
</nav>
<!-- Other pages -->
<div class="container-fluid">
<div class="collapse sticky-top" style="top:5rem;overflow:hidden" id="graphs">
<div class="card card-body height:100%">
<!-- TradingView Widget BEGIN -->
THE CHART CODE
<!-- TradingView Widget END -->
</div>
</div>
<div class="collapse sticky-top" style="top:5rem;overflow:hidden" id="graphs">
<div class="card card-body height:100%">
... Repeats ...