Skip to content
IndexRequest a UIAboutContact

Donut Chart with Linked Legend

A donut whose segments and legend highlight each other, with the value shown in the centre.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a donut chart for four categories: Direct 42%, Search 31%, Social 18% and Email 9%, drawn with SVG circles of radius 40 using stroke-dasharray and stroke-dashoffset, stroke width 14, rotated to start at the top, using four distinct greys plus one dark (#171717, #6f6f6f, #a3a3a3, #d4d4d4) with a 2px gap between arcs. The centre shows the total "12.4k visits" at rest and the name and percentage of the highlighted segment otherwise. A legend of four buttons (swatch, name, value) sits beside the chart. Hovering or focusing a legend entry or an arc highlights that segment (stroke width 18) and dims the others to 0.35 over 160ms; clicking pins it. Legend buttons have aria-pressed. On load the ring draws clockwise over 800ms ease-out. Under prefers-reduced-motion skip the draw and transitions.

About this pattern

Definition

A ring split into proportional arcs. Hovering or focusing an arc or its legend entry highlights that part, dims the others and shows its name and share in the centre.

Purpose & UX principles

  • Shows parts of a whole when there are few categories (up to five).
  • The legend is the accessible control: each entry is a button, and the numbers are always visible in it, so colour is never the only cue.
  • The centre label removes the need for a tooltip.

Interaction states

  • Rest (total shown), highlighted segment, focus-visible on legend, pinned segment on click.

Motion specification

  • Highlight: the active arc thickens from 14 to 18px and the others dim in 160ms.
  • The ring draws clockwise on load, 800ms ease-out.
  • Reduced motion: no draw, instant highlight.

Responsive behaviour

  • The SVG scales with its container; the legend sits beside the ring on wide layouts and below on narrow ones.

Code

HTML
<div class="wrap">
  <div class="ring"><svg viewBox="0 0 100 100" id="svg" aria-hidden="true"></svg><div class="ctr" id="ctr" aria-live="polite"><b>12.4k</b><small>visits</small></div></div>
  <ul class="lg" id="lg"></ul>
</div>

Related patterns

Interactive Bar Chart

↗
Interactive Bar ChartData Visualization

Stacked Bars with Series Toggle

↗
Stacked Bars with Series ToggleData Visualization

Progress Indicator

↗
Progress IndicatorLoading & Progress