# C drilldown chart 3

> Sales by product — horizontal bars, category → product

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-drilldown-chart-3).

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

## Install

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

## Files

### `registry/default/chart-variants/c-drilldown-chart-3.tsx`

```tsx
"use client";

import { ChartCard } from "@/registry/default/charts/chart-card";
import {
  DrilldownChart,
  type DrilldownNode,
} from "@/registry/default/charts/drilldown-chart";

const leaf = (name: string, value: number): DrilldownNode => ({ name, value });
const node = (name: string, children: DrilldownNode[]): DrilldownNode => ({
  children,
  name,
  value: children.reduce((sum, c) => sum + c.value, 0),
});

// Units sold in Q3: category → product, as horizontal bars for long names.
const data = [
  node("Audio", [
    leaf("Studio Air", 4120),
    leaf("Pulse Buds", 3380),
    leaf("Room One", 1960),
  ]),
  node("Keyboards", [
    leaf("Type Pro", 2870),
    leaf("Type S", 2110),
    leaf("Type Low", 940),
  ]),
  node("Accessories", [
    leaf("USB-C hub", 5240),
    leaf("Laptop stand", 3010),
    leaf("Cable kit", 2480),
  ]),
];

export default function UnitsByProduct() {
  return (
    <ChartCard
      className="max-w-xl"
      description="Units sold in Q3"
      title="Sales by product"
    >
      <DrilldownChart
        className="h-48"
        color="var(--chart-5)"
        data={data}
        layout="vertical"
        rootLabel="All categories"
        valueFormatter={(value) => value.toLocaleString("en-US")}
        valueLabel="Units"
        yAxisWidth={96}
      />
    </ChartCard>
  );
}
```
