From 43dd977c4cf0bf4cc6cdee39fcaa4778f1cb12c2 Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Mon, 19 Jan 2026 18:34:53 +0100 Subject: [PATCH] fix: update ChartTooltip to correctly display current metric values in tooltip based on payload order --- components/dashboard/Chart.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/dashboard/Chart.tsx b/components/dashboard/Chart.tsx index 2266add..5ae0855 100644 --- a/components/dashboard/Chart.tsx +++ b/components/dashboard/Chart.tsx @@ -84,9 +84,13 @@ function ChartTooltip({ colors: typeof CHART_COLORS_LIGHT }) { if (!active || !payload?.length || !label) return null - const d = payload[0] - const value = d.value as number - const prev = metric === 'visitors' ? d.payload.prevVisitors : d.payload.prevPageviews + // * Recharts sends one payload entry per Area; order can be [prevSeries, currentSeries]. + // * Use the entry for the current metric so the tooltip shows today's value, not yesterday's. + type PayloadItem = { dataKey?: string; value?: number; payload: { prevPageviews?: number; prevVisitors?: number; visitors?: number; pageviews?: number } } + const items = payload as PayloadItem[] + const current = items.find((p) => p.dataKey === metric) ?? items[items.length - 1] + const value = Number(current?.value ?? (current?.payload as Record)?.[metric] ?? 0) + const prev = metric === 'visitors' ? current?.payload?.prevVisitors : current?.payload?.prevPageviews const hasPrev = showComparison && prev != null const delta = hasPrev && (prev as number) > 0