# Stacked bars

> The total per period, and what it is made of. Sample data: failed payments per week by reason (card declined, insufficient funds, fraud block), W27 to W40.

- Type 003 · Part of a whole
- Component: `<StackedBars>`, the same name as the Figma component
- Install: `npx shadcn add @chartory/stacked-bars` (free in Hearth: the public registry, no token; Signal with Code and Complete)
- Type page: https://usechartory.com/charts/stacked-bars

## Installation

1. **Set up the registry once.** This chart is free in Hearth and MIT licensed: no token. Add @chartory to components.json once (the URL alone, no headers), or skip this when another chart is already installed. [Installation guide](https://usechartory.com/docs/installation)

2. **Add the chart.** One command adds the Stacked bars component to your project.

```bash
npx shadcn add @chartory/stacked-bars
```

3. **Use it.** Pass your rows. The props are the Figma properties.

usage.tsx:

```tsx
import { StackedBars }
  from "@/components/chartory/stacked-bars"

<StackedBars
  data={failuresByReason}
  size="m"
  legend
/>
```

## Props

### `<StackedBars>`

Every prop but data is a Figma property with the same name and values.

| Prop | Type | Default | Note |
| --- | --- | --- | --- |
| data | StackedBarsData | Required | The chart's data. The tables below list every field. |
| size | "xs" \| "s" \| "m" \| "l" | "m" | The size class. Each one is laid out again from the data. |
| legend | boolean | true | Shows the legend row under the plot. |

### StackedBarsData

The data prop: one object for the whole chart.

| Prop | Type | Default | Note |
| --- | --- | --- | --- |
| max | number | Required | The top of the value scale. |
| ticks | string[] | Required | The axis tick labels. |
| labels | Record<number, string> | Required | The labels, by index. |
| ratio? | number | 0.2 | The gap between bars, as a share of the band. |
| stacks | StackedBarsStack[] | Required | One entry per stacked part. |

### StackedBarsStack

One object per entry in stacks.

| Prop | Type | Default | Note |
| --- | --- | --- | --- |
| name | string | Required | The name shown on the chart. |
| tok | string | Required | The colour token, e.g. "data/primary". |
| vals | number[] | Required | The values, in order. |

## Stacked bar chart: a React and Figma chart in four sizes

### What does a stacked bar chart show?

A stacked bar chart builds each bar from its parts, so you read the total and the mix in one shape. Use it for failures by reason, revenue by plan or tickets by type, period after period.

Chartory ships it as a Figma component and a React component with the same name. The code installs from the shadcn registry with one command and lands in your project as a file you own.

### What is the Stacked bars component?

It is one **<StackedBars>** component. Its props are the Figma properties with the same names and values, and the props table above lists them. The data is two to four parts per period.

Sizes **XS**, **S**, **M** and **L** re-lay the chart out from the data instead of scaling it, so labels stay readable at every size.

### When should I use it?

- **Does the total per period matter?** Yes means the stacked bars fit.
- **Are there several periods?** Yes means the stacked bars fit.
- **Are there four parts or fewer?** Yes means the stacked bars fit.

### When does another type fit better?

- **Parts compared with each other.** Use Grouped bars instead.
- **One split, one moment.** Use Donut instead.
- **Many parts in a flowing mix.** Use Streamgraph instead.

## Stacked bar questions

### Does the Stacked bars chart work with shadcn/ui?

Yes. It installs through the shadcn registry with the shadcn CLI, and the file lands in your project.

### How do I install it?

It is free in Hearth and MIT licensed: add the @chartory registry URL once, no token, then run npx shadcn add @chartory/stacked-bars. The Installation guide has the steps.

### Can my coding agent install it?

Yes. Connect the Chartory MCP server and ask for the stacked bars chart; the agent runs the same command and you review the diff.

### What data does it expect?

Two to four parts per period. The sample data comes with the component, and the props table lists every field.

### Which sizes does it ship in?

XS, S, M and L, in Figma and in code. Each size is laid out again from the data, so text and lines keep their size.

### Is it in the Figma file too?

Yes. chart/003-stacked-bars has the same properties as the component.

### Does it follow light and dark mode?

Yes. Every paint is a token, so the chart follows light and dark mode and the collection you pick.

### Which plan has the code?

None for Hearth: it is free in the public registry, no token. The Signal collection (@chartory/signal) comes with Code and Complete.
