Skip to content

NbPieChart shows the relative size of a small set of categories that sum to a meaningful whole. For more than ~6 segments, prefer NbBarChart, pies become hard to read with too many slices.

vue
<template>
  <NbPieChart title="Traffic source" :data="data" />
</template>

<script setup lang="ts">
const data = [
  { label: 'Organic', value: 48 },
  { label: 'Referral', value: 22 },
  { label: 'Paid', value: 18 },
  { label: 'Direct', value: 12 },
]
</script>

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.

vue
<template>
  <NbPieChart :data="data" :inner-radius="0.55" />
</template>

Label modes ​

Choose between percentage (default), absolute value, or no labels.

Custom colors per slice ​

Supply a color on individual data items to override the palette per slice, useful for status palettes.

vue
<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 ​

PropTypeDefaultDescription
dataICategoricalDatum[][]Slice values and labels
titlestring-Chart title
subtitlestring-Secondary descriptive line
heightnumber | string280Container height
innerRadiusnumber0Ring radius ratio (0 to 1) for donut mode
labels'none' | 'percent' | 'value''percent'Label rendering style on each slice
showLegendbooleantrueRender a legend below the chart
showTooltipbooleantrueShow hover tooltip
colorsstring[]default palettePer-slice colors (overridden by per-datum color)

Events ​

EventPayloadDescription
selectIChartCategoricalSelectionA slice was clicked, or activated by key
vue
<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 ​

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