# Pie chart

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

Part-to-whole at a glance: up to six slices, each a categorical slot, separated by a 2px gap in the surface.

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

## Five slices

Always ship the legend with values: a pie without numbers asks the reader to estimate angles.

Vue (vue-ecosphere):

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

React (react-ecosphere):

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

## Three slices

Use it only when the question is “roughly how is this split” and the parts differ enough to see.

Vue (vue-ecosphere):

```vue
<EcoPieChart :data="three" :size="200" title="Three parts of a whole" />
```

React (react-ecosphere):

```tsx
<EcoPieChart data={three} size={200} title="Three parts of a whole" />
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `ChartSlice[]` | — | Label and value per slice. Past six, the tail is grouped into “Other”. |
| `size` | `number` | 220 | viewBox size; the radius is half of it less 6. |
| `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 in the label and legend. |
| `title / subtitle / caption / ariaLabel` | `string` | — | Head and the svg label; every slice's figure is appended to the label. |
| `emptyTitle / emptyText` | `string` | — | chart__empty when nothing has a value. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `ChartSlice[]` | — | Label and value per slice. Past six, the tail is grouped into “Other”. |
| `size` | `number` | 220 | viewBox size; the radius is half of it less 6. |
| `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 in the label and legend. |
| `title / subtitle / caption / ariaLabel` | `string` | — | Head and the svg label; every slice's figure is appended to the label. |
| `emptyTitle / emptyText` | `string` | — | chart__empty when nothing has a value. |
