fix: sort candle data before displaying in chart
- Add sorting by timestamp in ascending order before setting chart data - Fixes 'data must be asc ordered by time' error from lightweight-charts - Ensures chart displays correctly even if API returns unsorted data
This commit is contained in:
parent
11f0759b0e
commit
17eb2ca745
1 changed files with 9 additions and 7 deletions
|
|
@ -136,13 +136,15 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
|
|||
useEffect(() => {
|
||||
if (!seriesRef.current || candles.length === 0) return;
|
||||
|
||||
const chartData: CandlestickData[] = candles.map((candle) => ({
|
||||
time: candle.time as Time,
|
||||
open: candle.open,
|
||||
high: candle.high,
|
||||
low: candle.low,
|
||||
close: candle.close,
|
||||
}));
|
||||
const chartData: CandlestickData[] = candles
|
||||
.map((candle) => ({
|
||||
time: candle.time as Time,
|
||||
open: candle.open,
|
||||
high: candle.high,
|
||||
low: candle.low,
|
||||
close: candle.close,
|
||||
}))
|
||||
.sort((a, b) => (a.time as number) - (b.time as number));
|
||||
|
||||
seriesRef.current.setData(chartData);
|
||||
}, [candles]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue