Eunomia @eunomia/elements@eunomia/charts@eunomia/core
AllAngularReactNext.jsJavaScriptVue
EunomiaSalmonForestVioletOceanGoldFireCustom…
🇬🇧 English🇫🇷 Français

Polar area chart

Polar charts

A polar area chart gives each category a wedge of the same angle, reaching out from the center as far as its value, against a value axis drawn as rings: visits per month, tickets per hour of the day, a score per skill. It takes the same data as the bar and line charts, its categories becoming the wedges. Hovering a wedge, or moving along them with the arrow keys, moves it out and shows its value, and a click can open a modal with its details.

Dependencies

eun-skeleton · while loading eun-modal · if details is set
Overview API Examples Accessibility

When to use

Reach for a polar area chart to compare a handful to a dozen categories that go round, such as the months of a year or the hours of a day, or to give a profile a more striking look than bars, such as a score per skill. Every wedge has the same angle, so unlike a pie chart, its values don't need to add up to a whole: they're read against the rings, from zero at the center. Since the eye reads the wedges' areas, which grow with the square of their radius, a bar chart compares values more precisely; to compare several series on the same categories, use a radar chart.

The data follows the contract shared by every chart, see Charts for its fields.

Install & usage

npm install @eunomia/elements @eunomia/charts
import "@eunomia/charts/polar-area-chart.js";
<eun-polar-area-chart label="Visits per month"></eun-polar-area-chart>

<script type="module">
  const chart = document.querySelector("eun-polar-area-chart");
  chart.data = {
    categories: [
      { key: "jan", label: "January" },
      { key: "feb", label: "February" },
      { key: "mar", label: "March" },
      { key: "apr", label: "April" },
    ],
    series: [
      { key: "visits", label: "Visits", values: [1120, 1640, 730, 310] },
    ],
  };
</script>

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

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.

@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.

Alternatives

You want… Prefers
Shares of a whole, rather than values read against an axis eun-pie-chart
Several series compared on the same categories eun-radar-chart
To compare values precisely eun-bar-chart

Guidance

  • Give every chart a label: it names the plot for assistive technology and captions its data table
  • Keep to categories with a natural order round the circle, such as months, hours or days of the week
  • Use point-labels past five or six categories, so each label sits by its wedge
  • Give categories that carry a meaning their own color
  • Negative values: they get no wedge
  • Comparing values that are close to each other: the areas exaggerate their gaps, prefer bars
  • Several series: only the first one is drawn, use a radar chart

Live testing

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.

Polar area chart <eun-polar-area-chart>

Attributes

NameTypeDefaultDescription
dataEunomiaChartData<S>EMPTY_DATAWhat the chart draws, as JSON: its categories and its series
point-labelsbooleanfalseWrites the categories' labels around the chart, each centered on its wedge, and only the outer ring's value up the twelve o'clock line. The legend is then hidden unless legend is visible
legend-positionEunomiaChartLegendPosition'start'How the legend's entries line up under the plot
hide-tooltipbooleanfalseShows no tooltip on hover or keyboard moves
hide-gridbooleanfalseDraws no rings
hide-value-axisbooleanfalseHides the values written up the twelve o'clock line
empty-labelstring | undefined—The text shown in place of the wedges while there are no categories
hide-empty-labelbooleanfalseShows no text while there are no categories
axis-maxnumber | undefined—A value the value axis reaches at least, such as 100 for percentages
minnumber | undefined—The exact value at the center, whatever the values
maxnumber | undefined—The exact value of the outer ring, whatever the values
formatIntl.NumberFormatOptions | undefined—The Intl.NumberFormat options the values are written with, as JSON
select-hintstring | undefined—The hint at the bottom of the tooltip while wedges are clickable
non-interactivebooleanfalseDraws the chart as a plain picture: no focus stop, no hover, no tooltip, no selection
integerbooleanfalseWhether values are counts: the value axis then never steps below 1.
localestring | undefined—The locale used to resolve dictionary and `Intl` formatting. Defaults to the shared default set via `setDefaultLocale()`, itself defaulting to `"en"`.
labelstring | undefined—The chart's accessible name, also the caption of its data table.
legendEunomiaChartLegend"auto"When the legend is shown — see EunomiaChartLegend.
fillbooleanfalseTakes 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).
loadingbooleanfalseShows a placeholder in place of the plot while the data loads.
refreshingbooleanfalseKeeps 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.
animatedbooleanfalseDraws the marks in once the chart is first seen.
selectablebooleanfalseMakes every category clickable, firing `eunchartselect`.
detailsbooleanfalseOpens a modal listing a category's values once it's clicked. Implies selectable.

