# Line chart

> Lines with axes, labels and a legend. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/line-chart/

:::tip[In plain words]
A drawing with lines that go up and down to show how numbers change.
:::

Draws one or several series of numbers as lines over the x `labels`, with a y axis of four steps. A `{name: values}` dict adds a legend; `fill` shades under each line and `points` marks each value.

`ui.line_chart` · Category: [Data](https://albakore.github.io/pyzed/library/#data) · [Full reference →](https://albakore.github.io/pyzed/reference/ui/#line_chart)

**Code:**

```python
ui.line_chart({"Visits": [12, 18, 15, 24, 30, 28, 36], "Sales": [4, 6, 5, 9, 11, 10, 14]},
              labels=["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], width=440, height=200)
```

:::note[New]
This component was added recently. Tell us how it works for you in the [issue tracker](https://github.com/albakore/pyzed/issues).
:::

## When to use

- To show how values change over time: visits, sales, temperatures.
- Inside a card or a row, a [Sparkline](https://albakore.github.io/pyzed/library/sparkline/) takes less space.

## Usage

```python
from pyzed import ui

ui.line_chart({"Visits": [12, 18, 15, 24, 30, 28, 36], "Sales": [4, 6, 5, 9, 11, 10, 14]},
              labels=["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], width=440, height=200)
```

## Variants

:::note[About these captures]
Each capture is recorded by pyzed itself, off-screen at 2x, in Pyzed Dark or Pyzed Light to match this site's theme, and cropped to the component so it shows at its real size. The pointer hovers, presses or types into it; a component that does not react to the pointer cycles through a few themes. With reduced motion you see the first frame. Open **Code** under a capture to see the snippet that draws it; free names such as `on_save` stand for your own callbacks.
:::

### Options

```python
ui.line_chart([3, 7, 4, 9, 6, 11, 8], width=360, height=160)
```

```python
ui.line_chart([3, 7, 4, 9, 6, 11, 8], labels=list("MTWTFSS"), fill=True, points=True, width=360, height=170)
```

```python
ui.line_chart({"2025": [5, 8, 6, 9, 12], "2026": [7, 9, 11, 13, 17]}, labels=["Jan", "Feb", "Mar", "Apr", "May"], width=360, height=160)
```

```python
ui.line_chart([1200, 1800, 1500, 2400, 3000], grid=False, width=360, height=150)
```

## Events

Line chart has no events of its own: it shows what you give it. Like every widget it also has the **18 common events** (`click`, `double_click`, `right_click`, `mouse_enter`, `drag`, `key_down`, `resize`…), attached with `.on(...)`: see [Events](https://albakore.github.io/pyzed/guides/events/) and [Events of every component](https://albakore.github.io/pyzed/library/events/).

## Properties and API

### `ui.line_chart`

```python
line_chart(
    series,
    *,
    labels=None,
    width=360,
    height=180,
    colors=None,
    fill=False,
    points=False,
    grid=True,
    legend=None,
    min=None,
    max=None,
    theme=None,
)
```

A line chart with axes: one list of numbers, several lists or `{name: values}` (which adds a legend). The y axis shows four steps between `min` and `max`.

| Property | Default | Description |
| --- | --- | --- |
| `series` | *required* | A list of numbers, a list of lists or a `{name: values}` dict. |
| `labels` | `None` | Labels under the x axis (thinned out when they do not fit). |
| `width` | `360` | Width: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |
| `height` | `180` | Height: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |
| `colors` | `None` | Colors of the lines (defaults to the theme's). |
| `fill` | `False` | Shades under each line. |
| `points` | `False` | Marks each value with a dot. |
| `grid` | `True` | Draws the horizontal lines. |
| `legend` | `None` | With a dict, `False` hides the names under the chart. |
| `min` | `None` | Bottom of the y axis (from the data when `None`). |
| `max` | `None` | Top of the y axis (from the data when `None`). |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

[Full reference →](https://albakore.github.io/pyzed/reference/ui/#line_chart)

## Related

- [Sparkline](https://albakore.github.io/pyzed/library/sparkline/): A tiny line chart for trends.
- [Bar chart](https://albakore.github.io/pyzed/library/bar-chart/): A vertical bar chart with labels.
- [Stat](https://albakore.github.io/pyzed/library/stat/): A dashboard number with change and sparkline.
