如何在React Native Expo中使用TradingView?

huangapple go评论59阅读模式
英文:

How to use Trading view in react native Expo?

问题

我想使用React Native和Expo制作交易应用,但我不知道如何将TradingView集成到React Native应用中。

我尝试过其他图表库,但它们不如TradingView丰富,我也看到了TradingView的React Native示例,但它不是在Expo中,并且文档质量较差。

英文:

I want to make trading App with react native and expo, and I don't know how to integrate Trading view with react native app.

I did try other chart libraries, but they are not as rich as Trading view, and I saw Trading view react native example but it's not in expo and it has a poor documentation.

答案1

得分: 1

你可以在React Native Expo中使用WebView来使用TradingView图表。
运行:

npx expo install react-native-webview

使用TradingView的HTML示例:

const htmlContent = `
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>TradingView Chart</title>
    <script src="https://s3.tradingview.com/tv.js"></script>
    <style>
    .tv-header__title {
        font-size: 120px !important;
    }
    #tv_chart_container {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        font-size: 45px !important;
      }
    .tv-header__top-line {
        height: 250px !important;
    }
  </style>
  </head>
  <body>
    <div id="tv_chart_container"></div>
    <script>
      const tvChart = new TradingView.widget({
        symbol: '${coinId}USD',
        interval: '5',
        timezone: 'Etc/UTC',
        theme: 'dark',
        width: '100%',
        height: '99.5%',
        style: '1',
        theme: 'light',
        save_image: false,
        locale: 'en',
        hide_side_toolbar: false,
        toolbar_bg: '#f1f3f6',
        container_id: 'tv_chart_container'
      });
      tvChart.onChartReady(function() {
        tvChart.addCustomCSSFile('./tradingView.css')
      })
    </script>
  </body>
</html>
`;

并在WebView标签中使用它:

<WebView source={{ html: htmlContent }} />
英文:

You can use TradingView chart by webView in react native expo.
run:

npx expo install react-native-webview

use TradingView html for example:

const htmlContent = `
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
    &lt;title&gt;TradingView Chart&lt;/title&gt;
    &lt;script src=&quot;https://s3.tradingview.com/tv.js&quot;&gt;&lt;/script&gt;
    &lt;style&gt;
    .tv-header__title {
        font-size: 120px !important;
    }
    #tv_chart_container {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        font-size: 45px !important;
      }
    .tv-header__top-line {
        height: 250px !important;
    }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;tv_chart_container&quot;&gt;&lt;/div&gt;
    &lt;script&gt;
      const tvChart = new TradingView.widget({
        symbol: &#39;${coinId}USD&#39;,
        interval: &#39;5&#39;,
        timezone: &#39;Etc/UTC&#39;,
        theme: &#39;dark&#39;,
        width: &#39;100%&#39;,
        height: &#39;99.5%&#39;,
        style: &#39;1&#39;,
        theme: &#39;light&#39;,
        save_image: false,
        locale: &#39;en&#39;,
        hide_side_toolbar: false,
        toolbar_bg: &#39;#f1f3f6&#39;,
        container_id: &#39;tv_chart_container&#39;
      });
      tvChart.onChartReady(function() {
        tvChart.addCustomCSSFile(&#39;./tradingView.css&#39;)
      })
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt; `;

and use it in webView tag:

&lt;WebView source={{ html: htmlContent }} /&gt;

huangapple
  • 本文由 发表于 2023年6月1日 14:46:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定