3

I have a problem with the chart widget. It does not adjust to the height automatically.

How can I fix or make responsive it?

new TradingView.widget(
  {
    "autosize": true,
  "symbol": "BINANCE:BTCUSDTPERP",
  "interval": "5",
  "timezone": "America/Chicago",
  "theme": "dark",
  "style": "1",
  "locale": "es",
  "toolbar_bg": "#f1f3f6",
  "enable_publishing": false,
  "hide_side_toolbar": true,
  "hide_top_toolbar": true,
  "watchlist": [
    "BINANCE:BTCUSDTPERP",
    "BINANCE:ETHUSDTPERP",
    "BINANCE:1INCHUSDTPERP",
    "BINANCE:XLMUSDTPERP",
    "BINANCE:DOGEUSDTPERP",
    "BINANCE:XRPUSDTPERP",
    "BINANCE:ADAUSDTPERP"
  ],
  // "details": true,
  "container_id": "tradingview_447bd"
}
  );
  </script>

height issue

Flair
  • 2,609
  • 1
  • 29
  • 41
bashman
  • 138
  • 2
  • 11

2 Answers2

0
<style>
      div {
          height: 100vh;
      }
</style>
Incognito
  • 11
  • 1
  • 1
0

I know this isn't quite elegant... but I was having the same problem and fixed this way (I'm using Tailwind CSS)

<main ckass="w-full h-screen" id="main">
  <!-- Tradingview Widget -->

  <!-- ... -->

  <script type="text/javascript">
    let main = document.querySelector('#main')
    let width = main.offsetWidth
    let height = main.offsetHeight

    new TradingView.widget(
    {
      // "autosize": true,
      "width": width,
      "height": height,
      "symbol": "NASDAQ:AAPL",
      // ... etc.
    });
  </script>
  
</main>

So basically I calculated the width and height of the parent element and pass it to the widget ‍♂️

Now this thing isn't responsive...

luisfer
  • 1,927
  • 7
  • 40
  • 54