PeakUIPro

RadialChart

Progress shown as concentric rings, a dial, or a single ring around a figure

Usage

RadialChart is imported from its own subpath and needs the optional recharts peer.

npm install recharts
import {RadialChart} from "@peakui-pro/react/radial-chart";

Anatomy

import {RadialChart} from "@peakui-pro/react/radial-chart";

// Only the root is this package's own; the parts are the charting library's components under
// PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no
// chart never needs the peer installed, not even to render on a server.
export default () => (
  <RadialChart aria-label="Energy activity" data={[]}>
    <RadialChart.AngleAxis domain={[0, 100]} tick={false} type="number" />
    <RadialChart.Tooltip content={<RadialChart.TooltipContent />} />
    <RadialChart.Bar background dataKey="value">
      <RadialChart.Cell />
    </RadialChart.Bar>
  </RadialChart>
);

Data belongs to the chart

data is one object per ring. The first row is the innermost ring. A single row is a gauge or a progress ring. Bar reads each row's dataKey, and its background prop draws the empty track under every bar; the track takes the --default surface colour.

Fixing the scale

Without an AngleAxis, the largest value fills the sweep. Add one with type="number", domain={[0, 100]} and tick={false} to make each value a percentage of its own goal. Give it angleAxisId={0} to be certain the bars read it.

The sweep

startAngle and endAngle are degrees, counter-clockwise from three o'clock. The defaults, 90 and -270, make one full circle that starts at twelve o'clock and fills clockwise. A dial is a shorter sweep: 225 to -45 leaves the bottom quarter open (see Gauge).

innerRadius and outerRadius take pixels or a percentage of the plot's radius, and barSize is the ring's thickness in pixels. With several rows, the rings share the space between the two radii. cornerRadius on the Bar, half the thickness, rounds both ends fully.

Colouring rings

Give each ring its colour with a Cell, or put a fill on every row of the data and map it to a Cell. Use the series ramp var(--chart-2) … var(--chart-5). --chart-1 is the darkest step and nearly vanishes on a dark surface, --chart-2 is little better, and a ring is thin, so the examples on this page use --chart-3 to --chart-5.

A figure in the middle

The ring's centre is empty. Lay any React node over the chart in a relative wrapper, centre it, and set pointer-events-none so the pointer still reaches the bar beneath (see Gauge and Progress Ring).

Zero and empty data

A chart whose data is empty renders its container and draws no bar. Show your own empty state beside it.

Accessibility

The plot takes focus and answers the arrow keys, so aria-label names it, not the wrapper. Rings are told apart by colour; add a second cue the reader can use without it: print each ring's name and value beside the chart (see the first example) and state a single figure's value in the name.

// Named by a string, or by the element that already carries the chart's title.
<RadialChart aria-label="Daily steps: 75 percent" data={data}>{/* … */}</RadialChart>
<RadialChart aria-labelledby="steps-title" data={data}>{/* … */}</RadialChart>

// A chart that only repeats a figure printed beside it leaves the keyboard layer out.
<RadialChart accessibilityLayer={false} data={data}>{/* … */}</RadialChart>

Examples

Gauge

A shorter sweep, startAngle={225} to endAngle={-45}, leaves the bottom open. The figure sits in the middle.

Progress Ring

The default sweep with one row. A thicker barSize and a tighter band put the ring at the edge.

With Legend

Rings share a fixed scale, domain={[0, 128]}, so each reads as a share of the whole. The legend is the same rows, listed beside the figures.

Gauge Grid

One single-row chart per card, repeated in a grid.

Customization

Tailwind CSS

<RadialChart className="mx-auto max-w-xs" data={data} height={220} />

Global CSS

@layer components {
  .radial-chart .recharts-radial-bar-background-sector {
    fill: var(--border);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The RadialChart component uses these CSS classes (view source styles):

Base Classes

  • .chart-polar - The block every polar chart carries; tick text, the hidden tooltip cursor, the raised tooltip and the focus ring
  • .radial-chart - This chart's own block; gives the root its width and paints each ring's empty track in --default

Slots

  • [data-slot="radial-chart"] - The root element

CSS Variables

VariablePurpose
--defaultThe colour of each ring's empty track
--chart-1 … --chart-5The series ramp, derived from the theme's accent

API Reference

RadialChart

PropTypeDefaultDescription
dataRecord<string, number | string>[]-One object per ring; the first is the innermost
heightnumber | `${number}%` 300Height of the plot
widthnumber | `${number}%` '100%'Width of the plot
barSizenumber10Thickness of each ring, in pixels
innerRadiusnumber | string'30%'Where the innermost ring starts
outerRadiusnumber | string'80%'Where the outermost ring ends
startAnglenumber90Where the sweep starts, degrees counter-clockwise from three o'clock
endAnglenumber-270Where the sweep ends
accessibilityLayerbooleantrueWhether the plot is focusable and answers the arrow keys
childrenReactNode-The chart's parts
aria-labelstring-Names the plot, which is what takes focus — not the wrapping <div>
aria-labelledbystring-Names the plot by another element's id
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes, on the wrapper

There is no margin: a polar chart sizes itself from its container.

RadialChart.Bar

The charting library's RadialBar, re-exported. See the Recharts RadialBar API.

RadialChart.Cell

The charting library's Cell, re-exported. See the Recharts Cell API.

RadialChart.AngleAxis

The charting library's PolarAngleAxis, re-exported. See the Recharts PolarAngleAxis API.

RadialChart.Tooltip

The charting library's Tooltip, re-exported. See the Recharts Tooltip API.

RadialChart.TooltipContent

ChartTooltip.Content, for the content prop of RadialChart.Tooltip. Its props are on the ChartTooltip page.

On this page