Chord Diagram for React
A React chord diagram draws flows between a handful of groups as ribbons across a circle. Pass groups plus a square matrix: matrix[i][j] is the flow from group i to group j.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/chord-diagram.jsonPlan changes, quarter on quarter
ChordDiagramChordTablechordLegenddefaultChordTableLabelsdefaultChordDiagramLabels- +3 more
Plan changes, quarter on quarter
Accounts that moved between plans. Hover a plan to light up its ribbons; hover a ribbon to read both directions. Switch the quarter: every arc and ribbon tweens to its new angle. With the keyboard, left and right go around the plans, down steps through a plan's ribbons.
Plan changes
Accounts that changed plan in Q3
- Free
- Starter
- Pro
- Team
- Enterprise
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChordDiagram } from "@/components/sheenui/charts/chord-diagram";
import { type ChordGroup } from "@/components/sheenui/charts/chord-diagram/model";
import { ChordTable } from "@/components/sheenui/charts/chord-diagram/parts";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, ChordTable, ChordDiagram, type ChordGroup } from "@sheenui/theme";
const groups: ChordGroup[] = [
{ id: "free", label: "Free", color: 7 },
{ id: "starter", label: "Starter", color: 3 },
{ id: "pro", label: "Pro", color: 1 },
{ id: "team", label: "Team", color: 5 },
{ id: "enterprise", label: "Enterprise", color: 2 },
];
// matrix[from][to]: accounts that moved from one plan to another.
const matrix = [
[0, 640, 410, 120, 16],
[230, 0, 540, 190, 26],
[130, 270, 0, 460, 95],
[35, 80, 210, 0, 210],
[4, 12, 45, 130, 0],
];
<ChartCard
title="Plan changes"
table={<ChordTable groups={groups} matrix={matrix} caption="Moves between plans" />}
>
<ChordDiagram groups={groups} matrix={matrix} aria-label="Accounts moving between plans this quarter" />
</ChartCard>Code review across teams, names in the legend
showLabels={false} leaves the names to the ChartCard legend (chordLegend), so the circle gets all the room. With the default showLabels, names that would not fit around the ring (a phone, a crowded side) move into a legend under the circle by themselves.
Who reviews whom
Pull request reviews, last 90 days
- Web
- Mobile
- Platform
- Data
- Design system
- Infrastructure
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { ChordDiagram } from "@/components/sheenui/charts/chord-diagram";
import { chordLegend, type ChordGroup } from "@/components/sheenui/charts/chord-diagram/model";
import { ChordTable } from "@/components/sheenui/charts/chord-diagram/parts";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, chordLegend, ChordTable, ChordDiagram, type ChordGroup } from "@sheenui/theme";
const teams: ChordGroup[] = [
{ id: "web", label: "Web", color: 1 },
{ id: "mobile", label: "Mobile", color: 2 },
{ id: "platform", label: "Platform", color: 3 },
{ id: "data", label: "Data", color: 4 },
{ id: "design", label: "Design system", color: 5 },
{ id: "infra", label: "Infrastructure", color: 7 },
];
// reviews[i][j]: pull requests team i reviewed from team j
const reviews = [
[0, 46, 38, 12, 64, 9],
[41, 0, 22, 8, 37, 6],
[29, 18, 0, 44, 11, 57],
[9, 6, 39, 0, 4, 31],
[58, 33, 7, 3, 0, 2],
[5, 4, 49, 27, 1, 0],
];
export function Example() {
return (
<ChartCard
title="Who reviews whom"
legend={chordLegend(teams)}
table={<ChordTable groups={teams} matrix={reviews} caption="Reviews between teams" />}
>
<ChordDiagram
groups={teams}
matrix={reviews}
showLabels={false}
height={320}
aria-label="Pull request reviews between six teams, last 90 days"
/>
</ChartCard>
);
}Files to copy
13 folders · 29 files · 4 packages
- From
theme/src/ components/charts/{chord-diagram.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-tip.tsx, chart-utils.ts, flow-utils.tsx, heatmap.tsx}components/charts/chart-parts/components/charts/chord-diagram/components/charts/heatmap/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts, use-resolved-scheme.ts}motion/tokens.tslib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/chord-diagram.jsonRegistry item: chord-diagram. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Props
ChordDiagramLabels keys and English defaults (10)
ChordTable props
ChordTableLabels keys and English defaults (3)
Keyboard
Accessibility
- The diagram is one focusable figure with the role description “chord diagram”; keys never scroll the page while it has focus.
- A group is announced with its outflow, inflow and share (“Pro: 1,185 out, 1,235 in, 30% of all flow. 5 ribbons”); a ribbon reads both directions.
- Names that don't fit around the ring move into a legend under it by themselves; the Table view (ChordTable) is the full matrix.
- On the light theme, crowded diagrams (more than 5 groups) blend ribbons normally at a lower opacity, so crossings stay clean and readable.
- Reduced motion: the ring and ribbons appear at once and data changes jump.
All exports on this page
ChordDiagram— Flows between a handful of groups (≤ 8) as ribbons across a circle: who hands work to whom, plan upgrades and downgrades, trade between regions.ChordTable— The flow matrix as a table: one row per source group, one column per target, plus row totals.chordLegend— Legend items for a chord diagram (pass to ChartCard's legend, useful when names don't fit outside the ring).defaultChordDiagramLabels— The built-in English strings of ChordDiagram; spread it into your own labels and change what you need.defaultChordTableLabels— English defaults of ChordTableLabels.
When to use the chord diagram
- Use it as a chord chart for flows between a handful of groups that go both ways: who hands tickets to whom across support tiers, plan upgrades and downgrades, or trade between regions.
- Use it to show migration between segments, such as customers moving among free, pro and enterprise plans, where each ribbon's width at an end is the flow leaving that group.
- Make groups clickable with onGroupClick, which receives the id, label, outflow and inflow, so a click can open a drill-down for that team or region.
- Skip it when flows run one way from sources to targets or you have more than eight groups, because a Sankey chart handles directed stages and the Chord folds the extras into Other.
- Pair it with ChartCard and ChordTable, which gives the whole flow matrix as text, and with a Select to switch the period the matrix covers.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .