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

Bar chart

Cartesian charts

A bar chart draws a value per category as a bar rising from zero: orders per day, revenue per month, tickets per team. Several series stand side by side in each category, or on top of each other to add up into a total. Hovering a category, or moving along them with the arrow keys, shows its values in a tooltip, 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 bar chart to compare amounts from one category to the next: counts, sums, a figure per day, per month, per region. The length of a bar reads at a glance, and bars make each category a distinct, clickable target. Prefer a line chart to show how a measure evolves over many intervals, where the shape of the curve matters more than each value.

The data follows the contract shared by every chart, see Charts for its fields and for timeCategories, which builds the categories of a period.

Install & usage

npm install @eunomia/elements @eunomia/charts
import "@eunomia/charts/bar-chart.js";
<eun-bar-chart label="Orders per day" integer></eun-bar-chart>

<script type="module">
  const chart = document.querySelector("eun-bar-chart");
  chart.data = {
    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: [4, 7, 5] }],
  };
</script>

Importing the file registers <eun-bar-chart> as a custom element, with no further setup needed. It draws at its own width, so give it room the way you would an image: in a card, a grid cell, a flex item with min-width: 0. 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
To follow a measure over many intervals, where the shape of the curve matters most eun-line-chart
Amounts as bars with a target or a rate drawn as a washed, faded or dashed line eun-combo-chart
To list exact values, to be read, sorted or compared one by one eun-table

Guidance

  • Give every chart a label: it names the plot for assistive technology and captions its data table
  • Set integer for counts, so the axis never shows 2.5 orders
  • Build the categories of a period with timeCategories, so a day without data still gets its place, at zero
  • Stack series only when their total means something, such as online and in-store orders adding up to all orders
  • Keep to a few series: past four or five side by side, bars get too thin to compare
  • Mixing measures of different units on one axis, such as orders and revenue: read the second one against the secondary axis
  • Mutating data in place: replace the object, the chart only redraws when it changes
  • Relying on color alone to tell series apart: keep the legend, and give series meaningful labels

Live testing

Properties

data and label are the two you'll always set. The data's own fields, shared with the line chart, are listed on Charts: The data contract.

Bar chart <eun-bar-chart>

Attributes

NameTypeDefaultDescription
dataEunomiaChartData<S>EMPTY_DATAWhat the chart draws, as JSON: its categories and its series
bar-radiusnumber4The corner radius of a bar's outer end, in pixels: its top, or its bottom below zero, a stack rounded at its ends only. 0 draws square bars
bar-max-widthnumber24The widest a bar may be, in pixels. Bars narrow down to fit their category, never below 2 pixels
bar-gapnumber2The gap between bars standing side by side in a category, in pixels, never more than a tenth of the category's room
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 gridlines
hide-value-axisbooleanfalseHides the labels of the value axes
hide-category-axisbooleanfalseHides the labels of the categories under the plot
empty-labelstring | undefined—The text shown in place of the marks while there are no categories
hide-empty-labelbooleanfalseShows no text while there are no categories
hide-empty-gridbooleanfalseDraws no gridlines and no value labels while there are no categories
axis-minnumber | undefined—A value the value axis reaches at least, below zero
axis-maxnumber | undefined—A value the value axis reaches at least, above zero, such as 100 for percentages
minnumber | undefined—The exact lower end of the value axis, anything below it cut off
maxnumber | undefined—The exact upper end of the value axis, anything above it cut off
secondary-minnumber | undefined—The exact lower end of the secondary value axis
secondary-maxnumber | undefined—The exact upper end of the secondary value axis
decimationEunomiaChartDecimation'lttb'How the series drawn as lines or points thin out their values once there are too many
decimation-samplesnumber | undefined—How many values a line keeps once thinned out, across the whole plot
formatIntl.NumberFormatOptions | undefined—The Intl.NumberFormat options the values are written with, as JSON
secondary-formatIntl.NumberFormatOptions | undefined—The Intl.NumberFormat options of the series on the secondary axis, as JSON
curveEunomiaChartCurve'linear'How the series drawn as lines join their values: straight, a smooth curve that never overshoots them, or steps
pointsEunomiaChartPoints'auto'When the values of the series drawn as lines get a point
point-shapeEunomiaChartPointShape'circle'The shape of the points
point-sizenumber | undefined6The size of the points, in pixels across
select-hintstring | undefined—The hint at the bottom of the tooltip while categories are clickable. Defaults to the localized string when details is set (English: "Click to see the details"), to none otherwise
non-interactivebooleanfalseDraws the chart as a plain picture: no focus stop, no hover, no tooltip, no selection
stackedbooleanfalseStacks every series without a stack of its own in a single column per category
integerbooleanfalseWhether values are counts: the primary 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 a value axis, in place of format. Receives the value and the axis, primary or secondary. 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 category is clicked, or 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, axis labels included, 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 series, and of every eighth one after it. The primary color by default
--chart-color-2Sets the color of the second series. The secondary color by default
--chart-color-3Sets the color of the third series
--chart-color-4Sets the color of the fourth series
--chart-color-5Sets the color of the fifth series
--chart-color-6Sets the color of the sixth series
--chart-color-7Sets the color of the seventh series
--chart-color-8Sets the color of the eighth series
--chart-surface-colorSets the color of the surface the chart sits on, mixed into the hovered bars
--chart-grid-colorSets the color of the gridlines and of the hovered category's band
--chart-bar-border-widthSets the width of the bars' border. None by default
--chart-bar-border-colorSets the color of the bars' border. The surface color by default, which sets the bars apart
--chart-axis-colorSets the color of the axis labels and of the legend
--chart-axis-font-sizeSets the font size of the axis 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 marks 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 {
  EunomiaBarChartData,
  EunomiaBarChartSeries,
  EunomiaChartCategory,
  EunomiaChartLegend,
  EunomiaChartLegendPosition,
  EunomiaChartAxis,
  EunomiaChartDisplay,
  EunomiaChartValueFormatter,
  EunomiaChartTickFormatter,
  EunomiaChartCurve,
  EunomiaChartPoints,
  EunomiaChartPointShape,
  EunomiaChartTooltipRenderer,
} 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.

