Skip to content
Home Theme Gallery

Radial chart

The custom element is <hui-radial-chart>.

Overview

Radial bars: one ring per row, the first innermost, each sweeping in proportion to its value, optionally over a muted track. A single row is a progress ring.

Example

Rings on a track
Source
<div style="width:250px"><hui-radial-chart label="Visitors by browser" track center-label="935" center-caption="Visitors" style="height:250px">
<script type="application/json">{"series":[{"key":"visitors","label":"Visitors"}],"rows":[{"label":"Chrome","visitors":275},{"label":"Safari","visitors":200},{"label":"Firefox","visitors":287},{"label":"Edge","visitors":173}]}</script>
</hui-radial-chart></div>

The Go template that renders it:

<hui-radial-chart label="Visitors by browser" track center-label="{{ .Total }}" center-caption="Visitors" style="height:250px;width:250px">
<script type="application/json">{{ .Browsers }}</script>
</hui-radial-chart>

API

Attributes16
Attributes
NameTypeDefaultDescription
labelstring""Required. The chart's accessible name, followed by the centre text, and the data table's caption.
indexstring"label"The row property that names each slice or ring.
start-anglenumber90Where the first arc starts, in degrees from three o'clock, counter-clockwise - Recharts' convention, so shadcn's values carry over.
end-anglenumber-270Where a full sweep ends. Below the start angle, the chart runs clockwise.
inner-radiusnumber0.3The hole. Up to 1 a fraction of the room, above 1 pixels.
outer-radiusnumber1The outer edge, the same way.
maxnumberthe largest valueThe value a full sweep stands for.
trackbooleanfalseDraws each ring's whole sweep in --hui-muted behind its value.
radiusnumber5The corner radius of each ring's ends, in pixels.
center-labelstring-Large text in the middle - a total. Read after the label as part of the chart's name.
center-captionstring-Smaller, muted text beneath it.
legendbooleanfalseA legend of the rows under the chart.
tooltip"index" | "item" | "none""index"The row under the pointer, or no tooltip.
indicator"dot" | "line" | "dashed""dot"The marker beside the tooltip row.
formatstring-Intl.NumberFormat options as JSON.
localestringthe document's langThe locale values are formatted in.
Properties16
Properties
NameTypeDefaultDescription
labelstringas <code>label</code>Reflects to the label attribute.
indexstringas <code>index</code>Reflects to the index attribute.
startAnglenumberas <code>start-angle</code>Reflects to the start-angle attribute.
endAnglenumberas <code>end-angle</code>Reflects to the end-angle attribute.
innerRadiusnumberas <code>inner-radius</code>Reflects to the inner-radius attribute.
outerRadiusnumberas <code>outer-radius</code>Reflects to the outer-radius attribute.
maxnumberas <code>max</code>Reflects to the max attribute.
trackbooleanas <code>track</code>Reflects to the track attribute.
radiusnumberas <code>radius</code>Reflects to the radius attribute.
centerLabelstringas <code>center-label</code>Reflects to the center-label attribute.
centerCaptionstringas <code>center-caption</code>Reflects to the center-caption attribute.
legendbooleanas <code>legend</code>Reflects to the legend attribute.
tooltip"index" | "item" | "none"as <code>tooltip</code>Reflects to the tooltip attribute.
indicator"dot" | "line" | "dashed"as <code>indicator</code>Reflects to the indicator attribute.
formatstringas <code>format</code>Reflects to the format attribute.
localestringas <code>locale</code>Reflects to the locale attribute.
Events1
Events
NameDescription
hui-chart-focusThe reader moved to a category, by pointer or keyboard: its position, and the row as the server sent it. It bubbles and is composed. Announced, never stored: a host can mirror it elsewhere on the page.
Slots1
Slots
NameDescription
(default)One <script type="application/json"> holding series and rows. Replacing it, or its text, redraws the chart.
CSS custom properties2
CSS custom properties
NameDefaultDescription
--hui-chart-1 … --hui-chart-5the preset's violetSeries colours, by position, repeating after the fifth.
--hui-series-<key>-One series' colour, set from the host's stylesheet: --hui-series-mobile: var(--hui-chart-4). A colour field in the JSON wins over it.
::part() hooks9
::part() hooks
NameDescription
figureThe wrapper carrying role="figure" and the name.
plotThe <svg>, hidden from assistive technology.
markOne slice or ring, with data-index.
trackA ring's whole sweep, behind its value.
centre-labelThe text in the middle.
tableThe visually hidden data table.
tooltipThe tooltip, a manual popover.
legendThe legend of rows.
announcerThe visually hidden live region.

States

One ring against a goal

A single row, with track drawing the rest of the sweep behind it and max saying what a full turn is worth.

One ring against a goal
Source
<div style="width:200px"><hui-radial-chart label="Storage used" track max="100" center-label="72%" center-caption="of 100 GB" style="height:200px">
<script type="application/json">{"series":[{"key":"used","label":"Used"}],"rows":[{"label":"Used","used":72}]}</script>
</hui-radial-chart></div>

Server-side mechanics

The server writes one row per slice or ring into the element's <script type="application/json"> child, in the order they are drawn: the chart never sorts, so the server decides whether the biggest slice comes first. A row may carry its own colour. Only the first series is drawn. Replacing the child redraws the same element without animating.

Accessibility

  • The chart is a figure named by its label and the centre text - "Browser share: 935 Visitors" - because the SVG, and so the text drawn in the hole, is hidden from assistive technology. The data is a visually hidden table.
  • The plot is one tab stop: the arrow keys step the slices or rings with the tooltip following, and a polite live region reads each - "Safari 200".
  • The first draw sweeps the arcs open over 1500ms after a 400ms pause, as the reference's do; under prefers-reduced-motion: reduce they are simply there.

Keyboard

Keyboard
KeysAction
TabFocuses the plot, one stop per chart, and shows the tooltip at the category the keyboard was last on.
Arrow Right, Arrow DownThe next category.
Arrow Left, Arrow UpThe previous category.
Home, EndThe first and the last category.
EscapeHides the tooltip; focus stays on the plot.

Gotchas

  • Without max the largest value is a full turn. Send max when the rings measure progress towards a goal.
  • Like every chart, it ships in home-ui-charts.js.