Import the exact TypeScript type behind any property above, see Types.

Properties

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

NameTypeDefaultDescription
valueFormatterEunomiaChartValueFormatter | undefined—Writes a value in the tooltip, the details and the data table, in place of format. Property only
tickFormatterEunomiaChartTickFormatter | undefined—Writes a value of the value axis, in place of format. Property only
tooltipRendererEunomiaChartTooltipRenderer<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
resolvedLocalestring—This instance's own `locale` when set, the shared default locale otherwise.
dictionaryChartDictionary—This instance's locale-resolved chart strings.

Methods

NameReturnsDescription
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

NameDescription
detailsExtra 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}"
tooltipA <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

NameTypeDescription
eunchartselectChartSelectEventFired when a wedge 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.

CSS custom properties

NameDescription
--chart-heightSets the height of the plot, the chart's diameter following it, ignored with fill. 220px by default
--chart-min-heightSets the least height of the plot with fill. 80px by default
--chart-color-1Sets the color of the first category, and of every eighth one after it. The primary color by default
--chart-color-2Sets the color of the second category. The secondary color by default
--chart-color-3Sets the color of the third category
--chart-color-4Sets the color of the fourth category
--chart-color-5Sets the color of the fifth category
--chart-color-6Sets the color of the sixth category
--chart-color-7Sets the color of the seventh category
--chart-color-8Sets the color of the eighth category
--chart-wedge-opacitySets the opacity of the wedges, the hovered one being opaque. 0.8 by default
--chart-surface-colorSets the color of the surface the chart sits on, drawing the gaps between wedges and the backdrop of the values
--chart-slice-gapSets the width of the gap between two wedges. 2px by default
--chart-grid-colorSets the color of the rings
--chart-axis-colorSets the color of the values, of the categories' labels and of the legend
--chart-axis-font-sizeSets the font size of the values and of the categories' labels
--chart-tooltip-backgroundSets the background color of the tooltip
--chart-tooltip-colorSets the text color of the tooltip
--chart-focus-outline-colorSets the color of the plot's focus ring
--chart-animation-durationSets the duration of the entrance animation
--chart-refresh-opacitySets the opacity the wedges take while refreshing, their colors kept. 0.4 by default
--chart-refresh-highlight-colorSets the color of the shimmer sweeping the plot while refreshing

CSS shadow parts

NameDescription
plotThe svg the chart is drawn in
tooltipThe tooltip
legendThe legend
legend-itemAn entry of the legend, its swatch and its name
legend-swatchThe swatch of an entry of the legend
detailsThe details modal

Types

