# Sparkline

> A tiny line chart for trends. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

Source: https://albakore.github.io/pyzed/library/sparkline/

:::tip[In plain words]
A tiny line chart that shows if something is going up or down.
:::

A small line chart, filled below the line by default, that shows the shape of a series.

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

**Code:**

```python
pz.column([
    ui.sparkline([1, 4, 2, 6, 3, 7, 5, 8], width=240, height=48),
    ui.sparkline([8, 6, 7, 4, 5, 3, 2, 1], width=240, height=48, tint="error", fill=False),
], spacing=16)
```

## When to use

- Inline next to a number or in a table cell, where the trend matters more than the values.

## Usage

```python
import pyzed as pz
from pyzed import ui

pz.column([
    ui.sparkline([1, 4, 2, 6, 3, 7, 5, 8], width=240, height=48),
    ui.sparkline([8, 6, 7, 4, 5, 3, 2, 1], width=240, height=48, tint="error", fill=False),
], spacing=16)
```

## Variants

:::note[About these captures]
Each capture is recorded by pyzed itself, off-screen at 2x, in One Dark or One 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.sparkline([1, 4, 2, 6, 3, 7, 5, 8], width=200, height=40)
```

```python
ui.sparkline([1, 4, 2, 6, 3, 7, 5, 8], width=200, height=40, fill=False)
```

```python
ui.sparkline([8, 6, 7, 4, 5, 3, 2, 1], width=200, height=40, tint="error")
```

```python
ui.sparkline([2, 3, 3, 5, 6, 8, 9, 12], width=200, height=40, tint="success")
```

### Size

```python
ui.sparkline([3, 5, 2, 6, 4, 7], width=80, height=20)
```

```python
ui.sparkline([3, 5, 2, 6, 4, 7, 5, 9, 6, 8], width=280, height=64)
```

## Events

Sparkline 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.sparkline`

```python
sparkline(values, *, width=120, height=32, tint='accent', fill=True, theme=None)
```

A tiny line chart for trends.

| Property | Default | Description |
| --- | --- | --- |
| `values` | *required* | Values. |
| `width` | `120` | Width: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |
| `height` | `32` | Height: pixels, `"fill"`, `"shrink"` or `"fill:N"` (proportion). |
| `tint` | `"accent"` | Semantic color: `"accent"`, `"error"`, `"warning"`, `"success"`, `"info"` or a token. |
| `fill` | `True` | Fills the area under the line. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

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

## Related

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