Radar Chart

Compares several measures at once on a shape around a center point.

JanuaryFebruaryMarchMayJune03570105140

Usage

Code
import { RadarChart } from '@leverui/components';
Code
<RadarChart
  data={[
    { label: 'January', windows: 110 },
    { label: 'February', windows: 130 },
    { label: 'March', windows: 110 },
  ]}
  series={[{ name: 'windows', color: 'teal.solid' }]}
  radiusLabels
  aria-label="Monthly operating-system use"
/>

Examples

Lines Only

Compare two unfilled outlines against the shared polar grid.

macwindows

Multiple

Compare two translucent, independently colored data polygons.

macwindows

Circle Grid

Draw circular value levels behind the single teal polygon.

JanuaryFebruaryMarchMayJune03570105140

Dots

Mark the five data vertices on the single-series polygon.

JanuaryFebruaryMarchMayJune

Filled Grid

Tint the grid levels and retain visible point markers.

JanuaryFebruaryMarchMayJune

Point Label

Print each numeric measurement beside its polygon vertex.

JanuaryFebruaryMarchMayJune1101301109075

Tooltip

Reveal the active category and measurement on pointer or keyboard input.

JanuaryFebruaryMarchMayJune

Props

Data

PropDefaultTypeDescription
data—readonly RadarDatum[]Rows, one per category. Required.
series—readonly RadarSeries[]Number fields to draw. Required.
maxValue—numberNumber at the outer edge.

The chart needs at least three rows to draw a shape.

Without maxValue, the largest value is rounded up to a multiple of 20. A maxValue of zero or less is ignored.

A value that is negative or not a number is drawn at the center. A value above maxValue is drawn at the outer edge.

Shapes

PropDefaultTypeDescription
linesOnlyfalsebooleanDraw outlines only, no fill.
dotsfalsebooleanDraw a dot at each value.
pointLabelsfalsebooleanPrint each value at its point.

Grid and labels

PropDefaultTypeDescription
gridpolygon'polygon' | 'circle' | 'filled'Grid style.
angleLabelstruebooleanShow category names around the chart.
radiusLabelsfalsebooleanShow scale numbers, center to edge.

grid values: polygon (four rings with straight sides, plus spokes), circle (four round rings, plus spokes), filled (tinted rings, no ring lines or spokes).

Legend and tooltip

PropDefaultTypeDescription
legendfalsebooleanShow a legend below the shapes.
tooltipfalsebooleanShow values for the category nearest the pointer. Turns on keyboard use.

The legend sits inside the chart's height, so the shapes are drawn a little smaller. It lists the series in reverse order.

Size

PropDefaultTypeDescription
width384numberWidth, in pixels.
height288numberHeight, in pixels.

The chart keeps its shape when it shrinks to fit a narrower container.

Other attributes and event handlers go to the root element. Without aria-label, the chart is announced as "Radar chart".

Data rows

FieldTypeDescription
labelstringCategory name. Required.
Any other keynumberValue for one series. The key must match the series name.

Series options

FieldTypeDescription
namestringNumber field in your data. Also the name in the legend and tooltip. Required.
colorstringColor token such as teal.solid, or a CSS color. Required.

Keyboard

The chart takes focus when tooltip is on. Focus shows the tooltip for the first category.

KeyAction
ArrowLeft ArrowRightPrevious or next category.
EscapeClose the tooltip.

Your own onFocus, onBlur, and onKeyDown handlers run after the chart's.

Styling

Code
<RadarChart class="usage-radar" data={data} series={series} legend />
Code
.usage-radar {
  --leverui-radar-chart-grid-stroke: #a6c9c0;
  --leverui-radar-chart-series-fill-opacity: 0.35;
}

.usage-radar .leverui-radar-chart__angle-label {
  font-weight: 600;
}

Variables

VariableDefaultDescription
--leverui-radar-chart-widthThe width propDisplayed width.
--leverui-radar-chart-max-width100%Widest the chart gets.
--leverui-radar-chart-marginautoMargin around the chart. auto centers it.
--leverui-radar-chart-grid-strokeBorder colorGrid line color.
--leverui-radar-chart-grid-stroke-width1pxGrid line thickness.
--leverui-radar-chart-grid-fillteal.solid colorRing tint when grid is filled.
--leverui-radar-chart-grid-fill-opacity0.1Opacity of that tint, 0 to 1.
--leverui-radar-chart-label-font-size12pxText size of every label.
--leverui-radar-chart-angle-label-colorMuted text colorCategory name color.
--leverui-radar-chart-radius-label-color#cccScale number color.
--leverui-radar-chart-point-label-colorText colorColor of the pointLabels values.
--leverui-radar-chart-series-stroke-width1px or 2pxShape outline thickness.
--leverui-radar-chart-series-fill-opacity0.2Shape fill opacity, 0 to 1.
--leverui-radar-chart-legend-gap12pxSpace between legend items.
--leverui-radar-chart-legend-overlap-33pxLegend top margin. Pulls the legend up into the chart.
--leverui-radar-chart-legend-padding5px 0Space inside the legend.
--leverui-radar-chart-legend-colorMuted text colorLegend text color.
--leverui-radar-chart-legend-font-size12pxLegend text size.
--leverui-radar-chart-legend-item-gap4pxSpace between a swatch and its name.
--leverui-radar-chart-legend-swatch-size8pxSwatch width and height.
--leverui-radar-chart-legend-swatch-radius2pxSwatch corner radius.

The outline is 2px when linesOnly is on or there is more than one series. Otherwise it is 1px.

--leverui-radar-chart-width changes the displayed width, not what is drawn. The width and height props still set the proportions.

VariableDefaultDescription
--leverui-chart-tooltip-bgPanel colorTooltip background.
--leverui-chart-tooltip-padding4px 10pxSpace inside the tooltip.
--leverui-chart-tooltip-gap4pxSpace between rows.
--leverui-chart-tooltip-radius4pxTooltip corner radius.
--leverui-chart-tooltip-shadowMedium shadowTooltip shadow.
--leverui-chart-tooltip-font-size12pxTooltip text size.

Classes

Root: .leverui-radar-chart.

Parts, each prefixed with .leverui-radar-chart__: svg, grid, ring, spoke, angle-label, radius-label, series, shape, point, point-dot, point-label, legend, legend-item, legend-swatch.

Tooltip: .leverui-chart-tooltip. Parts, each prefixed with .leverui-chart-tooltip__: label, item, swatch, values, name, value.

Part attributes:

  • data-grid on the grid: the value of grid.
  • data-radar-series on each series: the series name.
  • data-radar-point on each point: the row's position, starting at 0.