import type {
  EunomiaPolarAreaChartData,
  EunomiaPolarAreaChartSeries,
  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.

Data

A wedge per category

The categories become the wedges, from twelve o'clock clockwise, in the order they come in, each taking the same angle. A wedge reaches out as far as its value on the value axis, drawn as rings from zero at the center and written up the twelve o'clock line. Missing, zero and negative values get no wedge.

chart.data = {
  categories: [
    { key: "jan", label: "January", tick: "Jan" },
    { key: "feb", label: "February", tick: "Feb" },
    { key: "mar", label: "March", tick: "Mar" },
    { key: "apr", label: "April", tick: "Apr" },
    { key: "may", label: "May", tick: "May" },
    { key: "jun", label: "June", tick: "Jun" },
  ],
  series: [
    {
      key: "visits",
      label: "Visits",
      values: [1120, 1640, 730, 310, 1420, 940],
    },
  ],
};

Like a pie, the chart draws its first series. The others, or a series set to display: "none", show in the tooltip, the details and the data table, such as the orders behind the visits of the first example.

Centered point labels

point-labels writes each category's label around the chart, centered on its wedge, rather than in the legend: the chart shrinks to make room for them, and the hovered category's label is set in bold. Only the outer ring's value is then written, the inner ones sitting over the wedges. The legend is hidden, unless legend="visible". 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.

<eun-polar-area-chart
  point-labels
  label="Score per skill"
  axis-max="100"
></eun-polar-area-chart>

Value axis

The value axis runs from zero at the center to a round value past the largest one, on round steps. axis-max makes it reach at least a value, such as 100 for a score out of 100, and max sets its outer ring whatever the values, a wedge past it stopping on the ring. integer keeps its steps whole, for counts. hide-grid drops the rings, hide-value-axis their values, and tickFormatter writes them your own way.

<eun-polar-area-chart
  point-labels
  hide-grid
  hide-value-axis
  label="Score per skill"
></eun-polar-area-chart>

Colors

Wedges take the palette's colors in category order, --chart-color-1 (the primary color) first, slightly see-through (--chart-wedge-opacity) so the rings show beneath them. A category's own color takes over, any CSS color or a token, for categories that carry a meaning of their own.

categories: [
  { key: "low", label: "Low", color: "var(--eun-color-green-500)" },
  { key: "medium", label: "Medium", color: "var(--eun-color-secondary-500)" },
  { key: "high", label: "High", color: "var(--eun-color-red-500)" },
  { key: "critical", label: "Critical", color: "var(--eun-color-purple-500)" },
],

Legend and tooltip

The legend lists the categories, from two of them on (legend="auto", unless point-labels is set), always (visible) or never (hidden). legend-position lines it up from the start, in the center or against the end. hide-tooltip shows no tooltip, the hovered wedge still moving out.

The legend and the tooltip work the same on every chart: see Legend for its swatches, its appearance and how to build your own, and 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 wedges into a placeholder while new data loads, such as after a change of period: they're faded, their colors kept, under a shimmer, and the tooltip is off until the new data comes in.

Toggle loading
Load another period
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 wedges 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.

Replay
<!-- No animation, the default -->
<eun-polar-area-chart label="Visits per month"></eun-polar-area-chart>

<!-- Animated when first seen -->
<eun-polar-area-chart label="Visits per month" animated></eun-polar-area-chart>

Selection

Selectable wedges

selectable makes every wedge clickable, and every category activatable with Enter or Space once the plot is focused, firing eunchartselect with the category and its values. Hovering anywhere along a wedge's angle shows its tooltip; a click must land on the wedge itself.

Click a wedge.

chart.addEventListener("eunchartselect", (event) => {
  filterVisits(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 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.

<eun-polar-area-chart
  label="Visits per month"
  non-interactive
></eun-polar-area-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 shades of teal, with opaque wedges and wider gaps between them.

.visits-chart {
  --chart-height: 280px;
  --chart-color-1: #0f766e;
  --chart-color-2: #14b8a6;
  --chart-color-3: #5eead4;
  --chart-color-4: #0d9488;
  --chart-color-5: #2dd4bf;
  --chart-color-6: #99f6e4;
  --chart-wedge-opacity: 1;
  --chart-slice-gap: 4px;
  --chart-tooltip-background: #134e4a;
}
Variable Sets
--chart-height Sets the height of the plot, the chart's diameter following it
--chart-color-1 … -8 Sets the palette the categories take their color from, in order
--chart-wedge-opacity Sets the opacity of the wedges, the hovered one being opaque. 0.8 by default
--chart-slice-gap Sets the width of the gap between two wedges. 2px by default
--chart-surface-color Sets the color of the surface the chart sits on, drawing the gaps
--chart-grid-color Sets the color of the rings
--chart-axis-color Sets the color of the values, of the labels around the chart 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 wedges take while refreshing, their colors kept. 0.4 by default

Keyboard interactions

The plot is a single focus stop. Once focused, it shows the last category, and the arrow keys move along the others, in the order of the wedges.

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, the legend and the labels around the chart are aria-hidden or 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

Without point-labels, wedges are told apart by color only, so keep the legend shown, or write the labels around the chart, and give categories meaningful labels: the tooltip, the details and the data table name every value. Neighboring wedges are separated by a gap in the surface color, and each should keep a 3:1 contrast with the surface around the chart (WCAG 1.4.11): lower --chart-wedge-opacity with care.

  • WAI Web Accessibility Tutorials: Complex images
  • Understanding WCAG 2.2: Non-text contrast