# Donut

> A donut chart with a label in the middle. A native Pyzed component for Python desktop GUIs, with a live preview, code examples and its API.

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

:::tip[In plain words]
A ring cut into colored slices that shows the parts of a whole.
:::

A donut chart of `values`, with a `label` in the center. `colors` overrides the theme's palette.

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

**Code:**

```python
pz.row([
    ui.donut([60, 25, 15], label="60%"),
    ui.donut([45, 35, 20], colors=["#e5c07b", "#c678dd", "#56b6c2"], size=120, thickness=20, label="3"),
], spacing=32, align="center")
```

## When to use

- To show the parts of a whole (disk usage, languages of a project) with three or four slices.

## Usage

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

pz.row([
    ui.donut([60, 25, 15], label="60%"),
    ui.donut([45, 35, 20], colors=["#e5c07b", "#c678dd", "#56b6c2"], size=120, thickness=20, label="3"),
], spacing=32, align="center")
```

## 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.donut([60, 25, 15], label="60%")
```

```python
ui.donut([45, 35, 20], colors=["#e5c07b", "#c678dd", "#56b6c2"], label="3")
```

```python
ui.donut([70, 30], thickness=6, label="70%")
```

```python
ui.donut([40, 30, 20, 10], size=140, thickness=24)
```

```python
ui.donut([82, 18], size=110, label="82%")
```

## Events

Donut 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.donut`

```python
donut(values, *, colors=None, size=96, thickness=14, label=None, theme=None)
```

A donut chart; `label` is drawn in the center.

| Property | Default | Description |
| --- | --- | --- |
| `values` | *required* | Values. |
| `colors` | `None` | Colors (defaults to the theme's). |
| `size` | `96` | Size. |
| `thickness` | `14` | Ring thickness. |
| `label` | `None` | Center text. |
| `theme` | `None` | Theme to use instead of the current one (`pyzed.theme.current()`). |

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

## Related

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