# C donut chart 1

> Traffic sources — channel share with the total in the centre

A shadcn/ui block from the [@cnippet](https://ui.cnippet.dev/?utm_source=shadcn.exchange) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/cnippet/c-donut-chart-1).

- Page, with a live preview: https://shadcn.exchange/r/cnippet/c-donut-chart-1
- Screenshot: https://shadcn.exchange/shot/cnippet/c-donut-chart-1/light.png
- Registry item: https://ui.cnippet.dev/r/c-donut-chart-1.json
- Categories: donut chart
- Listed: 2026-10-27, source last changed 2026-10-27

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/cnippet/c-donut-chart-1.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `@cnippet/donut-chart`, `@cnippet/chart-card`, `@cnippet/chart-utils`

## Files

### `registry/default/chart-variants/c-donut-chart-1.tsx`

```tsx
"use client";

import { ChartCard } from "@/registry/default/charts/chart-card";
import { DonutChart } from "@/registry/default/charts/donut-chart";
import { formatCompact, sumBy } from "@/registry/default/lib/chart-utils";

const data = [
  { channel: "Organic", visitors: 18420 },
  { channel: "Direct", visitors: 9310 },
  { channel: "Referral", visitors: 6280 },
  { channel: "Social", visitors: 4170 },
  { channel: "Email", visitors: 2960 },
];

export default function TrafficSources() {
  return (
    <ChartCard
      className="max-w-sm"
      description="Visitors by channel, last 30 days"
      title="Traffic sources"
    >
      <DonutChart
        category="visitors"
        centerLabel="Visitors"
        centerValue={formatCompact(sumBy(data, ["visitors"]))}
        className="h-60"
        data={data}
        index="channel"
      />
    </ChartCard>
  );
}
```
