Join our Discord community
Bar chart

Stacked Bar Chart

Stacked bar chart component with legend and rounded corners. Built for React applications requiring cumulative data visualization with Next.js and TypeScript.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/bar-chart-05.json
npx shadcn@latest add https://www.shadcn.io/registry/bar-chart-05.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/bar-chart-05.json
bunx shadcn@latest add https://www.shadcn.io/registry/bar-chart-05.json

Features

  • Stacked visualization combining desktop and mobile data into single bars
  • Interactive legend providing clear identification of data series
  • Custom radius styling with different corner radius for top and bottom segments
  • Stack grouping using shared stackId for proper data stacking
  • TypeScript support with complete type definitions for stacked charts
  • shadcn/ui integration using Chart components with legend styling

Use Cases

This free open source React component works well for:

  • Total visualization - Applications showing cumulative data across categories built with Next.js
  • Part-to-whole analysis - Understanding composition of total values using TypeScript and Tailwind CSS
  • Budget breakdowns - Financial data showing component contributions to totals
  • Resource allocation - Visualizing how resources are distributed across different areas

API Reference

ChartBarStacked

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the card container

Stacked Configuration

Two Bar components with shared stackId for stacking:

<Bar
  dataKey="desktop"
  stackId="a"
  fill="var(--color-desktop)"
  radius={[0, 0, 4, 4]}
/>
<Bar
  dataKey="mobile"
  stackId="a"
  fill="var(--color-mobile)"
  radius={[4, 4, 0, 0]}
/>

Legend Integration

Built-in legend component for series identification:

<ChartLegend content={<ChartLegendContent />} />

Radius Styling

  • Bottom segment (desktop): [0, 0, 4, 4] - rounded bottom corners
  • Top segment (mobile): [4, 4, 0, 0] - rounded top corners

Implementation Notes

  • Shared stackId "a" ensures data stacking rather than side-by-side display
  • Bottom segment gets bottom corner radius, top segment gets top corner radius
  • Legend automatically generates based on chartConfig labels and colors
  • Tooltip hides labels focusing on individual segment values
  • Creates cohesive stacked bars showing total and component values
  • Perfect for applications requiring cumulative data visualization with clear component identification