Data

Stacked bar chart.

Compare category totals and proportions using the same original values.

LIVE PREVIEWTry it. It works.

Install the source

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/stacked-bar-chart.json

Registry setup · Examples · API and behavior · Open the playground

COMPLETE EXAMPLES

Use it in context.

Each example includes its imports, data and state. The preview runs that same source. Include the stylesheet once in your application.

Absolute and percentage stacks

Use the same source values to compare totals or proportions, with stable series colours.

Keyboard

  • Series buttons retain focus while the chart updates.
  • View data exposes the complete values and visible totals.

States covered

  • absolute totals
  • percent view
  • series visibility
  • missing values

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-chart-stacked-periods.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useState} from 'react';
import {Button,StackedBarChart} from '@bld8/ui';
export default function Periods(){const [percent,setPercent]=useState(false);return <section><Button variant="secondary" aria-pressed={percent} onClick={()=>setPercent(previous=>!previous)}>Percentage view</Button><StackedBarChart label="Review work by month" mode={percent?'percent':'absolute'} series={[{id:'complete',label:'Complete'},{id:'pending',label:'Pending'}]} data={[{id:'sep',label:'September',values:{complete:24,pending:8}},{id:'oct',label:'October',values:{complete:36,pending:12}},{id:'nov',label:'November',values:{complete:40,pending:null}}]}/></section>;}

Quick reference

React / TypeScript
<StackedBarChart label="Work by month" data={data} series={series} mode="absolute" />

In the workspace or ZIP starter, import components from @bld8/ui and include @bld8/ui/styles.css once. Registry installations use your local bld8/ source path. Wrap overlays in UIProvider.

API & behaviour

Up to 100 rows and six series, with finite non-negative values or explicit nulls. Absolute and percentage modes share a stable palette and keyboard-operable legend. Exact source values and visible totals remain available in a table. Missing values remain distinguishable from zero.

StackedBarChart

StackedBarChart public properties
PropTypeDefault
dataRequiredreadonly StackedDatum[]—
labelRequiredstring—
seriesRequiredreadonly StackedSeries[]—
classNamestring | undefined—
descriptionstring | undefined—
formatIntl.NumberFormatOptions | undefined—
localestring | undefined—
mode"absolute" | "percent" | undefined'absolute'

StackedDatum

StackedDatum public properties
PropTypeDefault
idRequiredstring—
labelRequiredstring—
valuesRequiredReadonly<Record<string, number | null>>—

StackedSeries

StackedSeries public properties
PropTypeDefault
idRequiredstring—
labelRequiredstring—

Tables come from the public TypeScript declarations. Related types and function parameters are shown alongside their component. A dash means no default is declared at the public function boundary.

Related controls

Notes to self

Test this component with real content, keyboard input and both themes. The example is a starting point; labels, error handling and behaviour still need to fit the application.