Revenue flowFree
Which sources feed which products?
npx shadcn@latest add https://beautifulcharts.dev/r/revenue-flow.jsonEngine: ·
Every option in the CustomizerUsage
A complete client module. Install the item first, then paste it into your app.
"use client";
import { RevenueFlowBlock } from "@/components/beautiful-charts/blocks/instrument/revenue-flow";
import type { SankeyData } from "@/components/beautiful-charts/core/sankey";
// Your rows, in this shape. A missing value is null and stays a gap; the stats and copy recompute.
const data: SankeyData = {
nodes: [{ id: "organic", label: "Organic" }, { id: "partners", label: "Partners" }, { id: "sales", label: "Sales-led" }, { id: "revenue", label: "Revenue" }, { id: "core", label: "Core plan" }, { id: "addons", label: "Add-ons" }, { id: "enterprise", label: "Enterprise" }],
links: [{ source: "organic", target: "revenue", value: 420 }, { source: "partners", target: "revenue", value: 180 }, { source: "sales", target: "revenue", value: 510 }, { source: "revenue", target: "core", value: 460 }, { source: "revenue", target: "addons", value: 150 }, { source: "revenue", target: "enterprise", value: 500 }],
};
export function Dashboard() {
return <RevenueFlowBlock data={data} />;
}
Props
data
SankeyData
Your rows. Missing values are
nulland stay gaps; with no rows every stat shows a dash. Leave it out to see the sample.stats
ChartStat[] | false
The stat row: computed from the data by default; pass your own, or false to hide it. A row of figures under the title, for dashboard cards and blocks.
footer
ReactNode | false
The line at the bottom: pass your own, or false to hide it. A line or action at the bottom of the card, e.g. a source note or a link.
| Prop | Type | Description |
|---|---|---|
| data | SankeyData | Your rows. Missing values are null and stay gaps; with no rows every stat shows a dash. Leave it out to see the sample. |
| stats | ChartStat[] | false | The stat row: computed from the data by default; pass your own, or false to hide it. A row of figures under the title, for dashboard cards and blocks. |
| footer | ReactNode | false | The line at the bottom: pass your own, or false to hide it. A line or action at the bottom of the card, e.g. a source note or a link. |
Every sankey chart prop works too, so you can restyle it without touching the source.
Sourcecomponents/beautiful-charts/blocks/instrument/revenue-flow.tsx
Show the source (27 lines)
"use client";
import { SankeyChart, type SankeyChartProps } from "../../themes/instrument/recharts/sankey-chart";
import type { SankeyData } from "../../core/sankey";
import { formatWith, pct, pickStats, ratio, type BlockOptions } from "../block";
/** Sample: acquisition channels feed one revenue hub, which splits into the products it paid for ($k). */
export const flowSample: SankeyData = {
nodes: [{ id: "organic", label: "Organic" }, { id: "partners", label: "Partners" }, { id: "sales", label: "Sales-led" }, { id: "revenue", label: "Revenue" }, { id: "core", label: "Core plan" }, { id: "addons", label: "Add-ons" }, { id: "enterprise", label: "Enterprise" }],
links: [{ source: "organic", target: "revenue", value: 420 }, { source: "partners", target: "revenue", value: 180 }, { source: "sales", target: "revenue", value: 510 }, { source: "revenue", target: "core", value: 460 }, { source: "revenue", target: "addons", value: 150 }, { source: "revenue", target: "enterprise", value: 500 }],
};
/** "Which sources feed which products?" Everything passes through one hub, so both sides read as shares of it. */
const thousands = (v: number) => `$${v}k`;
export function RevenueFlowBlock({ data = flowSample, stats, footer, ...chart }: Omit<BlockOptions<never>, "data"> & { data?: SankeyData | undefined } & Partial<SankeyChartProps>) {
const into = data.links.filter((l) => l.target === "revenue" && Number.isFinite(Number(l.value)) && Number(l.value) > 0);
const total = into.length ? into.reduce((a, l) => a + Number(l.value), 0) : null;
const top = [...into].sort((a, b) => Number(b.value) - Number(a.value))[0];
const fmt = formatWith(chart.valueFormatter, thousands);
return (
<SankeyChart data={data} eyebrow="Revenue · Q3" title="From channel to product" valueFormatter={chart.valueFormatter ?? thousands}
stats={pickStats(stats, [{ label: "Revenue", value: fmt(total) }, { label: "Top channel", value: data.nodes.find((n) => n.id === top?.source)?.label ?? "—", note: top ? pct(ratio(Number(top.value), total)) : undefined }])}
footer={footer === false ? undefined : footer} {...chart} />
);
}
Details
Props every chart shares (27): data, config, header, states, legend, tooltip, formatting, motion and selection
locale
string
BCP 47 locale. Defaults to "en-US" so server and client render the same text.
timeZone
string
IANA time zone for dates. Defaults to "UTC" so server and client agree.
eyebrow
ReactNode
Small label above the title.
title
ReactNode
Card title. A string also names the chart for screen readers.
description
ReactNode
A line under the title.
takeaway
ReactNode | ((summary: string) => ReactNode) | false
The sentence under the title. Computed from the data by default; pass text, a function of the computed sentence, or false to hide it.
ariaDescription
string
Accessible summary for screen readers. Computed from the data by default.
motion
MotionPreference
"full" (default), "subtle" or "off". Reduced-motion settings always win.
motionOptions
MotionOptions
When the entrance plays.
sound
boolean
Sound cues on hover, scrub and select. Plays only if the visitor has also turned sound on for the page.
density
Density
"comfortable" (default) or "compact" for dashboards.
tooltip
TooltipOptions<TDatum> | false
Tooltip position, indicator, cursor and custom content, or false to turn it off.
valueFormatter
(value: number) => string
Values formatted for display. Series formatters in config win.
loading
boolean
Show the loading state. Over existing data, the old marks stay dimmed instead of vanishing.
error
string | null
An error message. Shows the error state in place of the plot.
emptyState
ReactNode
Shown instead of the plot when there is no data.
loadingState
ReactNode
Shown while
loadingis true and there is no data yet.errorState
ReactNode
Shown when
erroris set.selected
number | null
Controlled and uncontrolled interaction state. Point selection (
selected) pins one row by its index indata. Series selection (selectedSeries) picks one series and dims the others. They are separate: picking a row doesn't pick a series.defaultSelected
number | null
Initial selected row when uncontrolled.
activeIndex
number | null
Controlled hover or focus index, for syncing several charts on one cursor.
palette
"theme" | "shadcn"
Series colours: "theme" (default) uses the theme's designed palette; "shadcn" uses your --chart-1..5. --bc-series-N always wins. You can also opt a whole section in with the class bc-use-shadcn-colors.
table
boolean
Show the "Show data table" disclosure. On by default.
stats
ChartStat[]
A row of figures under the title, for dashboard cards and blocks.
footer
ReactNode
A line or action at the bottom of the card, e.g. a source note or a link.
className
string
Classes on the card, for spacing and layout.
height
number
Height of the plot area in px. The frame sizes around it.
| Prop | Type | Description |
|---|---|---|
| locale | string | BCP 47 locale. Defaults to "en-US" so server and client render the same text. |
| timeZone | string | IANA time zone for dates. Defaults to "UTC" so server and client agree. |
| eyebrow | ReactNode | Small label above the title. |
| title | ReactNode | Card title. A string also names the chart for screen readers. |
| description | ReactNode | A line under the title. |
| takeaway | ReactNode | ((summary: string) => ReactNode) | false | The sentence under the title. Computed from the data by default; pass text, a function of the computed sentence, or false to hide it. |
| ariaDescription | string | Accessible summary for screen readers. Computed from the data by default. |
| motion | MotionPreference | "full" (default), "subtle" or "off". Reduced-motion settings always win. |
| motionOptions | MotionOptions | When the entrance plays. |
| sound | boolean | Sound cues on hover, scrub and select. Plays only if the visitor has also turned sound on for the page. |
| density | Density | "comfortable" (default) or "compact" for dashboards. |
| tooltip | TooltipOptions<TDatum> | false | Tooltip position, indicator, cursor and custom content, or false to turn it off. |
| valueFormatter | (value: number) => string | Values formatted for display. Series formatters in config win. |
| loading | boolean | Show the loading state. Over existing data, the old marks stay dimmed instead of vanishing. |
| error | string | null | An error message. Shows the error state in place of the plot. |
| emptyState | ReactNode | Shown instead of the plot when there is no data. |
| loadingState | ReactNode | Shown while loading is true and there is no data yet. |
| errorState | ReactNode | Shown when error is set. |
| selected | number | null | Controlled and uncontrolled interaction state. Point selection (selected) pins one row by its index in data. Series selection (selectedSeries) picks one series and dims the others. They are separate: picking a row doesn't pick a series. |
| defaultSelected | number | null | Initial selected row when uncontrolled. |
| activeIndex | number | null | Controlled hover or focus index, for syncing several charts on one cursor. |
| palette | "theme" | "shadcn" | Series colours: "theme" (default) uses the theme's designed palette; "shadcn" uses your --chart-1..5. --bc-series-N always wins. You can also opt a whole section in with the class bc-use-shadcn-colors. |
| table | boolean | Show the "Show data table" disclosure. On by default. |
| stats | ChartStat[] | A row of figures under the title, for dashboard cards and blocks. |
| footer | ReactNode | A line or action at the bottom of the card, e.g. a source note or a link. |
| className | string | Classes on the card, for spacing and layout. |
| height | number | Height of the plot area in px. The frame sizes around it. |
Events (3)
onSelectedChange
(selection: SankeySelection | null) => void
Called when a node is selected or cleared. The selection carries the node and every link on its traced path.
onActiveChange
(index: number | null) => void
Called as the hovered or focused row changes, or null when it leaves.
onReady
(chart: EChartsType) => void
ECharts build only. Called once with the ECharts instance, e.g. to add event listeners.
| Prop | Type | Description |
|---|---|---|
| onSelectedChange | (selection: SankeySelection | null) => void | Called when a node is selected or cleared. The selection carries the node and every link on its traced path. |
| onActiveChange | (index: number | null) => void | Called as the hovered or focused row changes, or null when it leaves. |
| onReady | (chart: EChartsType) => void | ECharts build only. Called once with the ECharts instance, e.g. to add event listeners. |
Apache ECharts build only (2)
renderer
EChartsRenderer
"canvas" (default) or "svg".
option
OptionOverride
Deep-merged over the generated option, or
(generated) => option. Links are custom series "links" (one item per link), nodes "nodes" (id = node id).
| Prop | Type | Description |
|---|---|---|
| renderer | EChartsRenderer | "canvas" (default) or "svg". |
| option | OptionOverride | Deep-merged over the generated option, or (generated) => option. Links are custom series "links" (one item per link), nodes "nodes" (id = node id). |
- Pointer
- Hover a node or link to highlight its whole path and show the flow; click pins it.
- Keyboard
- Tab lands once on the plot. Left and Right move between points (the first press goes to the latest), Up and Down change series, Home and End jump to the ends, Enter or Space pins, Escape clears.
- Screen readers
- Every move is announced as a sentence, not coordinates. "Show data table" opens the numbers as a real table, and missing values stay empty, never zero.
- Motion
- Bars grow from the baseline, staggered in data order, then the labels fade in. The headline number rolls in. With reduced motion everything appears settled at once, and nothing depends on the motion to be read.