# C pie chart 2

> Survey answers — percentage labels and a side legend

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-pie-chart-2).

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

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/cnippet/c-pie-chart-2.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/pie-chart`, `@cnippet/chart-card`

## Files

### `registry/default/chart-variants/c-pie-chart-2.tsx`

```tsx
"use client";

import { ChartCard } from "@/registry/default/charts/chart-card";
import { PieChart } from "@/registry/default/charts/pie-chart";

// "How did you hear about us?" — 412 responses.
const data = [
  { answer: "Search", responses: 148 },
  { answer: "A friend", responses: 102 },
  { answer: "Social media", responses: 79 },
  { answer: "Newsletter", responses: 51 },
  { answer: "Other", responses: 32 },
];

export default function SurveyAnswers() {
  return (
    <ChartCard
      className="max-w-md"
      description="How did you hear about us? 412 responses"
      title="Survey"
    >
      <PieChart
        category="responses"
        className="h-60"
        data={data}
        index="answer"
        legendLayout="side"
        showLabels
        valueFormatter={(value) => `${value} responses`}
      />
    </ChartCard>
  );
}
```
