# Donut

> Parts-of-a-whole traffic-source split with a centered total.

- Group: Charts
- HTML page: https://design.ipmnx.com/charts/donut/
- Spec: https://design.ipmnx.com/design/#charts

## Usage

Load tokens.css, kit.css and behavior/charts.js (after behavior/util.js), then draw into an empty element. The chart is an inline SVG that re-themes with data-theme, dir and data-nx-product.

```js
NXCharts.renderDonut(el, dataset, a11y);
NXCharts.tableForDonut(el, dataset, a11y.tableSummary);
```

## Dataset

```json
{
  "labels": [
    "Direct",
    "Search",
    "Social",
    "Email"
  ],
  "series": [
    {
      "name": "Traffic",
      "colors": [
        "--nx-chart-1",
        "--nx-chart-2",
        "--nx-chart-3",
        "--nx-chart-4"
      ],
      "values": [
        40,
        25,
        20,
        15
      ]
    }
  ]
}
```

## Classes

| Class | Description |
| --- | --- |
| `.nx-legend` | Series key, column layout in the showcase |

## Accessibility

- Accessible name (role="img" with aria-label): Traffic mix, donut chart, 4 sources
- Data table summary (visually hidden table for screen readers): Traffic mix: Direct 40%, Search 25%, Social 20%, Email 15%.

## Do / Don't

- Do: Fold anything past ~5-6 slices into an "Other" category.
- Don't use a donut for 2 categories. A simple stat pair reads faster.

---

Source: registry.js (NX Design System)