Series

Single series

One value per category, here the orders of each day of a fortnight, built with timeCategories. A single series needs no legend: the card around the chart names the measure.

import { timeCategories } from "@eunomia/charts/chart-utils.js";

const categories = timeCategories("2026-11-03", "2026-11-16", "day");
chart.data = {
  categories,
  series: [{ key: "orders", label: "Orders", values: orders }],
};

Side by side

Several series stand side by side in each category, the legend appearing on its own from two series on.

chart.data = {
  categories: quarters,
  series: [
    { key: "2025", label: "2025", values: [42, 51, 38, 64] },
    { key: "2026", label: "2026", values: [48, 57, 49, 71] },
  ],
};

Stacked

stacked piles the series up into one column per category, the tooltip, the details and the data table adding their total.

<eun-bar-chart label="Orders per channel" integer stacked></eun-bar-chart>

Three series and more

Side by side, every series gets its own bar in each category, here three years compared quarter by quarter, the palette giving each its color in order. Stacked, the columns pile up as many series as needed, here four channels, the tooltip still adding their total.

chart.data = {
  categories: quarters,
  series: [
    { key: "2024", label: "2024", values: [36, 44, 31, 52] },
    { key: "2025", label: "2025", values: [42, 51, 38, 64] },
    { key: "2026", label: "2026", values: [48, 57, 49, 71] },
  ],
};

Past four or five series side by side, the bars get too thin to compare: stack them, or split the chart in two.

Several stacks

Give series a stack to pile up only those sharing it, the stacks standing side by side: here new and returning customers, one stack per year.

chart.data = {
  categories: quarters,
  series: [
    {
      key: "new-2025",
      label: "New, 2025",
      values: [12, 18, 15, 22],
      stack: "2025",
    },
    {
      key: "back-2025",
      label: "Returning, 2025",
      values: [20, 24, 19, 30],
      stack: "2025",
    },
    {
      key: "new-2026",
      label: "New, 2026",
      values: [16, 21, 20, 25],
      stack: "2026",
    },
    {
      key: "back-2026",
      label: "Returning, 2026",
      values: [24, 27, 25, 36],
      stack: "2026",
    },
  ],
};

Negative values

Negative values fall below zero, the axis extending to fit them.

Categories that aren't periods

Categories can be anything: products, regions, teams. Give each a key and a label, and a short tick only when the label is too long for the axis.

chart.data = {
  categories: [
    { key: "chair", label: "Office chair" },
    { key: "desk", label: "Standing desk" },
    { key: "lamp", label: "Desk lamp" },
  ],
  series: [{ key: "sold", label: "Units sold", values: [184, 96, 142] }],
};

