Stacked Bar Chart

Stacked Bar Chart

Charts
Data Visualization

Visualize composition and breakdown across categories over time with stacked horizontal bars.

Preview

Traffic by device type with stacked segments

  • Desktop
  • Mobile
  • Tablet
Jan
90
Feb
105
Mar
106
Apr
124
May
125
Jun
146

Percentage Mode

100% stacked bars showing proportional distribution

  • Desktop
  • Mobile
  • Tablet
Jan
Feb
Mar
Apr
May
Jun

Props

Component API reference

PropTypeDefaultDescription
data*Record<string, unknown>[]—Array of data objects with category values
categories*string[]—Keys for stacked categories
labelKey*string—Key for row labels
colorsstring[]—Fill classes per category, e.g. 'bg-info-default text-info-foreground'
mode'stacked' | 'percent''stacked'Chart display mode
barHeightnumber40Height of each bar in pixels
showTotalbooleantrueShow total value on right
showLegendbooleantrueShow color legend

Usage

Import and implementation examples

import { StackedBarChart } from '@/components/ui/stacked-bar-chart'
const data = [
{ month: 'Jan', desktop: 45, mobile: 30, tablet: 15 },
{ month: 'Feb', desktop: 52, mobile: 35, tablet: 18 },
{ month: 'Mar', desktop: 48, mobile: 38, tablet: 20 },
]
<StackedBarChart
data={data}
categories={['desktop', 'mobile', 'tablet']}
labelKey="month"
/>
// 100% mode shows each share inside its segment
<StackedBarChart data={data} categories={['desktop', 'mobile', 'tablet']} labelKey="month" mode="percent" showTotal={false} />

Features

Built-in functionality

  • Multiple modes: Stacked, grouped, and percent modes
  • Interactive legend: Toggle series visibility
  • Segment gaps: Optional spacing between segments
  • Hover states: Highlight segments on hover
  • Tooltips: Show values on hover

Accessibility

Accessibility considerations

ARIA Attributes

Uses role="img" for chart containeraria-label describes chart contentSegments have title attributes

Keyboard Navigation

KeyAction
N/AChart is not keyboard interactive

Notes

  • Legend provides text labels for colors
  • Values shown in tooltips and totals
  • Consider data table for complex data