# Bar Chart

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/bar-chart
- **Markdown:** https://refast.fastapicloud.dev/docs/components/bar-chart.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/charts/bar_chart.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Bar charts display data using rectangular bars proportional to the values they represent.
They are ideal for comparing values across categories.

```python
from refast.components.shadcn.charts import (
    ChartContainer, BarChart, Bar,
    CartesianGrid, XAxis, ChartTooltip, ChartTooltipContent,
)

data = [
    {"month": "January",  "desktop": 186, "mobile": 80},
    {"month": "February", "desktop": 305, "mobile": 200},
    {"month": "March",    "desktop": 237, "mobile": 120},
]

ChartContainer(class_name="h-64", children=[
    BarChart(data=data, children=[
        CartesianGrid(vertical=False),
        XAxis(data_key="month", tick_line=False, axis_line=False),
        ChartTooltip(content=ChartTooltipContent()),
        Bar(data_key="desktop", label="Desktop", radius=4),
        Bar(data_key="mobile",  label="Mobile",  radius=4),
    ]),
])
```

## ChartContainer Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `config` | `dict[str, ChartConfig] \| None` | `None` | Optional override map; auto-built from series children when omitted |
| `class_name` | `str` | `""` | Container class; set height here (e.g. `"h-64"`) |
| `children` | `list` | `[]` | The chart component(s) |
| `min_height` | `int \| str \| None` | `200` | Minimum height |
| `aspect` | `float \| None` | `None` | Aspect ratio (width / height) |

## ChartConfig Fields

| Field | Type | Description |
|-------|------|-------------|
| `label` | `str` | Human-readable series label |
| `color` | `str \| None` | CSS color value (e.g. `hsl(var(--chart-1))`) |
| `icon` | `str \| None` | Lucide icon name for the legend |

## BarChart Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `data` | `list[dict]` | *(required)* | Array of data objects |
| `layout` | `"horizontal" \| "vertical"` | `"horizontal"` | Chart orientation |
| `margin` | `dict` | `{top:10, right:10, left:10, bottom:0}` | Chart margins |
| `bar_category_gap` | `str \| int \| None` | `None` | Gap between bar categories |
| `bar_gap` | `str \| int \| None` | `None` | Gap between bars in the same group |
| `max_bar_size` | `int \| None` | `None` | Maximum bar width |
| `stack_offset` | `str` | `"none"` | `"expand"`, `"none"`, `"wiggle"`, `"silhouette"` |
| `on_click` | `Callback \| None` | `None` | Click on a bar |
| `children` | `list` | `[]` | Axes, bars, tooltip, legend |

## Bar Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `data_key` | `str` | *(required)* | Key from data objects |
| `fill` | `str` | *(auto from `data_key`)* | CSS color; defaults to `var(--color-{data_key})` |
| `radius` | `int \| list[int]` | `0` | Corner radius |
| `stack_id` | `str \| None` | `None` | Bars sharing the same `stack_id` are stacked |
| `bar_size` | `int \| None` | `None` | Fixed bar width in pixels |
| `min_point_size` | `int \| None` | `None` | Minimum bar height for zero values |
| `label` | `str \| None` | `None` | Human-readable series label shown in tooltip/legend |
| `bar_label` | `bool \| dict \| None` | `None` | Show value labels on bars |
| `background` | `bool \| dict` | `False` | Show background bar |
| `hide` | `bool` | `False` | Hide this bar series |

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
