suiss/ui ยท Chart
Pie Chart
Ten pie and donut charts for showing parts of a whole, with labels, legends, a centered total, nested rings and highlighted slices.
Pie Chart is an open-source chart from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Pie charts show how a whole splits into a few parts. Use the default pie or a donut for up to five or six slices, put the total in the center of a donut, and label slices directly or with a legend when the names are long. The nested variant shows groups and their members in two rings, and the active and separated variants draw attention to one slice.
Each chart is built on the Chart and Card components.
Every variant below is its own registry item, so you can add only the ones you need. Each one renders the same design on React, React Native, SwiftUI and Jetpack Compose.
Default
A full pie split into five device slices, separated by thin card-colored borders.
A full pie split into five slices separated by thin gaps, with a tooltip for each slice. Use it for a quick part-to-whole view of a small number of categories.
Give each record a category key, a value and a fill that references its color, and add a label and color for every key to chartConfig. Point dataKey and nameKey on the Pie at your value and category fields. Pies work best with about five slices or fewer; group the rest into an Other slice.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Web preview
The simplest PieChart: one Pie inside a Card, with slices separated by a thin stroke in the card color. chartData holds one record per device with a users count. Pressing a slice shows a tooltip with its name and value.
Replace chartData with your records and keep dataKey and nameKey in step with your field names. Add one entry per slice to chartConfig with its label and color; the component takes no props.
Installation
-
Target iOS 17 or later.
-
Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Active
A donut where one slice is enlarged and outlined with an outer arc to highlight it.
A donut with one slice pulled outward and traced by a thin outer arc, so a single category stands out from the rest. Use it to call attention to the segment a page is about, such as the current plan or the user's own device.
Give each record in chartData a value and a fill that points at its color in chartConfig. Set ACTIVE to the index of the slice to emphasize; the highlight does not follow hover, so drive ACTIVE from state if it should follow a selection.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart donut inside a Card, showing users by device. chartData holds one record per device with a users count. The Pie shape callback enlarges the slice at index ACTIVE and adds a thin arc outside it. Pressing a slice shows a tooltip with its name and value.
Replace chartData with your records and keep dataKey and nameKey in step with your field names. Add one entry per slice to chartConfig with its label and color; change ACTIVE to highlight a different slice. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Donut Text
A donut with the total number of users displayed in the center of the ring.
A donut with the total shown in its center, so readers get the overall number and the breakdown in one glance. Prefer it over the plain donut when the total is the headline.
Replace chartData and the category entries in chartConfig; the center total is summed from the data. Change the caption under the number to your unit, and adjust innerRadius if a longer number needs more room. The center text lets pointer events through, so slice tooltips still work.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart donut with small gaps and rounded slice corners. chartData holds one record per device with a users count. The total is summed from chartData and drawn as Text layered over the ring. Pressing a slice shows a tooltip.
Replace chartData with your records; the center total recalculates from it. Update the users caption and chartConfig labels and colors to match. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Donut
A donut chart with a hollow center and small gaps between slices.
A donut with a hollow center and small gaps between slices. It reads lighter than a full pie and leaves the center free for a label if you need one later.
Replace chartData and add a label and color for each category key to chartConfig. innerRadius and outerRadius set the ring thickness, and paddingAngle the gap between slices.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart whose Pie uses innerRadius to leave the middle empty and paddingAngle to space the slices. chartData holds one record per device with a users count. Pressing a slice shows a tooltip.
Replace chartData with your records and keep dataKey and nameKey in step with your field names. Add one entry per slice to chartConfig with its label and color; the component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Half
A semicircular gauge-style pie showing battery share by device, with a caption under the arc.
A semicircular donut that reads like a gauge, with a figure and caption tucked under the arc. Use it in compact cards where a full circle takes too much height.
Replace chartData with your categories and their shares, and add each key to chartConfig. The tooltip appends a percent sign, so change its formatter if your values aren't percentages. The figure and caption under the arc are static text. The arc's size depends on the container height, so check the fit if you change it.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart drawn from 180 to 0 degrees, with rounded, spaced slices. chartData holds a percentage share per device. A centered Text shows the 100% total, and the tooltip uses a custom formatter to print each share as a percentage.
Replace chartData with your shares and update chartConfig and the caption under the arc. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Interactive
A storage breakdown donut with a device switch, hover-linked list and lifted slices, plus a linear usage bar.
A storage breakdown with a Phone and Cloud switch, a stacked usage bar, a donut whose hovered slice lifts out and a list linked to it. The center shows the used total or the hovered category, and the slices morph when you switch devices. Use it as a reference for a rich part-to-whole view with linked controls.
Replace STORAGE with your sources, each with a total and the size of every category, list the categories in KINDS and add a label and color for each to chartConfig. Free space is computed from the total, and each source adds a toggle. Hovering the slices, the bar or the list highlights a category, but list rows aren't focusable, so keyboard users only get the totals. The center readout is a live region, and the morph is skipped when reduced motion is preferred.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A Card with a ToggleGroup that switches between phone and cloud storage, a stacked usage bar, a PieChart donut and a list of categories. Sizes come from the STORAGE record, and free space is the total minus what is used. Pressing a slice or a list row selects that category: its slice lifts outward, other segments in the bar dim, and the center text shows its size and share. Pressing it again returns to total used. The donut sets isAnimationActive={false} and draws without the enter animation.
Replace STORAGE with your devices, totals and per-category sizes, and keep KINDS, chartConfig and SWATCH in sync when adding categories. The component takes no props.
Installation
The CLI also adds what it builds on: Card, Chart, Text, Toggle Group.
Follow the manual steps under Default and copy this variant's source instead.
Usage
Label
A pie with each category name drawn outside its slice and joined by a leader line.
A pie with each category name printed outside its slice and connected by a leader line. Use it when readers shouldn't have to match colors against a separate legend.
Replace chartData and the category entries in chartConfig; labels read their text from the config. Change what the custom label renderer returns to print values or percentages, and shrink outerRadius if long names get clipped. Outside labels collide when slices are thin, so keep the category count low.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart with a smaller radius to leave room for labels. chartData holds one record per device with a users count. The label callback reads each slice name from chartConfig, and labelLine draws the connector. Pressing a slice shows a tooltip.
Replace chartData with your records and keep dataKey and nameKey in step with your field names. Add one entry per slice to chartConfig with its label and color; the component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Legend
A donut with a legend beneath it that lists every category and its color.
A donut with a legend underneath listing every category and its color. Pick it when a chart has enough slices that labels around the ring would get crowded.
Replace chartData and add a label and color for each category to chartConfig; the legend reads both from there. Keep nameKey on the legend content set to your category field so the names resolve.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart donut with a ChartLegend that lists every slice from chartConfig. chartData holds one record per device with a users count. Pressing a slice shows a tooltip.
Replace chartData with your records and keep dataKey and nameKey in step with your field names. Add one entry per slice to chartConfig with its label and color; the component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Nested
Two concentric pies: an inner ring of grouped totals surrounded by an outer ring of individual categories.
Two concentric rings: a lighter inner pie of group totals surrounded by an outer ring of individual categories. Use it for two-level breakdowns, such as product lines and the products within them.
Put the detailed records in chartData and the group totals in groups, with each group total equal to the sum of its categories. Order the outer categories so each group's members sit next to their inner slice. The demo groups reuse the Phone and Watch keys, so their tooltips read Phone and Watch; give each group its own key and label in chartConfig.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart with two Pie layers. The inner pie reads a groups array and is drawn at reduced opacity; the outer ring reads chartData, one record per device. Pressing a slice in either ring shows a tooltip.
Replace groups and chartData with your summary and detail records, and add each name to chartConfig with its label and color. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Separated
A donut whose slices are pulled apart with wide gaps and rounded corners.
A donut whose slices are pushed apart with wide gaps and rounded corners, giving each segment a tile-like look. Choose it for a softer, more decorative style than the standard donut.
Replace chartData and add each category to chartConfig. paddingAngle sets the spacing and cornerRadius the rounding; large values squeeze thin slices, so this style suits data without tiny values.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
A PieChart donut with paddingAngle and cornerRadius set so each slice stands apart. chartData holds one record per device with a users count. Pressing a slice shows a tooltip.
Replace chartData with your records and keep dataKey and nameKey in step with your field names. Add one entry per slice to chartConfig with its label and color; the component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.