DonutChart
Part-to-whole for ≤5 slices with center total, hover detail and % legend.
Code
import * as React from 'react';
import { DonutChart } from '@fruit-labs/design';
export default function Demo() {
return (
<div
style={{
maxWidth: 460,
}}
>
<DonutChart
title="Traffic sources"
subtitle="Sample data"
data={[
{
label: 'Search',
value: 46,
},
{
label: 'Direct',
value: 24,
},
{
label: 'Social',
value: 18,
},
{
label: 'Referral',
value: 12,
},
]}
/>
</div>
);
}Install
From npm:
npm install @fruit-labs/design
import { DonutChart } from '@fruit-labs/design';Or copy the TypeScript source into your project:
npx shadcn@latest add https://design.fruitlabs.online/r/donut-chart.jsonGuidelines
- More than 5 parts: use a bar chart.
Props
| Prop | Type | Required |
|---|---|---|
valueLabel | React.ReactNode | No |
data | Array<{ label: string; value: number; color?: string }> | Yes |
size | number | No |
thickness | number | No |
centerValue | React.ReactNode | No |
centerLabel | string | No |
title | React.ReactNode | No |
format | (v: number) => string | No |
allowTable | boolean | No |
className | string | No |