简体   繁体   中英

Tradingview Lightweight candlestick charts price depth

I'm building a candlestick chart with preset of price data. By default it is set to two decimals 0.01 of price. However my price data ranges way past from 0.01 to 0.0000002 etc. I'm trying to implement priceFormat property but it doesn't work. Thank you

Here's my code and chart data



const log = console.log;

const chartProperties = {
    width:1200,
    height:600,
    timeScale:{
        timeVisible:true,
        secondsVisible:false,
    },
    priceFormat: {
        type: 'price',
        precision: 6,
        minMove: 0.000001,
    },
}

const domElement = document.getElementById('chart');
const chart = LightweightCharts.createChart(domElement,chartProperties);
const candleSeries = chart.addCandlestickSeries();

fetch(`http://localhost:8888/chart/dataset.txt`)
    .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])}
        });
        candleSeries.setData(cdata);
    })
    .catch(err => log(err));
[
[1640060100000,"0.004","0.008","0.002","0.0055",1640060159999],[1640060160000,"0.0055","0.008","0.002","0.005",1640060219999],[1640078220000,"0.005","0.008","0.002","0.0045",1640078279000],[1640078280000,"0.0045","0.0065","0.0043","0.0058",1640078339000]
]

From https://github.com/tradingview/lightweight-charts/discussions/697 :

To change format of your series' data you need to override price format for your series by changing/applying options.

For example, if you'd like to show 6 digits after a comma you can use the following options:

series.applyOptions({
    priceFormat: {
        type: 'price',
        precision: 6,
        minMove: 0.000001,
    },
});

Also, you can look at this test case for more complete example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM