Skip to contentKino
Skip to Content

Donut and pie chart

Shares of a whole as a ring, or with no hole as a pie chart. The slice under the pointer stays bright while the rest step back and its value rolls into the centre, and new data moves every slice by its angles from where it is.

npx shadcn add https://kinoui.com/r/donut-chart.json
Share on

Examples

Storage

What the Kino team keeps, of the 100 GB in its plan.
CategoryUsedShare
Notes7.1 GB14.9%
Photos21.7 GB45.7%
Voice memos4.2 GB8.8%
Attachments12.9 GB27.2%
Other1.6 GB3.4%
Total47.5 GB100%

New data

Each slice moves by its angles to the new month, from wherever it is. The slice under the pointer stays bright while the rest step back, and its value rolls into the centre.

Notes by team

Who wrote in Kino this week.
CategoryNotesShare
Design4839.7%
Engineering3629.8%
Sales2218.2%
Support1512.4%
Total121100%

Pie chart

With innerRadius={0} the ring closes into a pie. Labels with position='inside' sit on their slices, in white or black, whichever reads on the colour, and sliceGap={0} closes the gaps.

Sign-ups by source

Where new Kino writers came from in November.
CategorySign-upsShare
Search41243.2%
Referrals23624.7%
Social14815.5%
Direct9710.2%
Newsletter616.4%
Total954100%

Labels

DonutChartLabels writes each slice’s value, share or name past the ring, on a short line. A label with no room is skipped.

Your week

Hours by project. Press one to keep it in view.
CategoryHoursShare
Autumn launch4653.2%
User research2124.3%
Support12.514.5%
Hiring78.1%
Total86.5100%

Selected

With selected, a press or the menu picks a slice, which stays bright and keeps its value in the centre. With grow, it grows out of the ring too.

Seats, year on year

This year outside, last year inside.
CategoryThis yearShare
Free1,28454.9%
Plus61226.2%
Team34814.9%
Enterprise964.1%
Total2,340100%

Rings

Each DonutChartRing adds a ring inside for another value of the same slices, such as last year’s. The tooltip gives every ring’s value.

Writers by device

Where Kino was opened this month.
CategoryWritersShare
Mac3.2k34.8%
Windows2.2k24.5%
iPhone2k21.4%
Android1.1k12.3%
Web6407%
Total9.1k100%

Patterns

patterns lays a fine pattern over each slice after the first, so slices differ by more than colour, in grey and in print too.

Writers

By region, this month.
CategoryWritersShare
Europe4.1k43.8%
Americas3.4k35.9%
Asia Pacific1.9k20.3%
Total9.4k100%

Notes

By region, this month.
CategoryNotesShare
Europe61.4k48.1%
Americas38.9k30.5%
Asia Pacific27.3k21.4%
Total127.6k100%

Synced

Charts in a ChartGroup share the slice under the pointer by its key, so pointing at a region on one lights it on the other.

Installation

npx shadcn@latest add https://kinoui.com/r/donut-chart.json
Files
lib/number-format.tslib/reduce-motion.tslib/resize.tslib/roll.tsxlib/refs.tslib/swap.tsxlib/run-progress.tscomponents/kino/animated-number.tsxlib/scroll.tslib/popup.tslib/glide.tsxcomponents/kino/tooltip.tsxlib/cut.tsxlib/announce.tsxcomponents/kino/spinner.tsxcomponents/kino/button.tsxlib/chart-math.tslib/controllable.tslib/chart-core.tsxlib/highlight.tscomponents/kino/chart.tsxlib/placeholder.tscomponents/kino/donut-chart.tsx
Packages
@base-ui/reactclass-variance-authorityd3-array

New to Kino? Installation covers what your project needs first and the @kino namespace.

The CLI keeps any of these colours your project already has, such as the chart colours shadcn init writes. To use Kino’s, set them in your global CSS:

globals.css
:root {  --chart-1: oklch(0.62 0.16 250);  --chart-2: oklch(0.54 0.18 257);  --chart-3: oklch(0.47 0.21 263);  --chart-4: oklch(0.4 0.19 268);  --chart-5: oklch(0.33 0.15 272);}.dark {  --chart-1: oklch(0.82 0.09 245);  --chart-2: oklch(0.74 0.13 250);  --chart-3: oklch(0.67 0.17 257);  --chart-4: oklch(0.61 0.19 263);  --chart-5: oklch(0.55 0.2 268);}

