Skip to Content
BBRICKSv0.7.4
KitCharts

BarChart

Spec §3 bar chart, hand-written (no chart dependency): y axis max / mid / 0, first and last x label, a hover tip per bar. LTR in both languages; one image to AT, named with the total.

import { BarChart } from '@ergasti/bricks';

Examples

Bar chart

Vertical bars with a total line; format writes each value.

Code
import { BarChart } from '@ergasti/bricks';

function Columns() {
  return (
    <div style={{ maxWidth: 520, background: 'var(--card)', borderRadius: 22, padding: 16 }}>
      <BarChart
        label="Orders per week"
        totalText="Total 1,284"
        data={[{ label: 'W1', value: 240 }, { label: 'W2', value: 310 }, { label: 'W3', value: 280 }, { label: 'W4', value: 454 }]}
        format={(n) => n.toLocaleString('en-US')}
      />
    </div>
  );
}

Horizontal bars

Rows with a label, a bar and a display value; with onSelect a row is a button (set selectable: false on one to keep it plain).

Code
import { HBars } from '@ergasti/bricks';

function Rows() {
  return (
    <div style={{ maxWidth: 380, background: 'var(--card)', borderRadius: 22, padding: 16 }}>
      <HBars
        label="Sales by challenge"
        onSelect={() => {}}
        rows={[
          { label: 'Winter glow launch', value: 184300, display: 'EGP 184.3K' },
          { label: 'Always-on', value: 126000, display: 'EGP 126.0K', tone: 'butter', selectable: false },
          { label: 'Back to campus', value: 2100, display: 'EGP 2.1K', tone: 'lime' },
        ]}
      />
    </div>
  );
}

Row variants

variant="rows" (the default) draws each row as a soft rounded tile: the bold label, the bar in the middle and the value at the end; under 600px it stacks. variant="stacked" is the 0.2 look, the label and value above a thin full-width bar. A row's display can be a node such as <Money compact />.

Code
import { HBars, Money } from '@ergasti/bricks';

function Variants() {
  const rows = [
    { label: 'Winter glow launch', value: 184300, display: <Money value="184300.00" compact /> },
    { label: 'Always-on', value: 126000, display: <Money value="126000.00" compact />, tone: 'butter' as const },
    { label: 'Back to campus', value: 2100, display: <Money value="2100.00" compact />, tone: 'lime' as const },
  ];
  return (
    <div style={{ display: 'grid', gap: 20, gridTemplateColumns: 'repeat(auto-fit, minmax(320px, 1fr))' }}>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        <p className="kit-muted">variant="rows"</p>
        <HBars label="Sales by challenge" variant="rows" rows={rows} />
      </div>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        <p className="kit-muted">variant="stacked"</p>
        <HBars label="Sales by challenge (stacked)" variant="stacked" rows={rows} />
      </div>
    </div>
  );
}

No data yet

