Charts
Charts draw a set of values per category: a day, a month, a product, a team. They're plain web components, drawn in SVG at their own width, themed by the same tokens as the rest of the library, with no charting dependency. Every chart takes the same data, so switching a measure from bars to a line, or to a pie, is a matter of changing the tag.
The charts aren't part of @eunomia/elements: they ship in @eunomia/charts, installed and versioned separately, and are imported from it (@eunomia/charts/bar-chart.js, not @eunomia/elements/…). See
Install
npm install @eunomia/charts
It installs @eunomia/core with it, the tokens and themes every Eunomia
package shares. @eunomia/elements is only an optional peer dependency:
a chart needs it for its loading placeholder
(@eunomia/elements/skeleton.js) and its details modal
(@eunomia/elements/modal.js), nothing else. Import each chart you use
from the charts package, or all of them with import "@eunomia/charts":
import "@eunomia/charts/bar-chart.js";
import "@eunomia/charts/line-chart.js";
Chart list
Values per category drawn as bars, side by side or stacked, with a tooltip, keyboard navigation and an optional details modal.
Items placed on two value axes, each bubble sized by a third value such as revenue, with a tooltip, keyboard navigation and an optional details modal.
Bars and lines on the same categories, such as amounts against a target or a rate, with a secondary axis, a tooltip and keyboard navigation.
A whole split between categories around its total, on one or several rings, with each share in a tooltip, keyboard navigation and a details modal.
Values per category drawn as lines over a light wash, several series sharing the axis, with a tooltip, keyboard navigation and an optional details modal.
A whole shared out between a handful of categories, a slice each, with their shares in a tooltip, keyboard navigation and an optional details modal.
One equal-angle wedge per category, reaching as far as its value, labelled in a legend or around the chart, with keyboard navigation and a details modal.
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.
Choosing a chart
- Bar chart: compares amounts from one category to the next, such as orders per day or revenue per region. Several series stand side by side, or stack up into a total.
- Line chart: follows a measure over time, such as revenue per day or sessions per week. Several series share the axis, and a secondary one (a target, a forecast) can be faded or dashed.
- Pie chart: shares a whole out between a handful of categories, such as revenue per channel, when their shares matter more than their values.
- Doughnut chart: the same slices around their total, written in the middle, and several series compared as rings inside one another.
- Polar area chart: a wedge of the same angle per category, reaching out as far as its value, for categories that go round, such as months or hours, with their labels around the chart if need be.
- Radar chart: things compared on several measures of the same scale, each category a spoke and each series an outline, such as a product's profile across criteria.
- Combo chart: bars and lines on the same categories, such as amounts and their target or their rate, the line often read against a secondary axis.
- Bubble chart: items compared on three measures at once, placed along two value axes by the first two series and sized by the third.
There is no separate time chart: time is a property of the data, not of
the drawing. Build the categories of a period with timeCategories (see
below) and hand them to any chart.
Shared features
Some behaviors work the same on every chart, each with a page of its own:
When it shows, what it lists, its position and its swatches
What it shows, how its values are written, how to customize it
Opening it on a click, filling it, or using your own modal
Following the parent's width, setting a height, filling a card
The data contract
Every chart takes a single data object: the categories along the bottom
axis, and one or more series giving a value for each of them. On a pie
or a doughnut, the categories are the slices; on a polar area chart, the
wedges; on a radar chart, the spokes; on a bubble chart, the bubbles,
their first three series giving their position and size.
import type { EunomiaBarChartData } from "@eunomia/charts";
const data: EunomiaBarChartData = {
categories: [
{ key: "2026-11-03", label: "Tuesday, November 3", tick: "Nov 3" },
{ key: "2026-11-04", label: "Wednesday, November 4", tick: "Nov 4" },
{ key: "2026-11-05", label: "Thursday, November 5", tick: "Nov 5" },
],
series: [{ key: "orders", label: "Orders", values: [12, 9, null] }],
};
| Field | Type | Description |
|---|---|---|
categories[].key |
string |
Stable identifier, handed back by eunchartselect to look the category up in your own data |
categories[].label |
string |
Full wording, in the tooltip, the details modal and the data table read by screen readers |
categories[].color |
string, pie, doughnut, polar area and bubble only |
The color of its slices, its wedge or its bubble, the categories being the slices, the wedges or the bubbles. Defaults to the palette, in category order |
categories[].tick |
string, optional |
Short wording under the axis. Defaults to label |
series[].key |
string |
Stable identifier of the series |
series[].label |
string |
Its name, in the legend, the tooltip, the details modal and the data table |
series[].values |
(number | null)[] |
One value per category, in the same order. null, or a missing trailing value, is no value: no bar, a gap in a line |
series[].color |
string, optional |
Any CSS color, var() included. Defaults to the palette, --chart-color-1 to --chart-color-8 in series order. Pie and doughnut slices and polar area wedges take their category's color instead |
series[].axis |
"primary" | "secondary", optional |
The value axis the series is read against: the left one (default), or one of its own on the right |
series[].display |
"bar" | "line" | "points" | "none", optional |
How the series is drawn. Bars by default on a bar chart, a line on a line chart, bars for the first series and lines for the others on a combo chart. none draws nothing, its values only in the tooltip, the details and the data table. On a pie, doughnut or polar area, only none applies; on a radar, line, points and none |
series[].stack |
string, bar and combo only |
Series sharing a stack are drawn on top of each other in one column |
series[].area |
boolean, lines only |
Fills the space between the line and zero with a light wash. Defaults to true for a single series, false otherwise; on a radar, fills the outline, true by default |
series[].faded |
boolean, line and radar only |
Draws the line semi-transparent, for a secondary figure such as a target or a forecast |
series[].dashed |
boolean, line and radar only |
Draws the line dashed |
series[].curve |
"linear" | "smooth" | "step", lines only |
How the line joins its values: straight, a smooth curve that never overshoots them, or steps. Defaults to the chart's curve |
series[].points |
"auto" | "all" | "hover" | "none", lines only |
When its values get a point: on the hovered category (and the last value on a line chart), on every value, on hover only, or never. Defaults to the chart's points |
series[].pointShape |
"circle" | "square" | "diamond" | "triangle" |
The shape of its points, and of its swatch when drawn as points. Defaults to the chart's point-shape |
series[].pointSize |
number, lines and points only |
The size of its points, in pixels across. Defaults to the chart's point-size, 6 |
Replace the whole object to update a chart, never mutate it in place: the
chart redraws when data changes, not when an array inside it does. In
plain HTML, data can also be written as a JSON attribute.
Everything around the data is shared by every chart too:
labelnames the chart for assistive technology and captions its data table;formattakesIntl.NumberFormatoptions (a currency, a percentage, a unit), the value axis writing them in compact notation, andvalueFormattertakes over entirely when a format isn't enough;legendshows the legend from two series on (auto), always (visible) or never (hidden), andlegend-positionlines it up from thestart, in thecenteror against theend;filltakes the parent's height rather than--chart-height;hide-tooltipdrops the tooltip;loadingandrefreshingcover the data's loading, the latter turning the current marks into a placeholder until new data comes in, andanimateddraws the marks in once the chart is first seen;empty-labelandhide-empty-labelshape a chart without data;tooltipRenderer, set as a property, writes the tooltip's content from the hovered category and its values, written and colored;selectablefireseunchartselecton a click, anddetailsopens a modal listing the clicked category's values.
The others shape an axis, a grid or a line, so they only exist on the charts that draw one:
- on every chart but the pie and the doughnut, which have no axis,
tickFormatterwrites the axis ticks, andhide-gridandhide-value-axisdrop the grid and the value axis, down to a sparkline; - on the bar, line, combo and radar charts,
hide-category-axisdrops the category axis too; - on the bar, line, combo, polar area and radar charts,
integerandaxis-maxshape the value axis, which always includes zero; - on the bar, line and combo charts,
axis-minsets the bottom of the value axis,secondary-formatwrites the values of the series on the secondary axis, andcurve(linear,smooth,step) chooses how lines join their values; - on the bar, line, combo and radar charts,
points,point-shapeandpoint-sizechoose when and how the values are marked; - on the bar, line, combo and bubble charts,
hide-empty-griddrops the grid of a chart without data.
Charts over time
timeCategories(from, to, unit) builds one category per hour, day, week,
month or year of a period, both ends included and with no gap, so a day
without data still gets its place on the axis. Each category's key is
the interval's start in local time (2026-11-05), its tick a short date
and its label a full one, written in the chart's locale.
import { timeCategories } from "@eunomia/charts/chart-utils.js";
const categories = timeCategories("2026-11-01", "2026-11-30", "day", {
locale: "en",
});
const byDay = new Map(rows.map((row) => [row.date, row.orders]));
chart.data = {
categories,
series: [
{
key: "orders",
label: "Orders",
values: categories.map(({ key }) => byDay.get(key) ?? 0),
},
],
};
@eunomia/charts/chart-utils.js registers no component, so it can run
on the server, such as in a Server Component preparing the data.
| Unit | Key | Tick (English) | Label (English) |
|---|---|---|---|
hour |
2026-11-05T14:00 |
2:00 PM | Thursday, November 5 at 2:00 PM |
day |
2026-11-05 |
Nov 5 | Thursday, November 5 |
week |
2026-11-02 |
Nov 2 | Week of November 2 |
month |
2026-11 |
Nov | November 2026 |
year |
2026 |
2026 | 2026 |
Weeks start on Monday. The year is added to the ticks and labels wherever
the period spans more than one, and tick/label options replace the
default Intl.DateTimeFormat options.
Theming
Series take their colors from --chart-color-1 to --chart-color-8,
the primary and secondary colors first, then the decorative palette, so a
chart follows the active theme on its own. Set them on any ancestor to
give a whole dashboard its own palette:
.dashboard {
--chart-color-1: var(--eun-color-primary-600);
--chart-color-2: var(--eun-color-green-500);
--chart-height: 260px;
}
A chart drawn on a card of another color should get that color as
--chart-surface-color, which rings the markers and softens the hovered
bar.