DocsComponentsTemplatesThemesGitHub

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

Guidelines

  • More than 5 parts: use a bar chart.

Props

PropTypeRequired
valueLabelReact.ReactNodeNo
dataArray<{ label: string; value: number; color?: string }>Yes
sizenumberNo
thicknessnumberNo
centerValueReact.ReactNodeNo
centerLabelstringNo
titleReact.ReactNodeNo
format(v: number) => stringNo
allowTablebooleanNo
classNamestringNo

Edit this example on GitHub