An empty data draws emptyText in place of the bars; HBars has no empty state of its own, so show your own line (here the kit's ListState) when there are no rows.

Code
import { BarChart, HBars, ListState } from '@ergasti/bricks';

function Empty() {
  const rows: { label: string; value: number; display: string }[] = [];
  return (
    <div style={{ display: 'grid', gap: 16, gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))' }}>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        <BarChart label="Orders per week" totalText="Total 0" data={[]} format={(n) => String(n)} emptyText="No orders in this period yet." />
      </div>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        {rows.length ? <HBars label="Sales by challenge" rows={rows} /> : <ListState loading={false} error={null} empty emptyText="No challenge sales yet." onRetry={() => {}} />}
      </div>
    </div>
  );
}

Two rows with one label

id is the row's key when two rows can share a label (two challenges both named "Winter glow", one per year); without it the label is the key and React would warn. Pass the server's id whenever labels are not unique.

Code
import { HBars, Money } from '@ergasti/bricks';

function SameLabel() {
  return (
    <div style={{ maxWidth: 520 }}>
      <HBars label="Sales by challenge" rows={[
        { id: 'c-2026', label: 'Winter glow', value: 184300, display: <Money value="184300.00" compact /> },
        { id: 'c-2025', label: 'Winter glow', value: 121750, display: <Money value="121750.00" compact />, tone: 'sky' },
        { id: 'c-aon', label: 'Always-on', value: 18900, display: <Money value="18900.00" compact />, tone: 'butter' },
      ]} />
    </div>
  );
}

Props

Prop

Type

Design guidance

How the BRICKS design system uses BarChart. Written in docs/content/components/BarChart.md; the props above are read from the code, which wins where the two disagree.

A hand-written vertical bar chart with a y axis (max / mid / 0), first and last x labels and a hover tip per bar; use it for a daily count over a period.

BarChart is the 0.1.x bar chart (spec §3), kept for screens that need readable axes rather than a sparkline. It draws without a chart library: a 180px plot with gridlines every 90px, bars in the accent colour that darken on hover and show "label · value". It is one image to assistive tech, named with label and totalText. The v3 mocks do not use it; v3 screens use AreaTrend and the Tile charts.

Anatomy

  1. Y axis (.kit-chart-y, mono 11px, muted): format(max), format(max / 2), format(0).
  2. Plot (.kit-bars, 180px, repeating subtle gridlines).
  3. Bars (.kit-bar): flex, 2px gap, radius 4 4 0 0, --color-accent; height = value / max.
  4. Hover tip: data-tip ("31 Oct · 76") drawn above the bar in a dark bubble.
  5. X axis (.kit-chart-x, mono 11px): the first label and, with more than one bar, the last.

Variants

None: one look. The bar colour is the accent.

States

StateTriggerLook
Defaultdata non-emptyBars scaled to the largest value
Hoverpointer over a barBar turns --color-accent-dark; tip shows label and formatted value
Emptydata=[]emptyText as a centred muted paragraph (40px padding); nothing else
One barsingle datumOnly the first x label

Usage

const days = [{ label: '18 Oct', value: 64 }, { label: '19 Oct', value: 71 }, { label: '20 Oct', value: 58 }, { label: '31 Oct', value: 76 }];

<BarChart
  label="Orders, last 14 days"
  totalText="1,018 orders"
  data={days}
  format={(v) => v.toLocaleString('en-US')}
  emptyText="No orders in this period."
/>
<Card>
  <Card.Header title="Sales by day" sub="EGP 312,400.00 this month" />
  <BarChart label="Sales by day" totalText="EGP 312,400.00" data={salesByDay}
    format={(v) => `EGP ${(v / 1000).toFixed(1)}K`} emptyText="No sales yet." />
</Card>

Where it appears

  • Not in the v3 mocks (they use AreaTrend and Tile charts). Available for custom report screens.
  • Kit gallery; no screen.

Guidelines

Do

  • Pass a format that matches the unit (counts with thousands separators, money compact).
  • Give totalText the period total so the accessible name is useful on its own.
  • Always set emptyText; the default is an empty paragraph.

Don't

  • Don't use it for more than ~60 bars; the 2px gaps collapse.
  • Don't use negative values; bars clamp at 0.

RTL and Arabic

  • dir="ltr" on the chart: time runs left to right and the y axis stays on the left in Arabic.
  • Pass Arabic strings to label, totalText and emptyText yourself; it has no built-in copy.

Tokens

--color-accent, --color-accent-dark (bar, hover), --color-surface-border-subtle (gridlines), --color-text-muted (axes, empty), --color-text-primary / --color-text-inverted / --radius-sm (tip).

Accessibility

  • The whole chart is role="img" with aria-label="{label}: {totalText}"; individual bars are not announced and the tips are hover-only.
  • Not keyboard-operable; put any per-day detail in a table if users need it.

Found in the source

  • Roles in the markup: img.
  • ARIA attributes set: aria-label, aria-hidden.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

  • AreaTrend: v3's trend chart (line, hidden table, gaps).
  • MiniBars: tiny bars for a Tile.
  • HBars: horizontal bars for comparing named items.

See also: Money · ListState · Gauge · Legend

Source

src/kit/Charts.tsx (line 16) on GitHub.

On this page