DitherCharts

Radial chart

Updated

RadialChart draws one ring per row, its bar running clockwise from 12 o'clock unless you set the start and end angles. Like every DitherCharts chart, it fills its container's width, animates in, moves a cursor with the arrow keys, and keeps a data table for screen readers.

Example

Radial Chart

One ring per browser on its track

Radial Chart

install command

npx dithercharts add radial-chart

usage

import { RadialChart } from "@/components/dithercharts/radial-chart"
import type { ChartConfig } from "@/components/dithercharts/chart-config"

const chartData = [
  { browser: "chrome", visitors: 268 },
  { browser: "safari", visitors: 214 },
  { browser: "firefox", visitors: 179 },
  { browser: "edge", visitors: 152 },
  { browser: "other", visitors: 86 },
]

const chartConfig = {
  visitors: { label: "Visitors" },
  chrome: { label: "Chrome" },
  safari: { label: "Safari" },
  firefox: { label: "Firefox" },
  edge: { label: "Edge" },
  other: { label: "Other" },
} satisfies ChartConfig

export function ChartRadialSimple() {
  return (
    <RadialChart
      data={chartData}
      config={chartConfig}
      nameKey="browser"
      dataKey="visitors"
      label="Visitors by browser"
      tooltip={{ hideLabel: true }}
      innerRadius={30}
      track
    />
  )
}

Installing needs DitherCharts Pro. See pricing.

Visitors by browser
browserVisitors
Chrome268
Safari214
Firefox179
Edge152
Other86
import { RadialChart } from "@/components/dithercharts/radial-chart"
import type { ChartConfig } from "@/components/dithercharts/chart-config"

const chartData = [
  { browser: "chrome", visitors: 268 },
  { browser: "safari", visitors: 214 },
  { browser: "firefox", visitors: 179 },
  { browser: "edge", visitors: 152 },
  { browser: "other", visitors: 86 },
]

const chartConfig = {
  visitors: { label: "Visitors" },
  chrome: { label: "Chrome" },
  safari: { label: "Safari" },
  firefox: { label: "Firefox" },
  edge: { label: "Edge" },
  other: { label: "Other" },
} satisfies ChartConfig

export function ChartRadialSimple() {
  return (
    <RadialChart
      data={chartData}
      config={chartConfig}
      nameKey="browser"
      dataKey="visitors"
      label="Visitors by browser"
      tooltip={{ hideLabel: true }}
      innerRadius={30}
      track
    />
  )
}

Install

Charts install with DitherCharts Pro. See Installation to log in and import the stylesheet.

npx dithercharts add radial-chart

Props

RadialChart props
PropTypeDefaultDescription
datarequiredType readonly ChartRow[]Default –One row per ring, first innermost, e.g. { browser: "chrome", visitors: 275 }.
configrequiredType ChartConfig<SlicePattern>Default –One entry per ring name (its label and, optionally, its pattern), plus one for dataKey (the value's label).
nameKeyrequiredType stringDefault –The row key that holds each ring's name, e.g. "browser".
dataKeyrequiredType string | readonly string[]Default –The row key that holds each ring's value, e.g. "visitors"; or several stacked along each bar, e.g. ["mobile", "desktop"].
labelrequiredType stringDefault –Accessible name, e.g. "Visitors by browser". Also captions the table twin.
innerRadiusType numberDefault 30The hole's radius in CSS pixels.
startAngleType numberDefault 0Where the bars start, in degrees clockwise from 12 o'clock.
endAngleType numberDefault 360Where a bar at the max ends, in degrees clockwise from 12 o'clock; a lone row fills to it.
centerLabelType booleanDefault falseThe total in the middle, over the value's label (or "Total" for stacked keys); above the center on a top half ring.
trackType booleanDefault falseEach ring's full turn behind its bar, as a 1-cell outline.
labelsInsideType booleanDefault falseEach ring's name at its bar's start, cut out of the ink.
gridType booleanDefault falseA dashed 1-cell circle through each ring's middle, behind its bar.
tooltipType TooltipOptionsDefault –The tooltip's indicator and label, and the ring it opens on at rest.
styleType StyleIdDefault "bayer4"Dither style.
animationType "develop" | "none"Default "develop"Entrance animation; reduced motion always shows the final frame.
heightType numberDefault 250Height in CSS pixels; the width fills the container.
cellType numberDefault 3Dither cell size in CSS pixels.
classNameType stringDefault –Classes on the chart's outer figure.

Styles

The dither styles style takes:

  • "bayer2"
  • "bayer4"
  • "bayer8"
  • "blue-noise"
  • "halftone"
  • "crosshatch"
  • "pixel"
  • "stipple"
  • "engraved"
  • "mezzotint"
  • "woodcut"
  • "floyd-steinberg"
  • "atkinson"
  • "riemersma"

Keyboard and accessibility

The chart is one Tab stop. Focusing it from the keyboard puts the cursor on the first ring, or where the keys last left it; moving focus away clears it. The keys stop at the ends.

Chart keys
KeyAction
Left arrow Right arrowRing inward / outward
Home EndInnermost / outermost ring
Up arrow Down arrowPrevious / next stacked value (stacked bars)
EscapeDismiss the cursor

Screen readers

  • The chart's label names it, says how many rings it has and lists these keys.
  • Each key press is announced in a polite live region. Moving the pointer is silent.
  • The table button under the chart shows its data as a table. Screen readers can reach the table even while it's hidden; clicking a row moves the cursor there and announces it.
  • With legend, each entry is a toggle button. The last one showing can't be hidden, but its button stays focusable.

On a touch screen, a tap pins the cursor and a tap outside the chart dismisses it.

See every radial chart example