【问题标题】:How to reposition tradingview chart so not going off screen to the left如何重新定位tradingview图表,以免离开屏幕左侧
【发布时间】:2021-03-04 14:39:10
【问题描述】:

Wepbage Output

我正在尝试将交易视图轻量级图表重新定位到更中心的位置,而不是延伸到屏幕之外。附加图像是当前显示的输出。

轻量级图表 Github = https://github.com/tradingview/lightweight-charts

import React from 'react';
import { createChart } from 'lightweight-charts';

const chart = createChart(document.body, { width: 800, height: 500});
const candlestickSeries = chart.addCandlestickSeries();

const log = console.log;

function populateChart() {
    fetch(`https://api.binance.com/api/v3/klines?symbol=ETHUSDT&interval=4h&limit=1000`)
        .then(res => res.json())
        .then(data => {
            const cdata = data.map(d => {
                return { time: d[0] / 1000, open: parseFloat(d[1]), high: parseFloat(d[2]), low:parseFloat(d[3]), close: parseFloat(d[4]) }
        });
        candlestickSeries.setData(cdata);
    })
    .catch(err => log(err))

}

render() {
    return (
        
        <div>
            <h1>Ethereum | USDT</h1>
            <p>{populateChart()}</p>  


        </div>
    );
}

}

【问题讨论】:

    标签: javascript reactjs charts cryptocurrency tradingview-api


    【解决方案1】:

    您是否尝试过以下方法:

    render() {
        return (
            <div style='text-align:center;'>
                <h1>Ethereum | USDT</h1>
                <div>{populateChart()}</div>
            </div>
        );
    }
    

    p 更改为div,让您可以根据需要更灵活地更改图表。然后我将起始 div 更改为具有 CSS 属性 text-align:center;,它将使所有元素居中。

    【讨论】:

      猜你喜欢
      • 2015-06-10
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多