Axes and displays

Secondary axis and mixed displays

A series with axis: "secondary" is read against a value axis of its own on the right, for a measure of another unit or magnitude, here a conversion rate next to order counts. secondary-format writes its values and its labels.

display changes how a series is drawn: line or points over the bars, such as a target or a rate, or none to leave it undrawn while its values stay in the tooltip, the details and the data table (here the visits). A none series is left out of the legend, and doesn't stretch its axis unless nothing else is drawn on it: alone on the secondary axis, it gets a scale of its own without being drawn.

<eun-bar-chart
  label="Orders and conversion per quarter"
  integer
  secondary-format='{"style":"percent","maximumFractionDigits":1}'
></eun-bar-chart>
series: [
  { key: "orders", label: "Orders", values: [420, 510, 380, 640] },
  { key: "target", label: "Target", values: [450, 450, 500, 550], display: "line" },
  { key: "rate", label: "Conversion", values: [0.031, 0.036, 0.028, 0.042], axis: "secondary", display: "points" },
  { key: "visits", label: "Visits", values: [13500, 14200, 13600, 15200], display: "none" },
],

A series drawn as a line or as points takes the curve, points, point-shape and point-size of the chart, or its own (curve, points, pointShape, pointSize), as on a line chart: a target in steps, a rate marked with diamonds.

tickFormatter receives the axis as its second argument, primary or secondary, and valueFormatter the series, to tell them apart.

Hiding the grid and the axes

hide-grid draws no gridlines, hide-value-axis and hide-category-axis drop the labels on the side and under the plot, the bars taking their room. Together, they make a compact chart for a card or a table cell, its values still in the tooltip.

<eun-bar-chart
  label="Orders per day"
  integer
  hide-grid
  hide-value-axis
  hide-category-axis
  style="--chart-height: 64px"
></eun-bar-chart>

Values

Formatting

format takes Intl.NumberFormat options, applied in the chart's locale: values are written in full in the tooltip, the details and the data table, and in compact notation along the axis (€12K).

<eun-bar-chart
  label="Result per quarter"
  format='{"style":"currency","currency":"EUR","maximumFractionDigits":0}'
></eun-bar-chart>

When a format isn't enough, valueFormatter writes the values and tickFormatter the axis, both set as properties.

chart.valueFormatter = (value) => `${value} order${value > 1 ? "s" : ""}`;

Value axis

The axis always includes zero and steps on round values. axis-max (and axis-min) extend it to at least a given value, such as 100% for a rate.

<eun-bar-chart
  label="Conversion per quarter"
  axis-max="1"
  format='{"style":"percent"}'
></eun-bar-chart>

min and max hold the axis between fixed bounds instead: it ends exactly on them, no longer reaches for zero, and a bar past them is cut off square. Set one alone to fix that end only. secondary-min and secondary-max do the same for the secondary axis. Bars starting above zero exaggerate the differences between them, so keep a lower bound for lines, or say so in the label.

<eun-bar-chart min="0.2" max="0.6" format='{"style":"percent"}'></eun-bar-chart>

Series drawn as lines or points over the bars thin out their values past about one per pixel; see decimation on the line chart.

Missing values

A null value, or a missing trailing one, draws no bar. The tooltip and the data table write it as "No value", distinct from a zero.

Legend and colors

Legend and tooltip

legend="auto", the default, shows the legend from two series on, visible always, a single series included, and hidden never. legend-position lines its entries up from the start, in the center or against the end. hide-tooltip shows no tooltip, the hovered category still being marked: with legend="hidden", the chart is drawn with nothing around it.

<eun-bar-chart
  label="Orders per quarter"
  legend-position="center"
></eun-bar-chart>
<eun-bar-chart
  label="Orders per quarter"
  hide-tooltip
  legend="hidden"
></eun-bar-chart>

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.

Colors

Series take the palette's colors in order, --chart-color-1 (the primary color) first. A series' own color takes over, any CSS color or a token.

series: [
  { key: "target", label: "Target", values: [40, 45, 50, 55], color: "var(--eun-color-grey-400)" },
  { key: "actual", label: "Actual", values: [42, 41, 56, 60], color: "#0f766e" },
],

States

Loading and refreshing

