Chart bugged when using equal date values
See original GitHub issueLightweight Charts Version: standalone.production
Steps/code to reproduce:
fetch("/api/tradehistory")
.then(function(response) {
return response.json();
})
.then(function(data,response) {
console.log("Data loaded ")
lineSeries.setData(data.map(line => {
return { time: line.time, value: line.price };
}));
})
This happens since I’m assigning equal time values with different price values
Sample data being fed through tradehistory endpoint
{ "maker_order": "98ab5a24-d113-495c-9d8d-fc2cafb4551a", "pair": "ETHUSD", "price": 110, "quantity": 1, "taker_order": "7d718a29-b1d5-4a61-a11e-0849f3047c6e", "time": 1595258908, "trade_id": "d9e14353-7d37-4906-b2ee-97e2beb60fbe" }, { "maker_order": "e0790be7-4688-4710-974d-d64df1a478da", "pair": "ETHUSD", "price": 100, "quantity": 1, "taker_order": "7d718a29-b1d5-4a61-a11e-0849f3047c6e", "time": 1595258908, "trade_id": "ded10223-bd48-477e-a299-b52b832c698a" }
Actual behavior:
Chart upon loading has very strange lines
Example below:
Right now it shows the chart like this:
But after ~500ms of loading it turns into how it should show
Expected behavior:
As seen above, if the same date value has 2 difference prices it should show an horizontal line for that time
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
I guess it’s related to some overlapping internally. When you set data for series, we prepare it internally (you can see in https://github.com/tradingview/lightweight-charts/blob/master/src/api/data-layer.ts), there is a map of data item by time point. I think that there is some overlapping with is fixed somehow after the next setting data. When you set data, we try to do less and generate “inremental” update whenever it’s possible, so I guess that something is cached from the previous setting a data and is used in the next one. Anyway, every data item must have unique time points and all items must be ordered in asc order.
🤔