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(() => {
|
useEffect(() => {
|
||||||
if (!seriesRef.current || candles.length === 0) return;
|
if (!seriesRef.current || candles.length === 0) return;
|
||||||
|
|
||||||
const chartData: CandlestickData[] = candles.map((candle) => ({
|
const chartData: CandlestickData[] = candles
|
||||||
time: candle.time as Time,
|
.map((candle) => ({
|
||||||
open: candle.open,
|
time: candle.time as Time,
|
||||||
high: candle.high,
|
open: candle.open,
|
||||||
low: candle.low,
|
high: candle.high,
|
||||||
close: candle.close,
|
low: candle.low,
|
||||||
}));
|
close: candle.close,
|
||||||
|
}))
|
||||||
|
.sort((a, b) => (a.time as number) - (b.time as number));
|
||||||
|
|
||||||
seriesRef.current.setData(chartData);
|
seriesRef.current.setData(chartData);
|
||||||
}, [candles]);
|
}, [candles]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue