# Funnel Chart

> React funnel chart with horizontal or vertical stages, conversion and drop-off between stages, an optional comparison outline and bars that spring to new data.

- Kind: Component (Charts)
- Docs: https://ui.minidev.pro/docs/funnel-chart
- Source (registry JSON with the full file): https://ui.minidev.pro/r/funnel-chart.json
- License: MIT. One file, yours to edit after install.

## When to use

Use for signup and checkout funnels. Pass `stages` for one series, or `datasets` to add a segmented switch between them. Screen readers get a full data table. For a compact list of bars use [`FunnelSteps`](https://ui.minidev.pro/docs/funnel-steps); for flows that branch use [`SankeyChart`](https://ui.minidev.pro/docs/sankey-chart).

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/funnel-chart
```

Writes `components/ui/funnel-chart.tsx` plus the MiniDev files it is built from (segmented-control) and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/funnel-chart.json`.

### npm package

```bash
npm i minidev-ui-kit motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { FunnelChart } from "@/components/ui/funnel-chart"
```

From the npm package:

```tsx
import { FunnelChart } from "minidev-ui-kit/ui/funnel-chart"
```

## Usage

```tsx
import { FunnelChart } from "@/components/ui/funnel-chart"

export function Example() {
  return (
    <FunnelChart />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `stages` | `FunnelStage[]` | - | no | Stages from the top of the funnel down. |
| `datasets` | `FunnelDataset[]` | `DATASETS` | no | Datasets to switch between with a segmented control. Ignored when `stages` is set. |
| `orientation` | `"horizontal" \| "vertical" \| "auto"` | `"auto"` | no | "auto" is horizontal when the container is at least 480px wide, vertical below that. |
| `title` | `string` | `"Visitors to paid"` | no | Chart title; also the figure's accessible name. |
| `compareLabel` | `string` | `"Last month"` | no | Legend text for the comparison series. |
| `format` | `(value: number) => string` | `defaultFormat` | no | Formats values in the bars and the table. |
| `showCompare` | `boolean` | `true` | no | Draw the comparison outline when stages carry `compare`. |
| `className` | `string` | - | no |  |

## Examples

### Fixed stages

Pass stages for a single funnel; the segmented control disappears and showCompare false hides the comparison legend.

```tsx
const checkout: FunnelStage[] = [
  { label: "Viewed cart", value: 9240 },
  { label: "Started checkout", value: 5110 },
  { label: "Entered card", value: 3380 },
  { label: "Paid", value: 2975 },
]

<FunnelChart stages={checkout} title="Checkout, this week" showCompare={false} />
```

### Vertical with comparison

orientation vertical lists stages as rows, compare values draw the dashed outline, and format keeps full numbers instead of compact ones.

```tsx
const onboarding: FunnelStage[] = [
  { label: "Invited", value: 1840, compare: 1620 },
  { label: "Accepted", value: 1312, compare: 1104 },
  { label: "Bank linked", value: 804, compare: 640 },
  { label: "First invoice", value: 561, compare: 402 },
]

<FunnelChart
  stages={onboarding}
  orientation="vertical"
  title="Team onboarding"
  compareLabel="September"
  format={(n) => n.toLocaleString("en-US")}
  className="max-w-md"
/>
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` | Moves focus to the dataset switch, when `datasets` has more than one entry and `stages` is not set. |
| `ArrowLeft` or `ArrowRight` | In the dataset switch, selects the previous or next dataset. |

## Accessibility

- The chart is a `<figure>` labelled by its title. All bars and labels are `aria-hidden`.
- A visually hidden `<table>` lists each stage's value, step conversion and drop-off, the comparison column when present, and an overall conversion row.
- Bars spring to new sizes when the data changes; under reduced motion they jump to the new size.

## FAQ

### How are conversion and drop-off calculated?

Between each pair of stages, step conversion is `value / previous value` and drop-off is `previous value - value`. The large figure in the header is overall conversion: the last stage divided by the first. Rates under 10% show one decimal.

### How do I compare against last month?

Give each stage a `compare` value and set `compareLabel`. Each bar then gets a dashed outline at the comparison size, the header adds the comparison's overall rate, and the hidden table gets a column for it. Turn it off with `showCompare={false}`.

### Why does the legend say "All" when I pass my own stages?

The legend names the main series after the selected dataset, and the default `datasets` start on "All". When you pass `stages` with `compare`, pass `datasets={[{ label: "This month", stages }]}` instead, so the legend reads your label.

### Does it switch to vertical on mobile?

With the default `orientation="auto"`, yes: a `ResizeObserver` lays the stages out as rows when the chart's box is under 480px wide, and as columns above that. Pass `"horizontal"` or `"vertical"` to fix the layout.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `motion`
- Built from: [segmented-control](https://ui.minidev.pro/docs/segmented-control/md)

## Related

- [Funnel Steps](https://ui.minidev.pro/docs/funnel-steps/md): A conversion funnel drawn as labeled horizontal bars scaled to the largest step, with formatted counts per stage. Suited to signup and checkout analytics.
- [Sankey Chart](https://ui.minidev.pro/docs/sankey-chart/md): React SVG sankey diagram: node columns laid out from the links, gradient ribbons, a node's flows lit on hover or focus, and a hidden data table.
- [Area Chart](https://ui.minidev.pro/docs/area-chart/md): Dependency free SVG area chart for React with a smoothed line, dashed grid, gradient fill and an optional highlighted point. Strokes stay crisp at any size.
- [Bar Chart](https://ui.minidev.pro/docs/bar-chart/md): Lightweight React bar chart with rounded bars, dashed gridlines and labels. Hovering a bar dims the rest and shows its value; the peak is highlighted first.
- [Chart Card](https://ui.minidev.pro/docs/chart-card/md): Card wrapper for charts with a title, optional description and a minimum height body. Pairs with the area, bar and donut charts in a React dashboard.
- [Chart Legend](https://ui.minidev.pro/docs/chart-legend/md): Wrapping chart legend with small color swatches and labels. Pass colors per series or fall back to accent, success, warning and danger theme tokens.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
