Stacked Bar Chart

Visualize multi-category data with production-ready stacked bars. Perfect for comparing composition across different groups with zero configuration required. Built for complex datasets with TypeScript-first design.

Multi-Category Support
Filled & Outline Variants
Vertical & Horizontal
Interactive Legend
Multi-Segment Tooltips
Keyboard Accessible
Performance Optimized
TypeScript

Revenue Breakdown by Product Category

Track monthly revenue split across Desktop, Mobile, and Services with interactive segments and dynamic legend

Loading...
Selected: Click a segment to select
Variant:
Orientation:

Installation

Get started with the StackedBarChart component in just a few steps.

Quick Install
bash
npx mario-charts@latest add stacked-bar-chart
Zero Lock-in Philosophy
The component is fully yours to own, modify, and customize.

Examples

Explore different configurations and use cases for comparing composition across categories.

Quarterly Sales by Region

Four-segment stacked bars showing sales distribution across North, South, East, and West regions with rich tooltips displaying all segments and totals

Loading...
Variant:
Orientation:

Marketing Channels - Modern Dashboard Style

Horizontal orientation with outline variant creates a contemporary look perfect for modern dashboards. Shows lead generation across Email, Social, Direct, and Referral channels

Loading...
Variant:
Orientation:

Product Mix by Store Location

Compare product category distribution across different store locations. Demonstrates proportion visualization for comparing composition

Loading...

Large Dataset Performance

24 bars with 4 stacked categories each (96 total segments) demonstrating smooth performance with memoization and optimized rendering

Loading...
Performance Notes:
  • • 24 bars × 4 categories = 96 segments rendered smoothly
  • • Memoized data processing prevents unnecessary recalculations
  • • ResizeObserver handles responsive updates efficiently
  • • Legend hidden for cleaner visualization with many bars
Variant:
Orientation:

Loading State

Error State

Chart Error
Failed to load revenue data

Empty State

No Data
There's no data to display

Variants & Orientations

Mix and match variants with orientations to achieve different visual styles for your dashboard.

Vertical + Filled

Classic stacked bars - solid colors, bottom-up stacking

Loading...

Vertical + Outline

Modern minimalist look with outline-only segments

Loading...

Horizontal + Filled

Left-to-right stacking with solid fills - great for rankings

Loading...

Horizontal + Outline

Contemporary dashboard style - perfect for executive views

Loading...

API Reference

Complete TypeScript interface with all available props and configurations for StackedBarChart.

PropTypeDefaultDescription
datarequired
readonly T[]Array of data objects to display in the chart. Each object should contain the x-axis key and all y-axis keys for stacking
xrequired
keyof TKey from data object to use for x-axis labels (bar labels)
yrequired
readonly (keyof T)[]Array of keys from data object to stack. Each key represents a segment in the stacked bars. Order determines stacking sequence (bottom to top for vertical, left to right for horizontal)
colors
readonly string[]DEFAULT_COLORSArray of colors for each stacked segment. Colors cycle through the array if more segments than colors
variant
'filled' | 'outline''filled'Visual style of bars - filled with solid colors or outline only for modern minimalist designs
orientation
'vertical' | 'horizontal''vertical'Direction of stacking - vertical (bottom-up) or horizontal (left-right)
showLegend
booleanfalseDisplay legend showing all stacked categories with their colors
height
number300Height of the chart in pixels
loading
booleanfalseShow loading state with animated skeleton matching the selected variant and orientation
error
string | nullnullError message to display
animation
booleantrueEnable entrance animations with staggered segment reveals
onSegmentClick
(data: T, stackKey: string, index: number) => voidCallback fired when a segment is clicked. Receives the data object, the segment key, and bar index
className
stringAdditional CSS classes to apply to the container