loading shows a placeholder the height of the chart while its first data loads. refreshing turns the current bars into a placeholder while new data loads, such as after a change of period: they're faded, their colors kept, under a shimmer, as rows are in a syncing table, the axes stay, 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

A chart without categories keeps its axis and writes "No data". empty-label writes your own message, hide-empty-label none, and hide-empty-grid drops the gridlines and the value labels, which mean nothing without data.

<eun-bar-chart
  label="Orders per day"
  empty-label="No order over this period"
  hide-empty-grid
></eun-bar-chart>

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 bars from zero, one after the other, once the chart is first seen. replayAnimation() plays it again, such as once a new period is shown. It's skipped when the person asked their system to reduce motion.

Replay
<!-- No animation, the default -->
<eun-bar-chart label="Orders per day"></eun-bar-chart>

<!-- Animated when first seen -->
<eun-bar-chart label="Orders per day" animated></eun-bar-chart>

Selection

Selectable categories

selectable makes every category clickable, and activatable with Enter or Space once the plot is focused, firing eunchartselect with the category and its values. select-hint adds a hint to the tooltip.

Click a day.

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

Details modal

details opens a modal on click, headed by the category's label and listing the value of every series, and their total when they're stacked. It needs eun-modal to be registered.

import "@eunomia/charts/bar-chart.js";
import "@eunomia/elements/modal.js";
<eun-bar-chart
  label="Orders per channel"
  integer
  stacked
  details
></eun-bar-chart>

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-bar-chart label="Orders per day" non-interactive></eun-bar-chart>

Customization

Bar shape

bar-radius sets the corner radius of a bar's outer end, 0 drawing square bars; bar-max-width caps how wide a bar may get; bar-gap sets the gap between bars side by side. --chart-bar-border-width and --chart-bar-border-color draw a border around every bar, the surface color by default, which sets the segments of a stack apart.

<eun-bar-chart
  label="Orders per quarter"
  bar-radius="0"
  bar-max-width="40"
  bar-gap="6"
></eun-bar-chart>

<eun-bar-chart
  label="Orders per channel"
  stacked
  bar-radius="12"
  style="--chart-bar-border-width: 2px"
></eun-bar-chart>

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 lighter gridlines, a rounded tooltip and the legend in the center.

.revenue-chart {
  --chart-height: 280px;
  --chart-color-1: #0f766e;
  --chart-color-2: #f59e0b;
  --chart-grid-color: #99f6e4;
  --chart-axis-color: #115e59;
  --chart-axis-font-size: 12px;
  --chart-tooltip-background: #134e4a;
  --chart-tooltip-color: #f0fdfa;
}

.revenue-chart::part(tooltip) {
  border-radius: 12px;
  padding: 8px 12px;
}

.revenue-chart::part(legend) {
  font-weight: 600;
}

The custom properties that change colors and sizes, at a glance. The API tab lists every property of the component.

Variable Sets
--chart-height Sets the height of the plot, axis labels included. 220px by default
--chart-color-1 … -8 Sets the palette the series take their color from, in order
--chart-surface-color Sets the color of the surface the chart sits on, mixed into the hovered bars
--chart-grid-color Sets the color of the gridlines and of the hovered category's band
--chart-bar-border-width Sets the width of the bars' border. None by default
--chart-bar-border-color Sets the color of the bars' border. The surface color by default
--chart-axis-color Sets the color of the axis labels and of the legend
--chart-axis-font-size Sets the font size of the axis labels
--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 bars 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, the most recent one on a chart over time, and the arrow keys move along the others.

Key Action
Tab / Shift+Tab Moves focus to or away from the plot
ArrowLeft Shows the previous category
ArrowRight Shows 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 (and their total when they're stacked). 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: they repeat what the table already holds.
  • hide-tooltip, hide-grid and the hidden axes only change the drawing: the data table and the keyboard announcements keep every value, a display: "none" series included.
  • While refreshing, the plot is marked aria-busy.
  • A missing value is written "No value", never left blank, so it can't be mistaken for a zero.
  • The details modal is an eun-modal, with its own focus trap, Escape to close and return of focus to the plot.
  • 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 in the plot, so keep the legend shown for several series and give them meaningful labels: the tooltip, the details and the data table name every value. Bars should keep a 3:1 contrast with the surface around them (WCAG 1.4.11); the default palette does on the default themes, check your own colors when you set them.

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