# Line Chart

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/line-chart
- **Markdown:** https://refast.fastapicloud.dev/docs/components/line-chart.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/charts/line_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

Line charts visualise trends over time or ordered categories by connecting data points
with a continuous line.

```python
from refast.components.shadcn.charts import (
    ChartContainer, LineChart, Line,
    CartesianGrid, XAxis, YAxis,
    ChartTooltip, ChartTooltipContent,
    ChartLegend, ChartLegendContent,
)

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=[
    LineChart(data=data, children=[
        CartesianGrid(vertical=False),
        XAxis(data_key="month", tick_line=False, axis_line=False),
        YAxis(tick_line=False, axis_line=False),
        ChartTooltip(content=ChartTooltipContent()),
        ChartLegend(content=ChartLegendContent()),
        Line(data_key="desktop", label="Desktop", type="monotone"),
        Line(data_key="mobile",  label="Mobile",  type="monotone"),
    ]),
])
```

## LineChart 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 |
| `sync_id` | `str \| None` | `None` | Sync multiple charts by the same ID |
| `on_click` | `Callback \| None` | `None` | Click on the chart area |
| `children` | `list` | `[]` | Axes, lines, tooltip, legend |

## Line Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `data_key` | `str` | *(required)* | Key from data objects |
| `type` | `str` | `"natural"` | Interpolation: `"linear"`, `"monotone"`, `"step"`, `"natural"`, `"basis"` |
| `stroke` | `str` | *(auto from `data_key`)* | Line color; defaults to `var(--color-{data_key})` |
| `stroke_width` | `int` | `2` | Line thickness in pixels |
| `dot` | `bool \| dict` | `True` | Show data-point dots; pass a dict for custom dot styling |
| `active_dot` | `bool \| dict` | `True` | Dot shown on hover |
| `connect_nulls` | `bool` | `False` | Draw a line through `null` values |
| `stroke_dasharray` | `str \| None` | `None` | SVG dash pattern e.g. `"5 5"` for dashed lines |
| `label` | `str \| None` | `None` | Human-readable series label shown in tooltip/legend |
| `line_label` | `bool \| dict \| None` | `None` | Show value labels at each data point |
| `hide` | `bool` | `False` | Hide this line series |

## XAxis / YAxis Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `data_key` | `str \| None` | `None` | Key for axis values |
| `tick_line` | `bool` | `True` | Show tick mark lines |
| `axis_line` | `bool` | `True` | Show the axis baseline |

## CartesianGrid Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `stroke_dasharray` | `str` | `"3 3"` | SVG dash pattern for grid lines |
| `horizontal` | `bool` | `True` | Show horizontal grid lines |
| `vertical` | `bool` | `True` | Show vertical grid lines |

---

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).
