# Donut chart

Source: https://ecosphere.dev/docs/charts/donut-chart (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A pie with its middle given back: the same part-to-whole reading, plus room for the total the slices add up to.

`import { EcoDonutChart } from "vue-ecosphere"`

## Donut with a total

The centre figure takes --font-num like every other number, and it is never a decoration.

Vue (vue-ecosphere):

```vue
<EcoDonutChart
  :data="[
    { label: 'Replied', value: 38 },
    { label: 'Awaiting review', value: 24 },
    { label: 'Closed', value: 19 },
    { label: 'Blocked', value: 12 },
    { label: 'Draft', value: 7 },
  ]"
  center-label="Requests"
  title="Requests by outcome"
  subtitle="August"
/>
```

React (react-ecosphere):

```tsx
<EcoDonutChart
  data={[
    { label: "Replied", value: 38 },
    { label: "Awaiting review", value: 24 },
    { label: "Closed", value: 19 },
    { label: "Blocked", value: 12 },
    { label: "Draft", value: 7 },
  ]}
  centerLabel="Requests"
  title="Requests by outcome"
  subtitle="August"
/>
```

## One ratio

Pick the donut over a meter when the remainder matters as much as the used part; the remainder takes s-rest.

Vue (vue-ecosphere):

```vue
<EcoDonutChart
  :data="[{ label: 'Used', value: 360 }, { label: 'Remaining', value: 140, slot: 'rest' }]"
  total="72%"
  center-label="of 500"
  legend-value="value"
  :size="200"
  title="Plan usage"
  subtitle="Resets on the 1st"
/>
```

React (react-ecosphere):

```tsx
<EcoDonutChart
  data={[{ label: "Used", value: 360 }, { label: "Remaining", value: 140, slot: "rest" }]}
  total="72%"
  centerLabel="of 500"
  legendValue="value"
  size={200}
  title="Plan usage"
  subtitle="Resets on the 1st"
/>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `ChartSlice[]` | — | Label, value and optional slot per slice (six at most). |
| `total` | `string \| number` | the sum | The figure in the hole (donut__n): the total, or the one ratio the ring is about. |
| `centerLabel` | `string` | — | The small caps line under it (donut__l). |
| `size` | `number` | 220 | viewBox size. |
| `sort` | `boolean` | true | Largest first, clockwise from twelve o'clock. |
| `legendValue` | `"percent" \| "value"` | "percent" | The number beside each legend label. |
| `valueFormat` | `(v: number) => string` | — | Formats values and the default total. |
| `title / subtitle / caption / ariaLabel` | `string` | — | Head and the svg label. |
| `emptyTitle / emptyText` | `string` | — | chart__empty when nothing has a value. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `ChartSlice[]` | — | Label, value and optional slot per slice (six at most). |
| `total` | `string \| number` | the sum | The figure in the hole (donut__n): the total, or the one ratio the ring is about. |
| `centerLabel` | `string` | — | The small caps line under it (donut__l). |
| `size` | `number` | 220 | viewBox size. |
| `sort` | `boolean` | true | Largest first, clockwise from twelve o'clock. |
| `legendValue` | `"percent" \| "value"` | "percent" | The number beside each legend label. |
| `valueFormat` | `(v: number) => string` | — | Formats values and the default total. |
| `title / subtitle / caption / ariaLabel` | `string` | — | Head and the svg label. |
| `emptyTitle / emptyText` | `string` | — | chart__empty when nothing has a value. |
