Skip to Content
TelamonJS

PieChart

Pie chart component for showing part-to-whole relationships

Pie chart component built on Recharts for visualizing part-to-whole relationships and proportions. With innerRadius > 0 it renders as a donut.

Use Sparingly

Pie charts are best for showing 3-5 categories. For more categories or precise comparisons, consider using BarChart instead.


Basic Usage

import { PieChart } from '@telamonjs/ui'

const data = [
  { name: 'Desktop', value: 400 },
  { name: 'Mobile', value: 300 },
  { name: 'Tablet', value: 200 },
]

export default function DeviceChart() {
  return <PieChart data={data} dataKey='value' />
}

The value prop is `dataKey`, colors come from `colors`

The value field is dataKey (required), slice colors come from the colors array (cycled in data order — a fill field on the data is ignored), sizing is height + outerRadius, and there is no percentage/loading mode.


Props

Prop

Type


Examples

Custom Colors

<PieChart
  data={[
    { name: 'Product A', value: 400 },
    { name: 'Product B', value: 300 },
    { name: 'Product C', value: 200 },
  ]}
  dataKey='value'
  colors={['#3b82f6', '#10b981', '#f59e0b']}
/>

Colors are applied by position — the first color goes to the first data item.

Legend Only (no slice labels)

<PieChart data={data} dataKey='value' showLabels={false} />

Custom Field Names

const traffic = [
  { source: 'Organic Search', visitors: 12500 },
  { source: 'Direct', visitors: 8200 },
]

<PieChart data={traffic} dataKey='visitors' nameKey='source' />

Donut

A donut is PieChart with innerRadius > 0. The ring thickness is outerRadius - innerRadius.

import { PieChart } from '@telamonjs/ui'

const data = [
  { name: 'Completed', value: 620 },
  { name: 'In Progress', value: 210 },
  { name: 'Pending', value: 120 },
]

export function TasksChart() {
  return <PieChart data={data} dataKey='value' innerRadius={60} outerRadius={90} />
}

Centered KPI

The component has no center-metric prop. Overlay one with CSS:

<div className='relative'>
  <PieChart
    data={data}
    dataKey='value'
    innerRadius={60}
    outerRadius={90}
    showLabels={false}
  />
  <div className='pointer-events-none absolute inset-0 flex flex-col items-center justify-center'>
    <span className='text-3xl font-bold'>950</span>
    <span className='text-sm text-muted-foreground'>total tasks</span>
  </div>
</div>

Thin ring

<PieChart
  data={data}
  dataKey='value'
  innerRadius={80}
  outerRadius={90}
  showLabels={false}
  height={260}
/>

On rings, showLabels={false} plus the legend reads cleaner, and a 20-40px ring balances legibility and weight.


Complete Example

components/traffic-sources.tsx
'use client'

import { PieChart, BaseCard } from '@telamonjs/ui'

interface TrafficSource {
  name: string
  value: number
}

export default function TrafficSources({ data }: { data: TrafficSource[] }) {
  const total = data.reduce((sum, item) => sum + item.value, 0)

  return (
    <BaseCard
      title='Traffic Sources'
      description={`${total.toLocaleString()} total visitors`}
    >
      <PieChart data={data} dataKey='value' height={350} />
    </BaseCard>
  )
}

Best Practices

  1. Limit slices - 3-5 categories max (combine small slices into "Other")
  2. Order by size - Largest slice first (data order = drawing order)
  3. Use distinct colors - Pass explicit colors when the default palette doesn't fit
  4. Provide totals - Show the total value in the surrounding card
  5. Consider alternatives - Bar charts are often better for 5+ categories

When NOT to Use Pie Charts

❌ Don't use when:

  • More than 5-6 categories
  • Precise value comparison needed
  • Values are very similar (hard to distinguish slices)
  • Showing trends over time (use LineChart)

✅ Use instead:


Accessibility

  • Tooltip shows exact values on hover/focus
  • Don't rely on color alone — keep showLabels on or pair with a legend
  • Prefer high-contrast custom colors when brand colors are too similar

  • BarChart - Better for comparisons
  • KPICard - Standalone KPI display
  • ChartWidget - Chart inside a dashboard card, and charts the package does not wrap

See Also

On this page