Donut mode
Set inner-radius to a value between 0 and 1 to render a donut. The slice labels move into the ring instead of being centred.
<template>
<NbPieChart :data="data" :inner-radius="0.55" />
</template>Custom colors per slice
Supply a color on individual data items to override the palette per slice, useful for status palettes.
<template>
<NbPieChart :data="data" />
</template>
<script setup lang="ts">
const data = [
{ label: 'Passing', value: 142, color: 'var(--nb-c-success)' },
{ label: 'Warning', value: 23, color: 'var(--nb-c-warning)' },
{ label: 'Failing', value: 6, color: 'var(--nb-c-danger)' },
]
</script>Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | ICategoricalDatum[] | [] | Slice values and labels |
title | string | - | Chart title |
subtitle | string | - | Secondary descriptive line |
height | number | string | 280 | Container height |
innerRadius | number | 0 | Ring radius ratio (0 to 1) for donut mode |
labels | 'none' | 'percent' | 'value' | 'percent' | Label rendering style on each slice |
showLegend | boolean | true | Render a legend below the chart |
showTooltip | boolean | true | Show hover tooltip |
colors | string[] | default palette | Per-slice colors (overridden by per-datum color) |
animate | boolean | false | Sweep the slices in on first render and on data change |
Entrance animation
animate sweeps the slices in clockwise from twelve o'clock, on a pie and on a donut, when the chart first renders and again when its data changes. It is off by default and is switched off entirely under prefers-reduced-motion: reduce.
<NbPieChart animate :inner-radius="0.6" :data="data" />Events
| Event | Payload | Description |
|---|---|---|
select | IChartCategoricalSelection | A slice was clicked, or activated by key |
<template>
<NbPieChart :data="data" @select="onSelect" />
</template>
<script setup lang="ts">
import type { IChartCategoricalSelection } from '@nubisco/ui'
const onSelect = (selection: IChartCategoricalSelection) => {
// { kind: 'categorical', label, value, index, datum }
console.log(selection.label, selection.value)
}
</script>Interactivity is opt-in and works the same way it does on the bar chart: with no @select listener the chart is a picture, and with one each slice becomes a focusable button, activated with Enter or Space.
Data shape
interface ICategoricalDatum {
label: string
value: number
color?: string
}Notes
- Negative
values are clamped to zero, pie charts can only render non-negative slices. - Slice ordering follows the array order, starting at the 12-o'clock position and progressing clockwise.