Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(insights): key trend chart x-axes by ISO days, not display labels (#80673)

Thomas Obermülleraa76057864ad
diff --git a/frontend/src/test/insight-testing/test-data.ts b/frontend/src/test/insight-testing/test-data.ts
index 332c43fa307d..f420c01ef4ec 100644
--- a/frontend/src/test/insight-testing/test-data.ts
+++ b/frontend/src/test/insight-testing/test-data.ts
@@ -131,6 +131,14 @@ export const trendsSeries = {
days,
labels,
} satisfies CannedSeries,
+ // Week display labels omit the year, so a multi-year weekly range returns the same label
+ // string for buckets in different years — the shape that folds a chart keyed by labels.
+ weeklyAcrossYears: {
+ label: 'WeeklyAcrossYears',
+ data: [10, 20, 30, 40, 50, 60],
+ days: ['2020-06-01', '2020-06-08', '2020-06-15', '2026-06-01', '2026-06-08', '2026-06-15'],
+ labels: ['1–7 Jun', '8–14 Jun', '15–21 Jun', '1–7 Jun', '8–14 Jun', '15–21 Jun'],
+ } satisfies CannedSeries,
noActivity: {
label: 'NoActivity',
data: [0, 0, 0, 0, 0],
@@ -176,6 +184,7 @@ const seriesByEvent: Record<string, EventSeriesConfig> = {
ZeroCounts: { default: trendsSeries.withZeroCounts[0], multi: trendsSeries.withZeroCounts },
Minimal: { default: trendsSeries.minimal },
NoActivity: { default: trendsSeries.noActivity },
+ WeeklyAcrossYears: { default: trendsSeries.weeklyAcrossYears },
}
/** Resolver for compare queries — returns current + previous period series. */
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.md
index 34fc2c9518d5..9f8b58d0e2ef 100644
--- a/packages/quill/packages/charts/AGENTS.md
+++ b/packages/quill/packages/charts/AGENTS.md
@@ -45,6 +45,7 @@ const series: Series[] = [
```
- `key` (React key + stacking identity), `label` (legend/tooltip), `data` are required.
+- `labels` entries must be **unique** — the x-scale keys positions off the strings, so a duplicate collapses onto the first occurrence's position and draws the series backwards. On time-series charts pass ISO date strings (never formatted display labels like "1–7 Jun", which repeat across years) and format ticks via `xAxis.timezone`/`interval` or `tickFormatter`.
- Line-only options: `points`, `stroke.pattern` (dashes/projections), `fill.opacity` / `fill.gradient` (area), `fill.lowerData` (ribbon).
- Bar-only options: `bars` (per-bar `color`/`label`/`meta` overrides, plus `hatch: true` to fill that bar with a diagonal-hatch pattern in its resolved color — flags individual not-final bars, e.g. buckets still being ingested, at arbitrary indices; for a contiguous trailing range `stroke.partial.fromIndex` does the same); `trackData` caps each bar's interactive extent at a per-bar ceiling in value units — the region beyond `trackData[i]` is a fully inert gap: no hover, tooltip, pointer cursor, highlight, or click (the chart vetoes the hover there via `resolveHoverIndex`). On grouped charts with `bars.track` the hatched "share of a whole" track also fills only to the ceiling; on stacked charts no track is drawn — the ceiling only bounds interactivity. Funnel compare uses it to draw a shorter period's volume gap as empty space rather than drop-off, in both its grouped (left-to-right) and stacked (top-to-bottom) charts.
- `BarChartConfig.bars.minBarSize` (px) floors each non-zero bar's thickness along the value axis so a single-occurrence bucket stays visible beside a spike three orders of magnitude taller (the old chart.js `minBarLength`) — zero-valued bars are never floored, so empty buckets stay empty. On a stacked chart only the outermost segment is floored — flooring an interior one would oversize a rect the segment above overpaints while still capturing its hover and clicks — so a breakdown stack floors only its top segment, and the option is aimed at single-series volume charts and grouped bars; `Sparkline` doesn't expose the prop. `TimeSeriesBarChart` takes `minBarSize`, `bandPadding`, and `margins` as top-level config keys (alongside `barCornerRadius`/`fillStyle`) rather than under `bars`.
diff --git a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
index 604cd6a8bf19..5e272c5de96d 100644
--- a/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
+++ b/packages/quill/packages/charts/src/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
@@ -63,6 +63,10 @@ export interface TimeSeriesLineChartConfig {
export interface TimeSeriesLineChartProps<Meta = unknown> {
series: Series<Meta>[]
+ /** One x value per data index, unique across the array (use ISO date strings, not formatted
+ * display labels). The x-scale keys positions off these strings, so a repeated value
+ * collapses onto the first occurrence's position and draws the series backwards. Display
+ * formatting belongs in `xAxis.timezone`/`interval` (auto tick formatter) or `tickFormatter`. */
labels: string[]
theme: ChartTheme
config?: TimeSeriesLineChartConfig
diff --git a/packages/quill/packages/charts/src/core/scales.ts b/packages/quill/packages/charts/src/core/scales.ts
index e80e9e173308..3f9c3b5fba01 100644
--- a/packages/quill/packages/charts/src/core/scales.ts
+++ b/packages/quill/packages/charts/src/core/scales.ts
@@ -119,6 +119,9 @@ export function niceLogDomain(minPositive: number, max: number): [number, number
return [niceMin, niceMax]
}
+/** Point scale keyed by label string. d3 ordinal domains keep only the first occurrence of a
+ * value, so duplicate labels collapse onto one position and a series drawn through them runs
+ * backwards. Callers must pass unique labels (ISO dates for time series, not display text). */
export function createXScale(labels: string[], dimensions: ChartDimensions): ScalePoint<string> {
return scalePoint<string>()
.domain(labels)
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx
index feca8f7ce56c..d8420597ca37 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx
@@ -163,7 +163,11 @@ export function FunnelLineChart({
)
const resolvedGroupTypeLabel = resolveGroupTypeLabel(labelGroupType, aggregationLabel)
- const labels = steps[0]?.labels ?? EMPTY_STRINGS
+ // The chart keys x positions off these strings, so they must be unique per point. Display
+ // labels are not (week and hour labels omit the year), which draws a multi-year funnel
+ // trend backwards. Use the ISO days; ticks and tooltips format from them.
+ const days = steps[0]?.days
+ const labels = (days?.length ? days : steps[0]?.labels) ?? EMPTY_STRINGS
const annotationDates = steps[0]?.days ?? EMPTY_STRINGS
const showAnnotations = !inSharedMode && funnelsFilter?.showAnnotations !== false
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
index 9b943f81bb6e..a7c905a4f2cb 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
@@ -174,9 +174,14 @@ export function TrendsBarChart({
buildMeta: buildTrendsSeriesMeta,
showMultipleYAxes: applyMultipleYAxes,
})
+ // Bands are keyed by these strings, so they must be unique per point. Display labels
+ // are not (week and hour labels omit the year), which folds a multi-year range's bars
+ // onto each other. Use the ISO days; ticks and tooltips format from them. Stickiness
+ // x values are interval counts rather than dates, so it keeps its labels.
+ const days = currentPeriodResult?.days
return {
series: timeSeries,
- labels: currentPeriodResult?.labels ?? EMPTY_LABELS,
+ labels: (!isStickiness && days?.length ? days : currentPeriodResult?.labels) ?? EMPTY_LABELS,
displayLabels: undefined,
}
}, [
@@ -184,6 +189,8 @@ export function TrendsBarChart({
indexedResults,
getTrendsColor,
getTrendsHidden,
+ isStickiness,
+ currentPeriodResult?.days,
currentPeriodResult?.labels,
stackBreakdowns,
getAggregatedDisplayLabel,
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx
index 1713435239d7..6cc233fb32ed 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx
@@ -110,7 +110,12 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLi
buildLifecycleChartModel<IndexedTrendResult, TrendsSeriesMeta>(indexedResults ?? [], {
getColor: (status) => getBarColorFromStatus((status ?? 'new') as LifecycleToggle),
buildMeta: buildTrendsSeriesMeta,
- labels: currentPeriodResult?.labels ?? EMPTY_LABELS,
+ // Bands are keyed by these strings, so they must be unique per point. Display
+ // labels are not (week and hour labels omit the year, so multi-year ranges
+ // repeat them); use the ISO days, which ticks and tooltips format from.
+ labels: currentPeriodResult?.days?.length
+ ? currentPeriodResult.days
+ : (currentPeriodResult?.labels ?? EMPTY_LABELS),
isStacked,
trendsFilter,
baseCurrency,
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
index 161717ffab79..96cce060ff76 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx
@@ -843,6 +843,42 @@ describe('TrendsLineChart', () => {
})
})
+ describe('multi-year weekly x-axis', () => {
+ // Week display labels omit the year ("1–7 Jun"), so a multi-year range repeats them.
+ // The chart keys x positions off its labels prop and collapses a repeated key onto the
+ // first occurrence's x, which draws the series backwards — so the components must key
+ // the axis by the unique ISO days instead. Covers the bar path too, where a repeated
+ // key collapses whole bands.
+ it.each([
+ ['line', undefined],
+ ['bar', ChartDisplayType.ActionsBar],
+ ])(
+ 'renders %s points at strictly increasing x when display labels repeat across years',
+ async (_displayName, display) => {
+ renderInsight({
+ query: buildTrendsQuery({
+ interval: 'week',
+ series: [{ kind: NodeKind.EventsNode, event: 'WeeklyAcrossYears', name: 'WeeklyAcrossYears' }],
+ trendsFilter: { showValuesOnSeries: true, ...(display ? { display } : {}) },
+ }),
+ })
+
+ await waitFor(() => {
+ expect(getHogChart().valueLabels()).toHaveLength(6)
+ })
+ const leftByText = new Map(
+ Array.from(document.querySelectorAll<HTMLElement>('[data-attr="hog-chart-value-label"]')).map(
+ (el) => [el.textContent, parseFloat(el.style.left)]
+ )
+ )
+ const lefts = ['10', '20', '30', '40', '50', '60'].map((text) => leftByText.get(text)!)
+ for (let i = 1; i < lefts.length; i++) {
+ expect(lefts[i]).toBeGreaterThan(lefts[i - 1])
+ }
+ }
+ )
+ })
+
describe('drag-to-zoom', () => {
const totalLabels = trendsSeries.pageviews.labels.length
const zoomFlag = { [FEATURE_FLAGS.INSIGHT_DRAG_TO_ZOOM]: true }
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
index 57dbd384e405..70713f3b5263 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx
@@ -103,7 +103,14 @@ export function TrendsLineChart({
const isPercentStackView = !!showPercentStackView && !!supportsPercentStackView
const resolvedGroupTypeLabel = context?.groupTypeLabel ?? resolveGroupTypeLabel(labelGroupType, aggregationLabel)
- const labels = currentPeriodResult?.labels ?? []
+ // The chart keys x positions off these strings, so they must be unique per point. The
+ // backend's display labels are not: week and hour labels omit the year, so a multi-year
+ // range repeats them and every repeated point snaps back to the first occurrence's x,
+ // drawing the line backwards. Pass the ISO days instead; the interval-aware tick and
+ // tooltip formatters already render display text from them. Stickiness x values are
+ // interval counts rather than dates, so it keeps its (already unique) labels.
+ const days = currentPeriodResult?.days
+ const labels = (!isStickiness && days?.length ? days : currentPeriodResult?.labels) ?? []
const hasData = hasTrendsChartData(indexedResults)
diff --git a/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsx
index 2c561b139730..37ab757dc77c 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsSlopeChart/TrendsSlopeChart.tsx
@@ -37,7 +37,9 @@ export function TrendsSlopeChart({ context }: TrendsSlopeChartProps): JSX.Elemen
// matching labels, so we just map to quill series: resolve the theme colour, drop legend-hidden
// series, and forward the backend's `incomplete_end` flag (which dashes the connector). A
// single-bucket range comes back as one point and is dropped — there's no slope to draw.
- const labels = currentPeriodResult?.labels ?? []
+ // Key the endpoints by ISO days rather than display labels: week and hour labels omit the
+ // year, so on a multi-year range both endpoints can share a label and collapse onto one x.
+ const labels = (currentPeriodResult?.days?.length ? currentPeriodResult.days : currentPeriodResult?.labels) ?? []
const series = useMemo<Series<SlopeSeriesMeta>[]>(() => {
return (indexedResults ?? [])
.filter((result: IndexedTrendResult) => !getTrendsHidden(result) && (result.data?.length ?? 0) >= 2)