# Radar chart

> Several measures of the same items on spokes from the center, one outline per series, with a tooltip, keyboard navigation and an optional details modal.

Source: https://eunomia-ds.com/charts/radar-chart/

A radar chart lays its categories out as spokes going out from the center, and draws each series as an outline joining its value on every spoke: a product's profile across criteria, a team's skills, this year against last on every indicator. It takes the same data as the bar and line charts, its categories becoming the spokes. Hovering near a spoke, or moving along them with the arrow keys, marks it and lists every series' value on it, and a click can open a modal with its details.

Dependencies

- [eun-skeleton · while loading](https://eunomia-ds.com/components/skeleton/)
- [eun-modal · if details is set](https://eunomia-ds.com/components/modal/)

## Overview

### When to use

Reach for a radar chart to show the profile of one or a few things across several measures on the same scale, such as scores out of 100: where a product is strong and where it falls short, how two candidates or two periods compare criterion by criterion. It reads best with three to a dozen categories and up to three or four series. To compare exact values, or measures of different units, prefer a [bar chart](https://eunomia-ds.com/charts/bar-chart/); for a single series of values that go round, such as months, a [polar area chart](https://eunomia-ds.com/charts/polar-area-chart/).

The data follows the contract shared by every chart, see [Charts](https://eunomia-ds.com/charts/) for its fields.

### Install & usage

**HTML / any framework:**

```bash
npm install @eunomia/elements @eunomia/charts
```

```js
import "@eunomia/charts/radar-chart.js";
```

```html
<eun-radar-chart label="Models compared" axis-max="100"></eun-radar-chart>

<script type="module">
  const chart = document.querySelector("eun-radar-chart");
  chart.data = {
    categories: [
      { key: "speed", label: "Speed" },
      { key: "comfort", label: "Comfort" },
      { key: "range", label: "Range" },
      { key: "safety", label: "Safety" },
      { key: "price", label: "Price" },
    ],
    series: [
      { key: "a", label: "Model A", values: [82, 64, 71, 90, 55] },
      { key: "b", label: "Model B", values: [61, 88, 58, 74, 83] },
    ],
  };
</script>
```

Importing the file registers `<eun-radar-chart>` as a custom element, with no further setup needed. It draws as large as `--chart-height` and its width allow, centered, the labels around it included. Import `@eunomia/elements/skeleton.js` too to show a placeholder while `loading`, and `@eunomia/elements/modal.js` to use `details`.

**React:**

```bash
npm install @eunomia/elements @eunomia/charts
```

```jsx
import { useMemo } from "react";
import "@eunomia/charts/radar-chart.js";

function ModelsChart({ criteria, models }) {
  const data = useMemo(
    () => ({
      categories: criteria.map((criterion) => ({
        key: criterion.id,
        label: criterion.name,
      })),
      series: models.map((model) => ({
        key: model.id,
        label: model.name,
        values: criteria.map((criterion) => model.scores[criterion.id] ?? null),
      })),
    }),
    [criteria, models],
  );

  return <eun-radar-chart label="Models compared" axis-max="100" data={data} />;
}
```

React 19 sets `data` as a property. On React 18, set it through a ref, or with `eunProps` from `@eunomia/elements/react`.

**Vue:**

```bash
npm install @eunomia/elements @eunomia/charts
```

```html
<script setup>
  import "@eunomia/charts/radar-chart.js";

  defineProps({ data: Object });
</script>

<template>
  <eun-radar-chart label="Models compared" axis-max="100" :data="data" />
</template>
```

**Angular:**

```bash
npm install @eunomia/elements @eunomia/charts
```

```ts
import { CUSTOM_ELEMENTS_SCHEMA, Component, Input } from "@angular/core";
import type { EunomiaRadarChartData } from "@eunomia/charts";
import "@eunomia/charts/radar-chart.js";

@Component({
  selector: "app-models-chart",
  template: `
    <eun-radar-chart
      label="Models compared"
      axis-max="100"
      [data]="data"
      (eunchartselect)="open($event.category.key)"
    ></eun-radar-chart>
  `,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class ModelsChartComponent {
  @Input() data!: EunomiaRadarChartData;
  open(key: string) {}
}
```

#### Server rendering

Before it upgrades, a chart is an empty tag. Import `chart-ssr.css` with the page's other styles to reserve its room from the first paint: `--chart-height`, plus a row for the legend once `legend="visible"`, or 100% of its parent's height with `fill`.

```css
@import "@eunomia/charts/chart-ssr.css";
```

Without a bundler, link `node_modules/@eunomia/charts/dist/ssr/chart-ssr.css` in the page's `<head>`. Two cases still shift the page on upgrade: a legend left to `legend="auto"`, which only shows with the data, and a legend that wraps onto more than one row. See [Size: Before it upgrades](https://eunomia-ds.com/charts/size/#before-it-upgrades).

### Alternatives

| You want… | Prefers |
| --- | --- |
| To compare exact values, or measures of different units | `eun-bar-chart` |
| A single series of values that go round, such as months | `eun-polar-area-chart` |
| Things compared on two or three measures, placed on axes | `eun-bubble-chart` |

### Guidance

> **Recommended**
>
> - Give every chart a `label`: it names the plot for assistive technology and captions its data table
> - Keep every category on the same scale, such as a score out of 100, and set `axis-max` to it
> - Keep to three or four series, a reference such as a target drawn `faded` and `dashed`
> - Order the categories so related ones sit side by side

> **Avoid**
>
> - Measures of different units or magnitudes on the same chart: they share one value axis
> - Fewer than three categories: the outline flattens into a line
> - Reading the outline's area as a total: it depends on the order of the categories

## API

### Properties

`data` and `label` are the two you'll always set. The data's own fields, shared with every chart, are listed on [Charts: The data contract](https://eunomia-ds.com/charts/#the-data-contract).

### Radar chart `<eun-radar-chart>`

#### Attributes

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| data | EunomiaChartData<S> | EMPTY_DATA | What the chart draws, as JSON: its categories and its series |
| grid-shape | 'polygon' \| 'circle' | 'polygon' | The shape of the gridlines: polygons joining the spokes, or circles |
| legend-position | EunomiaChartLegendPosition | 'start' | How the legend's entries line up under the plot |
| hide-tooltip | boolean | false | Shows no tooltip on hover or keyboard moves |
| hide-grid | boolean | false | Draws no gridlines and no spokes |
| hide-value-axis | boolean | false | Hides the values written up the twelve o'clock spoke |
| hide-category-axis | boolean | false | Hides the categories' labels around the chart, the plot taking their room |
| empty-label | string \| undefined | — | The text shown in place of the outlines while there are no categories |
| hide-empty-label | boolean | false | Shows no text while there are no categories |
| axis-max | number \| undefined | — | A value the value axis reaches at least, such as 100 for percentages or 5 for a rating |
| min | number \| undefined | — | The exact value at the center, whatever the values |
| max | number \| undefined | — | The exact value of the outer ring, whatever the values |
| format | Intl.NumberFormatOptions \| undefined | — | The Intl.NumberFormat options the values are written with, as JSON |
| points | 'auto' \| 'all' \| 'hover' \| 'none' | 'all' | When the values of the outlines get a point: all on every value, larger on the hovered spoke, hover (or auto) on the hovered spoke only, none never. A series' own points takes over |
| point-shape | 'circle' \| 'square' \| 'diamond' \| 'triangle' | 'circle' | The shape of the points. A series' own pointShape takes over |
| point-size | number | 6 | The size of the points, in pixels across, the one on the hovered spoke 2 pixels larger. A series' own pointSize takes over |
| select-hint | string \| undefined | — | The hint at the bottom of the tooltip while spokes are clickable |
| non-interactive | boolean | false | Draws the chart as a plain picture: no focus stop, no hover, no tooltip, no selection |
| integer | boolean | false | Whether values are counts: the value axis then never steps below 1. |
| locale | string \| undefined | — | The locale used to resolve dictionary and `Intl` formatting. Defaults to the shared default set via `setDefaultLocale()`, itself defaulting to `"en"`. |
| label | string \| undefined | — | The chart's accessible name, also the caption of its data table. |
| legend | EunomiaChartLegend | "auto" | When the legend is shown — see EunomiaChartLegend. |
| fill | boolean | false | Takes the whole height of the chart, rather than `--chart-height`: the plot stretches to what's left once the legend is laid out, and redraws whenever that changes. The chart takes 100% of its parent's height by default; size it like any block otherwise (`height`, `flex: 1`, a grid cell). |
| loading | boolean | false | Shows a placeholder in place of the plot while the data loads. |
| refreshing | boolean | false | Keeps the plot shown as a placeholder while new data loads, such as after a change of period: the marks faded, their colors kept, under a shimmer, the axes kept, the tooltip off. |
| animated | boolean | false | Draws the marks in once the chart is first seen. |
| selectable | boolean | false | Makes every category clickable, firing `eunchartselect`. |
| details | boolean | false | Opens a modal listing a category's values once it's clicked. Implies selectable. |

Import the exact TypeScript type behind any property above, see [Types](https://eunomia-ds.com/guides/types/).

#### Properties

JS-only — no matching HTML attribute, set these from a script or a template binding.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| valueFormatter | EunomiaChartValueFormatter \| undefined | — | Writes a value in the tooltip, the details and the data table, in place of format. Property only |
| tickFormatter | EunomiaChartTickFormatter \| undefined | — | Writes a value of the value axis, in place of format. Property only |
| tooltipRenderer | EunomiaChartTooltipRenderer<S> \| undefined | — | Writes the content of the tooltip in place of the values and the category's label. Receives the category, the values of every series written and colored, and the total; returns a DOM node, a string shown as text or a Lit template, null keeping the default content. Property only |
| resolvedLocale | string | — | This instance's own `locale` when set, the shared default locale otherwise. |
| dictionary | ChartDictionary | — | This instance's locale-resolved chart strings. |

#### Methods

| Name | Returns | Description |
| --- | --- | --- |
| replayAnimation() | Promise<void> | Plays the entrance animation again, such as once new data is shown. Does nothing while the person asked to reduce motion. |

#### Slots

| Name | Description |
| --- | --- |
| details | Extra content shown in the details modal, below the category's values, such as the records behind them. Update it from eunchartselect. A <template slot="details"> is filled for the clicked category instead, as the tooltip's: data-field, data-each and data-bind-* attributes such as data-bind-href="/orders?day={key}" |
| tooltip | A <template> writing the content of the tooltip in plain HTML, in place of the values and the category's label: data-each="values" (or "drawn") repeats an element per series, data-field writes category, key, tick, total, and per series series, text, value or color. tooltipRenderer takes over when set. data-bind-<attr> writes an attribute, {category}, {key}, {tick} and {index} replaced |

#### Events

| Name | Type | Description |
| --- | --- | --- |
| eunchartselect | ChartSelectEvent | Fired when a spoke is clicked, or a category activated with Enter or Space, while selectable or details is set. Cancelable to keep the details modal from opening |

Every event above follows the same naming convention, covered in [Events](https://eunomia-ds.com/guides/events/).

#### CSS custom properties

| Name | Description |
| --- | --- |
| --chart-height | Sets the height of the plot, labels included, the chart's diameter following it, ignored with fill. 220px by default |
| --chart-min-height | Sets the least height of the plot with fill. 80px by default |
| --chart-color-1 | Sets the color of the first series, and of every eighth one after it. The primary color by default |
| --chart-color-2 | Sets the color of the second series. The secondary color by default |
| --chart-color-3 | Sets the color of the third series |
| --chart-color-4 | Sets the color of the fourth series |
| --chart-color-5 | Sets the color of the fifth series |
| --chart-color-6 | Sets the color of the sixth series |
| --chart-color-7 | Sets the color of the seventh series |
| --chart-color-8 | Sets the color of the eighth series |
| --chart-surface-color | Sets the color of the surface the chart sits on, ringing the points and backing the values |
| --chart-grid-color | Sets the color of the gridlines and the spokes |
| --chart-axis-color | Sets the color of the values, of the categories' labels, of the hovered spoke and of the legend |
| --chart-axis-font-size | Sets the font size of the values and of the categories' labels |
| --chart-line-width | Sets the width of the outlines. 2px by default |
| --chart-area-opacity | Sets the opacity of the wash inside an outline. 0.15 by default |
| --chart-tooltip-background | Sets the background color of the tooltip |
| --chart-tooltip-color | Sets the text color of the tooltip |
| --chart-focus-outline-color | Sets the color of the plot's focus ring |
| --chart-animation-duration | Sets the duration of the entrance animation |
| --chart-refresh-opacity | Sets the opacity the outlines take while refreshing, their colors kept. 0.4 by default |
| --chart-refresh-highlight-color | Sets the color of the shimmer sweeping the plot while refreshing |

#### CSS shadow parts

| Name | Description |
| --- | --- |
| plot | The svg the chart is drawn in |
| tooltip | The tooltip |
| legend | The legend |
| legend-item | An entry of the legend, its swatch and its name |
| legend-swatch | The swatch of an entry of the legend |
| details | The details modal |

### Types

```ts
import type {
  EunomiaRadarChartData,
  EunomiaRadarChartSeries,
  EunomiaChartGridShape,
  EunomiaChartPoints,
  EunomiaChartPointShape,
  EunomiaChartCategory,
  EunomiaChartLegend,
  EunomiaChartLegendPosition,
  EunomiaChartValueFormatter,
  EunomiaChartTickFormatter,
} from "@eunomia/charts";
import { ChartSelectEvent } from "@eunomia/charts";
```

`ChartSelectEvent` carries the selected `category`, its `index` in `data.categories`, and `values`: every series with its value on that category, `null` for none.

## Examples

### Data

#### A spoke per category, an outline per series

The categories become the spokes, from twelve o'clock clockwise, in the order they come in, each labelled at its end. Each series is an outline joining its value on every spoke, filled with a light wash and marked with a point on each value. A missing value (`null`) gets no point, the outline joining the values on either side of it.

```js
chart.data = {
  categories: [
    { key: "speed", label: "Speed" },
    { key: "comfort", label: "Comfort" },
    { key: "range", label: "Range" },
    { key: "safety", label: "Safety" },
    { key: "price", label: "Price" },
    { key: "design", label: "Design" },
  ],
  series: [
    { key: "a", label: "Model A", values: [82, 64, 71, 90, 55, 78] },
    { key: "b", label: "Model B", values: [61, 88, 58, 74, 83, 66] },
  ],
};
```

A label writes the category's `tick` when it has one, else its `label`, shortened with an ellipsis past about a quarter of the chart's width: give long categories a short `tick`, the tooltip and the data table keeping the full `label`.

#### A reference, points and hidden series

A series can be drawn `faded` and `dashed`, such as a target or an average, with `area: false` to leave it unfilled and `points: "none"` to drop its points. `display: "points"` draws a dot on each value only, in its `pointShape`, and `display: "none"` draws nothing, its values only in the tooltip, the details and the data table.

```js
series: [
  { key: "a", label: "Model A", values: [82, 64, 71, 90, 55, 78] },
  { key: "b", label: "Model B", values: [61, 88, 58, 74, 83, 66] },
  { key: "target", label: "Target", values: [70, 70, 70, 70, 70, 70], faded: true, dashed: true, area: false, points: "none" },
],
```

```js
series: [
  { key: "a", label: "Model A", values: [82, 64, 71, 90, 55, 78] },
  { key: "reviews", label: "Reviews", values: [74, 70, null, 85, 60, 81], display: "points", pointShape: "diamond" },
  { key: "tests", label: "Tests run", values: [12, 9, 14, 21, 6, 8], display: "none" },
],
```

`points` sets when the values get a point for every series: `all` (default), `hover` on the hovered spoke only, or `none`. `point-shape` and `point-size` set their shape and size. A series' own `points`, `pointShape` and `pointSize` take over.

#### Value axis

The value axis runs from zero at the center to a round value past the largest one, on round steps, written up the twelve o'clock spoke; it reaches below zero when a value does. `axis-max` makes it reach at least a value, such as 100 for a score out of 100, and `min` and `max` set the center and the outer ring whatever the values, to zoom in on the values' range: anything past them is drawn on the center or on the ring. `integer` keeps its steps whole, for counts, and `tickFormatter` writes its values your own way.

```html
<eun-radar-chart
  label="Models compared, from 50 to 100"
  min="50"
  max="100"
></eun-radar-chart>
```

#### Grid

The gridlines are polygons joining the spokes; `grid-shape="circle"` draws circles instead. `hide-grid` drops the gridlines and the spokes, `hide-value-axis` the values up the twelve o'clock spoke, and `hide-category-axis` the labels around the chart, the plot taking their room.

```html
<eun-radar-chart
  grid-shape="circle"
  label="Models compared"
  axis-max="100"
></eun-radar-chart>
<eun-radar-chart
  hide-value-axis
  hide-category-axis
  legend="hidden"
  label="Model A"
></eun-radar-chart>
```

### Legend and tooltip

The legend lists the drawn series, from two of them on (`legend="auto"`), always (`visible`) or never (`hidden`), with a swatch drawn like the series. `legend-position` lines it up from the `start`, in the `center` or against the `end`. The tooltip lists every series' value on the hovered spoke; `hide-tooltip` shows none, the spoke still being marked.

The legend and the tooltip work the same on every chart: see [Legend](https://eunomia-ds.com/charts/legend/) for its swatches, its appearance and how to build your own, and [Tooltip](https://eunomia-ds.com/charts/tooltip/) for its hint, its appearance and writing its content in HTML or JavaScript.

### States

#### Loading and refreshing

`loading` shows a round placeholder while the first data loads. `refreshing` turns the current outlines into a placeholder while new data loads, such as after a change of period: they're faded, their colors kept, under a shimmer, the grid kept, and the tooltip is off until the new data comes in.

```js
chart.refreshing = true;
chart.data = await fetchPeriod(period);
chart.refreshing = false;
```

#### Empty

While there are no categories, the chart draws its rings and writes "No data". `empty-label` writes your own message, `hide-empty-label` none.

#### Entrance animation

By default, a chart is drawn at once, with no motion: the right choice for a dashboard refreshed often, or for one chart among many on a page.

`animated` grows the outlines out from the center once the chart is first seen. `replayAnimation()` plays it again. It's skipped when the person asked their system to reduce motion.

```html
<!-- No animation, the default -->
<eun-radar-chart label="Models compared"></eun-radar-chart>

<!-- Animated when first seen -->
<eun-radar-chart label="Models compared" animated></eun-radar-chart>
```

### Selection

#### Selectable spokes

`selectable` makes every spoke clickable, and every category activatable with Enter or Space once the plot is focused, firing `eunchartselect` with the category and every series' value on it. A click picks the spoke nearest to it.

```js
chart.addEventListener("eunchartselect", (event) => {
  showReviews(event.category.key);
});
```

#### Details modal

`details` opens a modal on click, headed by the category's label and listing the value of every series. It needs `eun-modal` to be registered, and takes extra content through its `details` slot.

The modal works the same on every chart: see [Details modal](https://eunomia-ds.com/charts/details/) for what it lists, content of your own in HTML or from JavaScript, opening your own modal instead, and its appearance.

#### Non-interactive

`non-interactive` draws the chart as a plain picture: no focus stop, no hover, no tooltip and no selection, even with `selectable` or `details`. It fits a small chart in a table cell or a card, where the row or the card already takes the click. The plot keeps its accessible name and its data table. See [Size: Small charts](https://eunomia-ds.com/charts/size/#small-charts).

```html
<eun-radar-chart
  label="Models compared on six criteria"
  non-interactive
></eun-radar-chart>
```

### Customization

#### Custom appearance

The custom properties below restyle the chart, and its parts (`plot`, `tooltip`, `legend`, `details`) take any other rule. Here a taller chart in teal and amber, with thicker outlines and a deeper wash.

```css
.models-chart {
  --chart-height: 320px;
  --chart-color-1: #0f766e;
  --chart-color-2: #d97706;
  --chart-line-width: 3px;
  --chart-area-opacity: 0.3;
  --chart-tooltip-background: #134e4a;
}
```

| Variable | Sets |
| --- | --- |
| `--chart-height` | Sets the height of the plot, labels included, the chart's diameter following it |
| `--chart-color-1` … `-8` | Sets the palette the series take their color from, in order |
| `--chart-line-width` | Sets the width of the outlines. 2px by default |
| `--chart-area-opacity` | Sets the opacity of the wash inside an outline. 0.15 by default |
| `--chart-surface-color` | Sets the color of the surface the chart sits on, ringing the points |
| `--chart-grid-color` | Sets the color of the gridlines and the spokes |
| `--chart-axis-color` | Sets the color of the values, of the labels, of the hovered spoke and of the legend |
| `--chart-axis-font-size` | Sets the font size of the values and of the labels around the chart |
| `--chart-tooltip-background` | Sets the background color of the tooltip |
| `--chart-tooltip-color` | Sets the text color of the tooltip |
| `--chart-focus-outline-color` | Sets the color of the plot's focus ring |
| `--chart-animation-duration` | Sets the duration of the entrance animation |
| `--chart-refresh-opacity` | Sets the opacity the outlines take while refreshing, their colors kept. 0.4 by default |

## Accessibility

### Keyboard interactions

The plot is a single focus stop. Once focused, it shows the last category, and the arrow keys move along the others, clockwise or anticlockwise round the spokes.

| Key | Action |
| --- | --- |
| `Tab` / `Shift+Tab` | Moves focus to or away from the plot |
| `ArrowLeft` / `ArrowRight` | Shows the previous or the next category |
| `Home` / `End` | Shows the first or the last category |
| `Enter` / `Space` | Selects the shown category, while `selectable` or `details` is set |

### Aria attributes and rules

- The plot is an `svg` with `role="img"`, named by `label`. Give every chart one.
- Every value stays reachable in a visually hidden table, captioned by `label`, a row per category and a column per series. Screen reader users read the data there rather than through the drawing.
- Moving along the categories with the keyboard announces each one through a polite live region, its label followed by its values.
- The tooltip and the legend are `aria-hidden`, and the labels around the chart are part of the drawing: they repeat what the table already holds.
- While `refreshing`, the plot is marked `aria-busy`.
- `animated` is skipped when the person asked their system to reduce motion.
- With `non-interactive`, the plot is no focus stop and reacts to neither the pointer nor the keyboard; its accessible name and its data table are still read by screen readers.

### Color and contrast

Series are told apart by color, so keep the legend shown with several of them, and set a secondary one apart by more than its color: `faded`, `dashed` or drawn as `points` in a shape of its own. Each outline should keep a 3:1 contrast with the surface around the chart (WCAG 1.4.11); the default palette does on the default themes, check your own colors when you set them.

### Reference links

- [WAI Web Accessibility Tutorials: Complex images](https://www.w3.org/WAI/tutorials/images/complex/)
- [Understanding WCAG 2.2: Non-text contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)
