Donut chart
A ring of shares with an optional central readout.
npx @swipeui/cli add donut-chartWhen to use it
- A ring of shares with an optional central readout.
When not to use it
- Use Metric card when one headline number answers the question without a full plot.
Installation
Installs with a Pro licence
Everything on this page is public except the source. Founder pre-sale opens around 5 January 2027.
Usage
import { DonutChart } from '@/components/swipeui/chart/donut-chart';
<DonutChart label="Storage" data={[{ id: "photos", label: "Photos", value: 42 }, { id: "files", label: "Files", value: 26 }]} />Examples
storage and activity. App and public preview use the same original scenario data. Range and feature controls stay outside the component.
Settings
| Prop | Default | Behaviour |
|---|---|---|
tooltipPlacement | plot | Place inspection inside the plot or above it. |
tooltipWidth | 184 | Readout width bounded by the visible plot. |
renderTooltip | default card | Custom inspection content; streamgraph supplies a coloured multi-row comparison. |
dismissOnOutsidePress | true | Clear floating inspection when touching outside a chart under ChartInteractionProvider. |
data[].max | 100 | Per-ring goal used by activity mode. |
variant | shares | Shares of a whole, or independent activity-goal rings. |
cornerRadius | 6 | Curvature at every slice corner. |
sliceGap | 6 | Constant physical separation in points. |
data | — | Ordered nonnegative parts. |
labels | true | Show each part in the labelled key. |
selectionOffset | true | Separate the selected slice from its neighbours. |
gap | 0 | Clockwise gap between slices, in radians. |
thickness | 0.25 | Ring thickness as a fraction of radius. |
center | — | Caller centre content; defaults to the selected value or total. |
showCenter | true for shares, false for activity | Show centre content. |
label | — | Short accessible chart name. |
summary | — | Written description of the pattern, in the caller's words. |
loading | false | Show shimmer placeholders and expose the busy state. |
invalid | false | Explicitly unavailable dataset. |
interactive | true | Enable plot interaction and accessible value stepping. |
tooltip | true | Compact floating value card over the selected observation. |
legend | true | Show a labelled series/category key. |
legendPosition | 'bottom' | Put the key under the plot or 'top' above it. |
haptics | true | Tick when a different observation is selected. |
reveal | true | Reveal geometry on first appearance. |
animateData | true | Morph data changes; resize snaps. |
active | true | Pause ambient effects on hidden routes. |
selectedId | — | Controlled observation ID; null clears selection. |
defaultSelectedId | null | Initial observation when uncontrolled. |
onSelectionChange | — | Called only when semantic selection changes. |
locale | — | Device locale unless overridden. |
formatValue | — | Override value formatting. |
messages | — | Translatable built-in strings. |
motion | — | Inherited SwipeUI motion feel. |
height | 208 | Plot height in points; text flows outside it. |
className | — | Root class escape hatch. |
style | — | Root native layout escape hatch. |
testID | — | Stable root identifier. |
Accessibility
The plot exposes its name, summary and original values. Accessible value stepping and labelled keys supplement touch. Decorative marks do not repeat the readout. Reduced motion removes geometry travel.
Layout and data
Measure from the parent; let labels and keys wrap. Use stable IDs. Missing observations are gaps, not zeros. Parts of a whole and flows require nonnegative finite values. Native runtime, screen-reader, haptic and device-performance checks remain pending.
Presentation
Storage demonstrates rounded separated shares of a whole. Activity demonstrates three independently filled goal rings, rounded ends and staggered circular fills. The standard share donut reveals clockwise. Web and native use the same original data and signed goal values; the activity centre is empty by default.
Activity rings
<DonutChart label="Daily goals" variant="activity" data={[{ id: 'move', label: 'Move', value: 78, max: 100 }, { id: 'train', label: 'Train', value: 64, max: 100 }, { id: 'recover', label: 'Recover', value: 88, max: 100 }]} />Outside dismissal
Wrap the app or chart screen in ChartInteractionProvider from @/components/swipeui/lib/chart-core. It observes native touches without taking the responder; controls keep their normal behaviour. dismissOnOutsidePress={false} retains a caller-managed selection. Browser demonstrations use pointer observation and Escape.
Behavior and gestures
- Select a labelled observation by touch or accessible value stepping. The caller can control the selection.
- Data changes animate independently from reveal, selection feedback and optional ambient effects.
Accessibility
- The chart has a written summary and named values. Decorative SVG geometry is hidden from assistive technologies.
- Value stepping, labelled legends and text readouts supplement colour. Native screen-reader runtime validation remains pending.
Motion
- Uses the
morph,selectandambientmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Geometry transitions use the shared morph role; reduced motion swaps immediately.
- Ambient effects pause offscreen and in the background.
Performance
- Display geometry is bounded for time series; selection retains original data. Native device performance is not yet verified.
Notes for AI
- Use stable IDs and caller-owned data/state. Provide an accessible label and a useful written summary.
- Use ChartCard for an interactive chart composition; keep MetricCard sparkline content decorative.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.