Skip to content

Components

DonutChart

Traffic sources

Visits: 13,000. Use the arrow keys to explore segments, or Home and End to jump.

Component reference

Properties

Use DonutChart

Shares of a whole with an in-ring total and exact values on inspection.

Example import style
donut-chart.tsxTSX
"use client";

import { FloodRoot, DonutChart } from "@flood-md/react";
import "@flood-md/react/styles.css";

export function Example() {
  return (
    <FloodRoot>
      <DonutChart label="Traffic sources" totalLabel="Visits" items={[
        {id:"direct", label:"Direct", value:6420},
        {id:"search", label:"Search", value:3720},
        {id:"referrals", label:"Referrals", value:1960}
      ]} />
    </FloodRoot>
  );
}

Design notes

  • Pass up to six mutually exclusive categories in display order. Values must be finite and nonnegative. The ring uses their sum as the whole.
  • Hover, tap or use arrow keys, Home and End to inspect a category. Its name, exact value and share appear inside the ring. Enable showLegend when readers need the category names before interacting.
  • An empty list displays the empty label. All-zero data displays a total of zero and omits percentages. Supply formatValue and formatShare for localized output.

API reference

PropValuesDefault
labelstringRequired
itemsreadonly DonutChartItem[]Required
totalLabelstring"Total"
emptyLabelstring"No data"
navigationLabelstring"Use the arrow keys to explore segments, or Home and End to jump."
showLegendboolean—
formatValue(value: number) => string—
formatShare(share: number) => string—
Native HTML propsOmit<HTMLAttributes<HTMLDivElement>, "children" | "role" | "aria-label">Forwarded
View TypeScript source