Wick Charts

usePreviousClose

usePreviousClose: (chart: ChartInstance, seriesId: string) => number | null

Returns the previous-session close for a series, when one is set on the chart. Useful for building custom "% change" overlays that match the built-in <InfoBar>.

Example

import { useChartInstance, useLastYValue, usePreviousClose } from '@wick-charts/react';
 
function ChangePill({ seriesId }: { seriesId: string }) {
const chart = useChartInstance();
const last = useLastYValue(chart, seriesId);
const prev = usePreviousClose(chart, seriesId);
if (last === null || prev === null) return null;
 
const pct = ((last - prev) / prev) * 100;
 
return <span style={{ color: pct >= 0 ? 'limegreen' : 'tomato' }}>{pct.toFixed(2)}%</span>;
}