Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Data displayGlass surface

BarChart

Compares categorical or discrete-period values with grouped and stacked bars.

FrameworksAstro · React · Elements

Registry commandlumen add BarChart

InteractionEnhanced runtime

← All chart guides · Framework setup · Native counterparts

01

See it and copy it

Framework example

Explore the live chart, then open its code for Astro, React, or Elements.

AstroCode target · live preview uses Astro

Package downloads

1 series, 4 points. Values range from 4210 to 18420.

View chart data
CategoryDownloads
Lumen18,420 downloads
Astro Doctor9,870 downloads
Quality6,320 downloads
Dep Beacon4,210 downloads
Illustrative package download totals.
View BarChart code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.
astro
---
import { BarChart } from '@santi020k/lumen-astro'

const series = [
  {
    data: [
      { label: '18,420 downloads', x: 'Lumen', y: 18420 },
      { label: '9,870 downloads', x: 'Astro Doctor', y: 9870 },
      { label: '6,320 downloads', x: 'Quality', y: 6320 },
      { label: '4,210 downloads', x: 'Dep Beacon', y: 4210 }
    ],
    id: 'downloads',
    label: 'Downloads'
  }
]
---

<BarChart
  aria-label="Package downloads by project"
  caption="Illustrative package download totals."
  heading="Package downloads"
  orientation="horizontal"
  {series}
/>
Edit BarChart in browser

Framework differences

Elements: Pass series as a JSON attribute or through the public element property. The Elements example serializes the sample data with JSON.stringify; Astro expression bindings are not HTML attributes.

When to use BarChart

Use for category totals, rankings, or comparing the same measures across a small set of named groups.

  • Use horizontal orientation when category names need more room. Grouped bars emphasize comparisons between series; stacked bars emphasize totals and contributions.
  • Positive and negative values stack separately around zero. Keep the legend and exact-data disclosure available when multiple series share a category.

Prepare the data

ts
import type { LumenChartSeries } from '@santi020k/lumen-core'

const series = [{
  id: 'downloads',
  label: 'Downloads',
  data: [
    { x: 'lumen', xLabel: 'Lumen', y: 18420 },
    { x: 'quality', xLabel: 'Quality', y: 6320 }
  ]
}] satisfies readonly LumenChartSeries[]
  • Aggregate source records before passing series. Each series needs a unique id, label, and at most one observation for each category identity.
  • Reuse the same x identities across series to align categories. Use xLabel for display text and null for unavailable measurements.

Shared data and formatting guidance →

Avoid misleading comparisons

  • Stack only quantities whose sum is meaningful. Percentages with different denominators are not additive.
  • A bar encodes magnitude through length. Preserve a zero baseline when configuring scales through lower-level chart tools.

Chart accessibility and keyboard guidance →

02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add BarChart
lumen add BarChart

Glass

Add the glass prop to apply the shared blur, saturation, border, and highlight tokens. Glass reads best over vivid content, so place the surface above imagery or color.

AstroCode target · live preview uses Astro

Pipeline duration

1 series, 3 points. Values range from 7 to 18.

View chart data
CategoryMinutes
Build18
Test11
Deploy7
View BarChart code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.
astro
---
import { BarChart } from '@santi020k/lumen-astro'

const series = [
  {
    data: [
      { x: 'Build', y: 18 },
      { x: 'Test', y: 11 },
      { x: 'Deploy', y: 7 }
    ],
    id: 'minutes',
    label: 'Minutes'
  }
]
---

<div class="docs-glass-demo">
  <BarChart
    aria-label="Pipeline duration"
    glass
    heading="Pipeline duration"
    {series}
  />
</div>
Edit BarChart in browser

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
glassboolean | "subtle" | "strong"falseApplies the tokenized liquid-glass surface treatment with backdrop-filter fallbacks; "subtle" and "strong" adjust the fill intensity.
drilldownboolean (Astro / Elements attribute)falseEnables plotted datum actions and an equivalent native button disclosure, including with hidden tables. Astro requires UIPrimitives; Elements owns its lifecycle.
onDatumActivate(detail: LumenChartDatumActivationDetail) => void (React)-Enables React datum actions and receives validated values with raw identities. Navigation and filtering remain application owned.
explore-data-label, datum-action-prefix, datumActionFormatterstring attributes, (context: string) => string property (Elements)English labelsLocalizes the Elements disclosure and datum actions.
labels.exploreData, labels.formatDatumActionstring, (context: string) => stringEnglish labelsLocalizes the actions disclosure and each contextual datum button.
seriesLumenChartSeries[]requiredProvides already-aggregated categorical values and stable series metadata.
orientation"horizontal" | "vertical""vertical"Controls whether values extend across the x or y axis.
layout"grouped" | "stacked""grouped"Places series beside one another or combines their positive and negative totals.
categoryWidthnumber160Reserves 64–240 SVG units for horizontal category labels.
formatCategory, formatValueformatter functionsStringFormats axes, SVG titles, and the accessible data table without changing data identity.
emptyLabelstring"No chart data available."Provides actionable, source-specific empty-state guidance.
showLegendbooleantrue for multiple seriesShows the color-independent series key.
showTablebooleantrueProvides a revealable semantic table containing every plotted value.
heading, description, captionstring-Adds visible chart context without replacing the accessible name.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Keyboard interactions

Keyboard behavior provided by the Astro UIPrimitives runtime for this component.

KeyAction
TabFocus the actions disclosure and its native buttons in document order.
Enter, SpaceToggle the disclosure or activate the focused datum button. Actions remain available when the data table is hidden.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:chart-datum-activateAstro chart figure or Elements data chart hostLumenChartDatumActivationDetail: series { seriesId, x, y, datumId? }, heatmap { x, y, value, datumId? }, range { x, low, high, datumId? }Fires once after a plotted datum or its native action button is activated. Requires drilldown. Astro uses UIPrimitives, Elements owns its lifecycle, and React uses onDatumActivate instead.

Web docsFull catalog