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.

feat(mcp): migrate ActionsBarValue display to quill horizontal bar chart (#61915)

Sam Pennington37ca8ad6b28f
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index f1fd347c4d41..feeae8349370 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3840,6 +3840,10 @@ snapshots:
hash: v1.k794b7964.da67b48f277665016d143ea09d4471ca6f01f3b8a6d22e7fe0f3dc51b075e92a.l81wzNlVna0bTrWF2HHg1RkJaB7vXRpAIdMbNylhzCw
mcp-apps-trends--area-chart--light:
hash: v1.k794b7964.6ed37783ed84b48f2d648749ffc298bfd71075de834aae5d71f1a3b57dceb307.CP-Rjuy-9M_y2GO4qu462L0uVUqNr5EjDcW5v81BryE
+ mcp-apps-trends--bar-value-few-series--light:
+ hash: v1.k794b7964.bcb42d00df54e5bf9adccb454c817a56a52561ec5b481ffe9b25a8896baeae89.E3s1npkDTg03NEIlR9OhwvzSa2k1RWTAlqi-HlgnjZg
+ mcp-apps-trends--bar-value-many-breakdowns--light:
+ hash: v1.k794b7964.d421caf04ff4ffe69988ee87e3faa29b8de082074da252a8afb62ab1855648f2.qIt6erKrYbIJIHSDm1PF4wtGvohw-Dkk5BK2v5jyjAk
mcp-apps-trends--multi-series--light:
hash: v1.k794b7964.466f26e9748bf36e37c3b01368ede6314529acc9de022545d2d7732fd27b9876.UBFF_lMm5lyhQHZ67NejD1gwBIUG40R24So4yyXge2I
mcp-apps-trends--single-series--light:
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarValueChart/trendsBarValueChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsBarValueChart/trendsBarValueChartTransforms.ts
new file mode 100644
index 000000000000..40cf812216f1
--- /dev/null
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarValueChart/trendsBarValueChartTransforms.ts
@@ -0,0 +1,33 @@
+import type { BarChartConfig, Series } from '@posthog/quill-charts'
+
+// ActionsBarValue renders aggregated totals as a horizontal bar per series/breakdown — a single
+// quill series whose per-bar entries carry the color and label. Kept dependency-neutral (quill
+// only) so the MCP app can import it; the web TrendsBarChart transforms pull in frontend-only
+// modules (lib/utils, ~/queries, scenes/...) and can't be imported outside the frontend bundle.
+export interface TrendsBarValueItem {
+ label: string
+ value: number | null | undefined
+}
+
+export interface BuildTrendsBarValueSeriesOpts {
+ getColor: (index: number) => string
+}
+
+export function buildTrendsBarValueSeries(items: TrendsBarValueItem[], opts: BuildTrendsBarValueSeriesOpts): Series[] {
+ return [
+ {
+ key: 'total',
+ label: 'Total',
+ data: items.map((item) => (Number.isFinite(item.value) ? (item.value as number) : 0)),
+ bars: items.map((item, index) => ({ color: opts.getColor(index), label: item.label })),
+ },
+ ]
+}
+
+export function buildTrendsBarValueConfig(): BarChartConfig {
+ return {
+ axisOrientation: 'horizontal',
+ showGrid: true,
+ bars: { cornerRadius: 4, fitToHeight: true },
+ }
+}
diff --git a/products/product_analytics/mcp/apps/Trends.stories.tsx b/products/product_analytics/mcp/apps/Trends.stories.tsx
index 7c150accb538..c3259ae8f698 100644
--- a/products/product_analytics/mcp/apps/Trends.stories.tsx
+++ b/products/product_analytics/mcp/apps/Trends.stories.tsx
@@ -2,9 +2,14 @@ import type { Meta, StoryObj } from '@storybook/react'
import type { ReactElement } from 'react'
import { McpThemeDecorator } from '@posthog/mcp-ui/storybook/decorator'
-import { TimeSeriesLineChart } from '@posthog/quill-charts'
+import { BarChart, TimeSeriesLineChart } from '@posthog/quill-charts'
import type { ChartTheme } from '@posthog/quill-charts'
+import {
+ buildTrendsBarValueConfig,
+ buildTrendsBarValueSeries,
+ type TrendsBarValueItem,
+} from '../../frontend/insights/trends/TrendsBarValueChart/trendsBarValueChartTransforms'
import {
buildTrendsLineTimeSeriesConfig,
buildTrendsSeries,
@@ -24,7 +29,8 @@ const CHART_THEME: ChartTheme = {
tooltipColor: '#111827',
}
-const getColor = (_r: TrendsResultLike, i: number): string => CHART_COLORS[i % CHART_COLORS.length]!
+const colorAt = (i: number): string => CHART_COLORS[i % CHART_COLORS.length]!
+const getColor = (_r: TrendsResultLike, i: number): string => colorAt(i)
const DAYS = ['2025-05-26', '2025-05-27', '2025-05-28', '2025-05-29', '2025-05-30', '2025-05-31', '2025-06-01']
@@ -90,3 +96,55 @@ export const AreaChart: Story = {
),
name: 'Area chart',
}
+
+// Renders ActionsBarValue the same way the MCP app does: aggregated totals through
+// buildTrendsBarValueSeries, then quill's BarChart. Fixed pixel size for the same
+// headless-snapshot reason as the line demo above.
+function TrendsBarValueChartDemo({
+ items,
+ height = 300,
+}: {
+ items: TrendsBarValueItem[]
+ height?: number
+}): ReactElement {
+ const series = buildTrendsBarValueSeries(items, { getColor: colorAt })
+ const config = buildTrendsBarValueConfig()
+ return (
+ // eslint-disable-next-line react/forbid-dom-props
+ <div style={{ display: 'flex', flexDirection: 'column', width: 640, height }}>
+ <BarChart series={series} labels={items.map((item) => item.label)} theme={CHART_THEME} config={config} />
+ </div>
+ )
+}
+
+export const BarValueFewSeries: Story = {
+ render: () => (
+ <TrendsBarValueChartDemo
+ items={[
+ { label: 'Chrome', value: 8421 },
+ { label: 'Firefox', value: 3204 },
+ { label: 'Safari', value: 2817 },
+ ]}
+ />
+ ),
+ name: 'Bar value — few series',
+}
+
+export const BarValueManyBreakdowns: Story = {
+ render: () => (
+ <TrendsBarValueChartDemo
+ items={[
+ { label: 'United States', value: 14320 },
+ { label: 'United Kingdom', value: 6210 },
+ { label: 'Germany', value: 4890 },
+ { label: 'France', value: 3720 },
+ { label: 'Canada', value: 2940 },
+ { label: 'Australia', value: 2310 },
+ { label: 'Netherlands', value: 1870 },
+ { label: 'India', value: 1640 },
+ ]}
+ height={400}
+ />
+ ),
+ name: 'Bar value — many breakdowns',
+}
diff --git a/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx b/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx
index 93f43649bdf0..08fc31c1c3f6 100644
--- a/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx
+++ b/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx
@@ -2,15 +2,19 @@ import { type ReactElement, useState } from 'react'
import { emptyStateIllustration } from '@posthog/mcp-ui'
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia } from '@posthog/quill'
-import { TimeSeriesLineChart } from '@posthog/quill-charts'
+import { BarChart as BarValueChart, TimeSeriesLineChart } from '@posthog/quill-charts'
+import {
+ buildTrendsBarValueConfig,
+ buildTrendsBarValueSeries,
+} from 'products/product_analytics/frontend/insights/trends/TrendsBarValueChart/trendsBarValueChartTransforms'
import {
buildTrendsLineTimeSeriesConfig,
buildTrendsSeries,
} from 'products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms'
import { BarChart, BigNumber, Select, type Series } from './charts'
-import { CHART_COLORS, CHART_THEME } from './charts/theme'
+import { CHART_THEME, colorAt } from './charts/theme'
import type { TrendsResultItem, TrendsVisualizerProps } from './types'
import { formatDate, getDisplayType, getSeriesLabel, isBarChart } from './utils'
@@ -89,6 +93,27 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
return <BigNumber value={total} label={label} />
}
+ // ActionsBarValue returns aggregated_value per series (empty data[]/days[]) — render a
+ // horizontal bar of totals, not a time series, so there's no line/bar mode toggle.
+ if (displayType === 'ActionsBarValue') {
+ const items = results.map((item, i) => ({
+ label: getSeriesLabel(item, i),
+ value: item.aggregated_value,
+ }))
+ const barSeries = buildTrendsBarValueSeries(items, { getColor: colorAt })
+ const barConfig = buildTrendsBarValueConfig()
+ return (
+ <div className="flex flex-col w-full h-[400px]">
+ <BarValueChart
+ series={barSeries}
+ labels={items.map((item) => item.label)}
+ theme={CHART_THEME}
+ config={barConfig}
+ />
+ </div>
+ )
+ }
+
const lineResults = results.map((item, i) => ({
id: i,
label: getSeriesLabel(item, i),
@@ -98,7 +123,7 @@ export function TrendsVisualizer({ query, results }: TrendsVisualizerProps): Rea
const lineSeries = buildTrendsSeries(lineResults, {
isArea: displayType === 'ActionsAreaGraph',
- getColor: (_, index) => CHART_COLORS[index % CHART_COLORS.length]!,
+ getColor: (_, index) => colorAt(index),
})
const lineConfig = buildTrendsLineTimeSeriesConfig({
diff --git a/services/mcp/src/ui-apps/components/charts/theme.ts b/services/mcp/src/ui-apps/components/charts/theme.ts
index 43ab92e4a6de..21d89b63b7e4 100644
--- a/services/mcp/src/ui-apps/components/charts/theme.ts
+++ b/services/mcp/src/ui-apps/components/charts/theme.ts
@@ -12,6 +12,9 @@ export const CHART_COLORS = [
'#dc2626', // red
]
+// Picks a palette color by index, wrapping when there are more series than colors.
+export const colorAt = (index: number): string => CHART_COLORS[index % CHART_COLORS.length]!
+
// Single mid-gray for axis labels — readable on both light and dark hosts. Claude
// Desktop's iframe doesn't set `prefers-color-scheme`, so we can't detect the host
// theme and adapt at runtime.