Diverging Bar Chart for React
A React diverging bar chart centers survey answers on a neutral midpoint; the butterfly variant draws a population pyramid. Pass data as readonly ChartRow[]: one row per item (a question, a product, an age group).
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/diverging-bar-chart.jsonCustomer survey
DivergingBarChartDivergingBarTabledivergingLegenddivergingLevelsdefaultDivergingBarChartLabels- +3 more
Likert survey
Six statements, 460 answers each. Shares sit inside the segments where they fit (black or white ink, whichever reads better), and the net score follows each row. Switch the quarter and the segments morph. Up and down move between statements, left and right between answers.
Customer survey
Q4, 460 answers per statement
- Strongly disagree
- Disagree
- Neutral
- Agree
- Strongly agree
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { DivergingBarChart } from "@/components/sheenui/charts/diverging-bar-chart";
import { divergingLegend, type DivergingLevel } from "@/components/sheenui/charts/diverging-bar-chart/model";
import { DivergingBarTable } from "@/components/sheenui/charts/diverging-bar-chart/table";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, divergingLegend, DivergingBarTable, DivergingBarChart, type DivergingLevel } from "@sheenui/theme";
const levels: DivergingLevel[] = [
{ key: "sd", label: "Strongly disagree" },
{ key: "d", label: "Disagree" },
{ key: "n", label: "Neutral" },
{ key: "a", label: "Agree" },
{ key: "sa", label: "Strongly agree" },
];
const data = [
{ statement: "The product is easy to learn", sd: 12, d: 30, n: 64, a: 214, sa: 160 },
{ statement: "It saves me time every week", sd: 9, d: 24, n: 51, a: 222, sa: 174 },
{ statement: "Support answers quickly", sd: 22, d: 48, n: 90, a: 196, sa: 124 },
];
export function Example() {
return (
<ChartCard
title="Customer survey"
legend={divergingLegend(levels)}
table={<DivergingBarTable data={data} index="statement" levels={levels} indexLabel="Statement" caption="Survey answers" />}
>
<DivergingBarChart data={data} index="statement" levels={levels} aria-label="Survey answers, from strongly disagree to strongly agree" />
</ChartCard>
);
}Population pyramid
variant="butterfly" with two levels: men to the left, women to the right of the spine, the age groups in the middle. One scale for both sides, so the halves compare honestly.
Population by age
Mid-year estimate, millions
- Men
- Women
import { DivergingBarChart } from "@/components/sheenui/charts/diverging-bar-chart";
// Package build (after the first npm release, or a packed tarball): import { DivergingBarChart } from "@sheenui/theme";
const population = [
{ age: "60+", men: 3_400_000, women: 4_100_000 },
{ age: "40–59", men: 4_900_000, women: 5_000_000 },
{ age: "20–39", men: 5_200_000, women: 5_100_000 },
{ age: "0–19", men: 4_300_000, women: 4_100_000 },
];
export function Example() {
return (
<DivergingBarChart
variant="butterfly"
data={population}
index="age"
levels={[
{ key: "men", label: "Men" },
{ key: "women", label: "Women" },
]}
aria-label="Population by age group and sex"
/>
);
}Files to copy
15 folders · 30 files · 4 packages
- From
theme/src/ components/charts/{diverging-bar-chart.tsx, histogram.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-pointer.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}components/charts/chart-parts/components/charts/diverging-bar-chart/components/charts/heatmap/components/charts/histogram/components/charts/kits/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-direction.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.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/diverging-bar-chart.jsonRegistry item: diverging-bar-chart. 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
DivergingBarChartLabels keys and English defaults (10)
DivergingBarTable props
Keyboard
Accessibility
- The figure takes focus as one stop and is named by its aria-label, the chart title. A one-line hint explains the keys, and a ChartCard table view is linked through aria-details. Values are announced politely, once per move. Shares are printed as text and every Likert row has a net score, so color never carries the reading; each move announces the row and segment.
- DivergingBarTable is the table view: pair it with ChartCard's table prop (Chart / Table tabs) so every value can be read without color or sight.
- Reduced motion: the bars appear at their final lengths on either side of zero and data changes jump instead of morphing.
All exports on this page
DivergingBarChart— Bars that diverge from a midpoint.DivergingBarTable— Every row's count and share per level (plus the net score of a Likert row).defaultDivergingBarChartLabels— The built-in English strings of DivergingBarChart; spread it into your own labels and change what you need.divergingLegend— Legend items for a diverging chart, in level order (or the two sides of a butterfly).divergingLevels— Each level's side and colour: equal steps per arm, strongest at the extremes, a grey neutral.
When to use the diverging bar chart
- Use the likert variant as a Likert scale chart for survey results, such as strongly disagree through strongly agree per question, with each row summing to 100 percent and a net score after it.
- Use the butterfly variant for a population pyramid or an A/B comparison, drawing two groups back to back from a central spine on one shared scale with row names down the middle.
- Use it for sentiment by product feature or NPS-style breakdowns, where positive and negative answers should pull to opposite sides of a neutral midpoint.
- Skip it when the categories are not ordered or have no meaningful midpoint, because a Bar chart or Percent bar chart fits unordered parts of a whole better.
- Pair it with ChartCard and DivergingBarTable for a text view, ChartLegend to explain the answer levels, and a Select to switch the survey wave.
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 .