API reference

DonutChart

PropTypeDefaultDescription
dataChartDatum[]NoneOne row per slice: its key under index, and its value under dataKey. A missing or negative value takes no room.
indexstringNoneThe key of each row’s slice, which is its key in the config.
configChartConfigNoneEach slice by its key: its label, color (or theme for light and dark) and pattern. shadcn’s pie chart config works as it is.
labelstringNoneWhat the chart shows, for screen readers, such as “Visitors by month”.
descriptionstringNoneA longer account for screen readers, such as the trend.
formatIntl.NumberFormatOptions(value: number) => stringNoneHow values are written in the tooltip, the centre and the table.
categoryFormat(value: unknown) => stringNoneHow a slice is named; its config’s label by default.
localeIntl.LocalesArgumentNoneThe locale numbers are written in. Give one, so the server and the browser agree.
patternsbooleanfalseA pattern over each slice after the first.
hiddenSeriesstring[]NoneThe slices hidden, by key, with defaultHiddenSeries and onHiddenSeriesChange. The legend hides and shows them.
activeIndexnumber | nullNoneThe slice under the pointer or the focus, by its place among those shown, with defaultActiveIndex and onActiveIndexChange.
selectedstring | nullNoneThe slice picked, by its key, with defaultSelected and onSelectedChange. Giving any of them lets a press pick one.
loadingbooleanfalseShows a placeholder; the marks grow out of it when the data arrives.
errorReactNodeNonetrue for the chart’s own words, or what to say.
onRetry() => voidNoneAdds a Try again button beside the error.
emptyReactNodeNoneWhat shows when data is empty.
messagesPartial<ChartMessages>NoneEvery word the chart says or reads out, for another language.
dataKeystringNoneThe key of each slice’s value in the data.
valueLabelstring'Total'What the values are, such as “Visitors”: the centre’s caption under the total, and the data table’s column.
innerRadiusnumber0.62The hole’s radius as a share of the ring’s, from 0, a pie chart, to below 1, a thin ring.
sliceGapnumber2The room between two slices, in px, as wide at the hole as at the edge; 0 for none.
growbooleanfalseThe slice under the pointer, the keys or picked grows out of the ring as well as staying bright. The ring leaves room for it.
entrance'none''draw''none'How the slices arrive the first time the chart comes into view: drawn round the ring from the top. None by default, since a page that loads doesn’t animate into place.

DonutChartCentre

PropTypeDefaultDescription
labelReactNodeNoneThe caption under the total; the chart’s valueLabel by default.

DonutChartLabels

PropTypeDefaultDescription
position'outside''inside''outside'Past the ring on a short line, or on the slice, in white or black, whichever reads on its colour.
content'value''share''name'(slice: DonutLabelSlice) => string'value'What each label writes. Your own function gets the slice’s key, name, value and share, from 0 to 1.

DonutChartRing

PropTypeDefaultDescription
dataKeystringNoneThe key of each slice’s value in this ring, in the chart’s data.
labelstringNoneWhat this ring’s values are, such as “Last year”, in the tooltip and the data table.

Data attributes

AttributeOnDescription
data-dimA sliceIt steps back while another slice is under the pointer or picked.
data-grownA sliceIt has grown out of the ring, with grow.

CSS variables

VariableSet it onDefaultDescription
--donut-chart-dimDonutChart, or anything above it0.3How much colour a slice that steps back keeps. It keeps its lightness, so it keeps its contrast.
--donut-chart-growDonutChart, or anything above it1.08How much a slice grows with grow, as a scale. The ring leaves room for it.

Accessibility

  • The ring is one stop in the tab order: a slider over the slices. The arrow keys step round, Home and End go to the first and last, and each slice’s name, value and share are read as the slider’s value.
  • A hidden table holds every slice’s value and share, with the total, for screen readers and for copying.
  • Loading, an error and new data are announced in a status region.
  • Each slice is named in the legend, the tooltip and the centre, so none relies on colour alone; patterns adds a pattern too. Forced colours draw each slice in a system colour.
  • A slice too small to see is drawn a few pixels long, so it shows and the pointer can find it.
  • Labels repeat what the tooltip and the data table say, so screen readers skip them. With rings, the tooltip, the table and the slider read every ring’s value.
  • When the system asks for less motion, slices move to their place at once and only fade.