Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Charts

PieChart

Parts of a whole (MUI X's PieChart). Best with 2 to 5 slices.

import { PieChart } from "@stylhero/ui";

Example

Code
import { PieChart } from "@stylhero/ui";

function PieChartExample() {
  return <PieChart title="Budget split" centerLabel="$1,140"
    data={[{ label: "GPU", value: 420 }, { label: "CPU", value: 260 }, { label: "Memory", value: 140 }, { label: "Other", value: 320 }]} />;
}

Props

PropTypeDefaultDescription
data required PieSlice[] - Up to 8 slices; anything past the 7 largest is grouped into "Other".
centerLabel ReactNode - Text in the hole, e.g. the total.
description string -
donut boolean true Hole in the middle (0 = pie).
size number 200
subtitle ReactNode -
title ReactNode -
valueFormat Fmt defaultFmt

Also takes the HTML attributes of its root element (id, style, data-*, aria-*, event handlers…).

Types

type PieSlice = { label: string; value: number };

type Fmt = (n: number) => string;

Accessibility

  • role="img" labelled by description (else the title). The "Show as table" button switches to a data table with the same numbers.

Generated from src/components/Charts.tsx. Something wrong or missing? Open an issue.