Skip to content

100% Stacked Bar Chart for React

A React 100% stacked bar chart that scales every bar to 100%, so you can compare the mix inside each category whatever its size. Pass data as readonly ChartRow[]: one object per bar: the index key plus one number per series key (shares are worked out for you).

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/percent-bar-chart.json

Plan mix by region

  • Free
  • Pro
  • Team
Use arrow keys to move between bars and their segments.

  • PercentBarChart
  • PercentBarTable
  • percentShares
  • defaultPercentBarChartLabels
  • +2 more

Horizontal, with shares

showValues prints a share inside a segment only when it fits with room to spare, on a surface chip that passes contrast on any color. Up/Down move between regions, Left/Right between segments.

Plan mix by region

Customers on each plan

  • Free
  • Pro
  • Team

Files to copy

11 folders · 25 files · 4 packages
From theme/src/
  • components/charts/{percent-bar-chart.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-utils.ts}
  • components/charts/chart-parts/
  • components/drawer/parts/sheet.tsx
  • components/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}
  • motion/tokens.ts
  • lib/{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/percent-bar-chart.jsonRegistry item: percent-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".

Vertical columns

layout="vertical". Left/Right move between quarters, Up/Down climb the stack.

Sessions by device

  • Desktop
  • Mobile
  • Tablet

Zero rows and long names

A category whose values add up to 0 gets an empty track instead of a misleading bar; long names truncate (the full name is in the tooltip and the table).

Time spent by team

  • Building
  • Meetings
  • Support

PercentBarChart props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneOne object per bar: the index key plus one number per series key (shares are worked out for you).
index (required)stringNoneSets the key of the category in each row.
series (required)readonly ChartSeries[]NoneSegments, from the baseline outwards. Give each a fixed color slot.
layout"horizontal" | "vertical""horizontal""horizontal" = bars from the left (best for long names); "vertical" = columns.
showValuesbooleanfalsePrint each share inside its segment, only where it fits with room to spare.
heightnumber40px a rowPlot height. Horizontal bars default to 40px a row.
format((n: number) => string)formatCompactFormats raw values (tooltip, table). Negative values count as 0.
formatPercent((n: number) => string)defaultFormatPercentFormats shares, 0–100 (axis, labels, tooltip).
emptyStateReactNodeNoneShown when there is nothing to plot.
patternsbooleantrue when series.length > 3Tell series apart without colour (hatch fills).
labelsPartial<PercentBarChartLabels>defaultPercentBarChartLabelsEvery other string, for translation: labels={{ total: "…" }}; omitted keys keep the English of defaultPercentBarChartLabels. All 4 keys of PercentBarChartLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the chart for assistive tech (required).
classNamestringNoneAdds extra classes to the outer element.
PercentBarChartLabels keys and English defaults (4)
Pass any key in labels; the rest keep the defaults of defaultPercentBarChartLabels.
KeyEnglish default
totalTotal
noDataNo data
instructionsUse arrow keys to move between bars and their segments.
touchHintTap a bar to read its shares.

PercentBarTable props

PropTypeDefaultDescription
data (required)readonly ChartRow[]NoneTakes the same rows as the chart.
index (required)stringNoneKey of each row that names its bar.
series (required)readonly ChartSeries[]NoneTakes the same series as the chart.
format((n: number) => string)formatCompactFormats a value for the data table cells: takes the number, returns the text shown.
formatPercent((n: number) => string)defaultFormatPercentFormats a share of the total for the data table cells: takes the share, returns the text shown.
indexLabelstringNoneSets the header of the first column.
captionstringNoneSets a visually hidden caption that names the table.
showTotalbooleantrueShow a Total column (default true).
labelsPartial<Pick<PercentBarChartLabels, "total" | "noData">>defaultPercentBarChartLabelsOverride the "Total" column header and the empty text. Every other string, for translation: labels={{ total: "…" }}; omitted keys keep the English of defaultPercentBarChartLabels. All 2 keys of PercentBarChartLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer element.

Keyboard

KeysAction
TabFocus the chart. It is one tab stop; the arrow keys then read it.
←/→Vertical layout: previous / next bar. Horizontal layout: previous / next segment of the bar.
↑/↓Vertical layout: previous / next segment of the bar. Horizontal layout: previous / next bar.
Home/EndJump to the first / last bar.
EscapeStep out of a segment to the whole bar; press again to clear the reading.

Accessibility

  • Keyboard and screen-reader users get a single focusable figure labelled by the chart title, with a short reading hint as its description; inside a ChartCard with a table view, aria-details links it to the table. Every value read is announced politely, once. Each move announces the segment's value and its share.
  • For a non-visual reading, give ChartCard's table prop a PercentBarTable; the Chart / Table tabs then expose each value as plain table cells.
  • With reduced motion on, the segments start at their final shares and a data change jumps straight to the new state.

All exports on this page

  • PercentBarChart — Bars that all add up to 100%, so each bar shows the mix rather than the size.
  • PercentBarTable — The table view of a part-to-whole chart (PercentBarChart, or StackedAreaChart in percent mode).
  • defaultPercentBarChartLabels — The built-in English strings of PercentBarChart; spread it into your own labels and change what you need.
  • percentShares — Shares (0–100) of each series in each row.

When to use the 100% stacked bar chart

  • Use it as a percentage bar chart for a plan mix by region, where Free, Pro and Team customers are counted in very different volumes and you care about each region's proportions rather than its size.
  • It suits time-spent breakdowns by team, such as building, meetings and support, where every row must be read as a share of 100% and long team names truncate inside a horizontal layout.
  • Choose layout vertical for a quarterly device mix, where columns line up like a time series and the arrow keys climb each stack, with showValues printing a share only where a segment has room.
  • Skip it when the absolute totals matter as much as the split; a regular BarChart keeps the size of each category visible, and Marimekko chart shows both width and share together.
  • Pair it with ChartCard for the title, legend and Chart / Table tabs, seriesLegend for the swatches, and PercentBarTable so every share can be read as text without relying on color.

Frequently asked questions

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .