# Donut chart

Show composition with exact controlled inspection, legend visibility and a native table fallback.

Access: pro. Category: Data. Kind: composite.

## When to use

- Use it when a page needs show composition with exact controlled inspection, legend visibility and a native table fallback.
- Choose it when the data structure, labels, and state are supplied by the application and must remain consumer controlled.

## Alternatives

- Choose analytics-card instead when explore revenue, compare periods and inspect chart values is the actual interface need, rather than donut chart.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Donut chart

```sh
npx shadcn@latest add @tidal-pro/donut-chart
```

Stylesheets: `components/ui/tidal.css`, `components/ui/donut-chart.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/donut-chart.css";
import{TidalDonutChart}from"./components/ui/donut-chart";
export default()=><div className="tidal-scope"><TidalDonutChart segments={[{id:"example",label:"Demo",value:1,displayValue:"value"}]} title={"Demo"} totalText={"Demo"}/></div>;
```

## Structured props

- `TidalDonutChart.segments: ReadonlyArray<TidalDonutSegment>`: Required segments value accepted by this exported component.
- `TidalDonutChart.title: ReactNode`: Required title value accepted by this exported component.
- `TidalDonutChart.totalText: ReactNode`: Required total text value accepted by this exported component.
- `TidalDonutChart.activeId?: string | undefined`: Optional active id value accepted by this exported component.
- `TidalDonutChart.center?: ReactNode`: Optional center value accepted by this exported component.
- `TidalDonutChart.chartLabel?: string | undefined` (default "Composition chart"): Optional chart label value accepted by this exported component.
- `TidalDonutChart.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalDonutChart.emptyMessage?: ReactNode` (default "No positive values are available."): Optional empty message value accepted by this exported component.
- `TidalDonutChart.getLegendButtonProps?: ((segment: TidalDonutSegment) => LegendButtonProps | undefined) | undefined`: Optional get legend button props value accepted by this exported component.
- `TidalDonutChart.headingLevel?: "h2" | "h3" | "h4" | undefined` (default "h2"): Optional heading level value accepted by this exported component.
- `TidalDonutChart.hiddenIds?: ReadonlyArray<string> | undefined` (default []): Optional hidden ids value accepted by this exported component.
- `TidalDonutChart.legendButtonRefs?: Readonly<Record<string, Ref<HTMLButtonElement> | undefined>> | undefined`: Optional legend button refs value accepted by this exported component.
- `TidalDonutChart.legendLabel?: string | undefined` (default "Chart legend"): Optional legend label value accepted by this exported component.
- `TidalDonutChart.onActiveChange?: ((segment: TidalDonutSegment, source: "keyboard" | "pointer") => void) | undefined`: Callback invoked when the active change interaction is proposed.
- `TidalDonutChart.onHiddenChange?: ((hiddenIds: readonly string[], segment: TidalDonutSegment) => void) | undefined`: Callback invoked when the hidden change interaction is proposed.
- `TidalDonutChart.segmentRefs?: Readonly<Record<string, Ref<SVGGElement> | undefined>> | undefined`: Optional segment refs value accepted by this exported component.
- `TidalDonutChart.tableLabel?: ReactNode` (default "View data table"): Optional table label value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/donut-chart.tsx) | [Manifest](https://tidalui.com/examples/donut-chart.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useMemo, useState } from "react";

import { TidalDonutChart, type TidalDonutSegment } from "./components/ui/donut-chart";

import "./components/ui/donut-chart.css";



const tidalExampleStyles = ".tidal-scope .donut-chart-demo {\n  container: donut-chart-demo / inline-size;\n  display: grid;\n  gap: 14px;\n  width: 100%;\n  max-width: 720px;\n  min-width: 0;\n  margin-inline: auto;\n}\n\n.tidal-scope .donut-chart-demo-footer {\n  display: flex;\n  min-width: 0;\n  align-items: center;\n  justify-content: space-between;\n  gap: 12px;\n}\n\n.tidal-scope .donut-chart-demo-footer p {\n  min-width: 0;\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.45;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .donut-chart-demo-footer button {\n  flex: none;\n  min-width: 96px;\n  min-height: 44px;\n  padding: 0 15px;\n  color: var(--t-ink);\n  background: var(--t-surface);\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-control);\n  font: inherit;\n  font-size: 12px;\n  font-weight: 650;\n  cursor: pointer;\n  transition:\n    color 140ms,\n    background-color 140ms,\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .donut-chart-demo-footer button:hover:not(:disabled) {\n  color: var(--t-surface);\n  background: var(--t-ink);\n  border-color: var(--t-ink);\n}\n\n.tidal-scope .donut-chart-demo-footer button:active:not(:disabled) {\n  transform: scale(0.98);\n}\n\n.tidal-scope .donut-chart-demo-footer button:disabled {\n  opacity: 0.42;\n  cursor: not-allowed;\n}\n\n@container donut-chart-demo (max-width: 360px) {\n  .tidal-scope .donut-chart-demo-footer {\n    align-items: stretch;\n    flex-direction: column;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .donut-chart-demo-footer button {\n    transition: none;\n  }\n}\n\n.tidal-scope .donut-chart-demo-note {\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.45;\n}";

const SEGMENTS: readonly TidalDonutSegment[] = [
  {
    id: "research",
    label: "Research",
    value: 12,
    displayValue: "12 h",
    description: "Project notes and background research.",
  },
  {
    id: "design",
    label: "Design",
    value: 9,
    displayValue: "9 h",
    description: "Interface design and prototyping.",
  },
  {
    id: "writing",
    label: "Writing",
    value: 6,
    displayValue: "6 h",
    description: "Documentation and release notes.",
  },
  {
    id: "review",
    label: "Review",
    value: 4,
    displayValue: "4 h",
    description: "Quality checks and feedback.",
  },
  {
    id: "handoff",
    label: "Handoff",
    value: 0.75,
    displayValue: "45 min",
    description: "Delivery notes and handoff.",
  },
];

export function DonutChartDemo() {
  const [activeId, setActiveId] = useState("research");
  const [hiddenIds, setHiddenIds] = useState<readonly string[]>([]);
  const [status, setStatus] = useState("Research selected: 12 h.");
  const visibleTotal = useMemo(
    () =>
      SEGMENTS.filter((segment) => !hiddenIds.includes(segment.id)).reduce(
        (sum, segment) => sum + segment.value,
        0,
      ),
    [hiddenIds],
  );

  return (
    <section className="donut-chart-demo" aria-label="Donut chart preview">
      <TidalDonutChart
        title="Time by activity"
        description="Project time · This week"
        segments={SEGMENTS}
        totalText={`${visibleTotal.toLocaleString("en-US", { maximumFractionDigits: 2 })} h`}
        activeId={activeId}
        onActiveChange={(segment) => {
          setActiveId(segment.id);
          setStatus(`${segment.label} selected: ${segment.displayValue}.`);
        }}
        hiddenIds={hiddenIds}
        onHiddenChange={(nextHiddenIds, changedSegment) => {
          setHiddenIds(nextHiddenIds);
          const nextVisible = SEGMENTS.find(
            (segment) =>
              segment.value > 0 && !nextHiddenIds.includes(segment.id),
          );
          if (nextHiddenIds.includes(activeId) && nextVisible) {
            setActiveId(nextVisible.id);
          } else if (!nextVisible) {
            setActiveId("");
          } else if (!nextHiddenIds.includes(changedSegment.id)) {
            setActiveId(changedSegment.id);
          }
          setStatus(
            `${changedSegment.label} ${nextHiddenIds.includes(changedSegment.id) ? "hidden" : "shown"}.`,
          );
        }}
      />
      <footer className="donut-chart-demo-footer">
        <p role="status" aria-live="polite">
          {status}
        </p>
        <button
          type="button"
          disabled={!hiddenIds.length}
          onClick={() => {
            setHiddenIds([]);
            setActiveId("research");
            setStatus("All sample segments shown.");
          }}
        >
          Show all
        </button>
      </footer>
      <p className="donut-chart-demo-note">
        Sample data. Changes stay in this preview.
      </p>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <DonutChartDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Required title, consumer-owned segments{id,label,value,displayValue,description?}, and exact totalText. Finite positive visible values produce exact proportional arc geometry with only a bounded sub-degree visual gap; zero, negative and nonfinite values stay out of the chart while remaining explicit in the HTML table. Geometry scales before summing so multiple Number.MAX_VALUE values remain finite. Optional controlled activeId/onActiveChange enables a labelled SVG radiogroup with plain Arrow/Home/End inspection and Enter/Space activation. Optional controlled hiddenIds/onHiddenChange turns legend rows into native toggle buttons and leaves the legend available when every arc is hidden. Optional description, center, h2-h4 headingLevel, chartLabel, legendLabel, tableLabel, emptyMessage, per-segment SVG refs, legend button refs/getLegendButtonProps, and native figure attributes/ref. Legend native onClick runs first and preventDefault suppresses the higher callback; disabled and aria-disabled true normalize while explicit false is preserved. Focus recovers only when the actually focused arc is removed. The table region enters the tab order only when it overflows. The component does no requests, aggregation, persistence or analytics.
