Components · Bars

Bar chart

Compare one or more measures across the values of a dimension.

Open in playground

Preview

Customers by industry

Usage

tsx
import { ChartsProvider, BarChart, dimension, measure, results } from 'em-kit';

const industry = dimension({ name: 'industry', title: 'Industry' });
const customers = measure({
  name: 'customers',
  title: 'Customers',
  inputs: { abbreviateLargeNumber: true },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BarChart
        title="Customers by industry"
        dimension={industry}
        measures={[customers]}
        results={results(rows)}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { industry: 'Health', customers: 448 },
  { industry: 'Media', customers: 677 },
  { industry: 'Retail', customers: 741 },
  { industry: 'Tech', customers: 707 },
];
  • Each row in results is one bar: the dimension's value plus each measure.
  • Format values through the measure's inputs: here abbreviateLargeNumber shortens thousands to K.

Install with npm install em-kit. Needs <ChartsProvider> once and a parent with a height: Quick start.

Examples

Monthly columns

Six months as columns, each labelled with its abbreviated value. A time dimension with granularity: 'month' labels the axis and fills months with no row.

tsxDiffers from Usage
Show full code (35 lines)
import { ChartsProvider, BarChart, dimension, measure, results } from 'em-kit';

const startDate = dimension({
  name: 'startDate',
  title: 'Start date',
  type: 'time',
  granularity: 'month',
});
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BarChart
        title="Revenue by month"
        dimension={startDate}
        measures={[revenue]}
        results={results(rows)}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { startDate: '2026-01-01T00:00:00.000', revenue: 131229 },
  { startDate: '2026-02-01T00:00:00.000', revenue: 116685 },
  { startDate: '2026-03-01T00:00:00.000', revenue: 141619 },
  { startDate: '2026-04-01T00:00:00.000', revenue: 138438 },
  { startDate: '2026-05-01T00:00:00.000', revenue: 148882 },
  { startDate: '2026-06-01T00:00:00.000', revenue: 160625 },
];
const startDate = dimension({
  name: 'startDate',
  title: 'Start date',
  type: 'time',
  granularity: 'month',
});
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});

<BarChart
  title="Revenue by month"
  dimension={startDate}
  measures={[revenue]}
  results={results(rows)}
/>

Growth, up and down

Month-on-month change as a percentage, with bars below zero for the months that fell. Compute growth in your query and describe it with its own measure(), formatted by suffix and decimalPlaces.

tsxDiffers from Usage
Show full code (35 lines)
import { ChartsProvider, BarChart, dimension, measure, results } from 'em-kit';

const startDate = dimension({
  name: 'startDate',
  title: 'Start date',
  type: 'time',
  granularity: 'month',
});
const growth = measure({
  name: 'growth',
  title: 'Revenue growth',
  inputs: { suffix: '%', decimalPlaces: 1 },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BarChart
        title="Revenue growth, month on month"
        dimension={startDate}
        measures={[growth]}
        results={results(rows)}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { startDate: '2026-01-01T00:00:00.000', growth: 0.6 },
  { startDate: '2026-02-01T00:00:00.000', growth: -11.1 },
  { startDate: '2026-03-01T00:00:00.000', growth: 21.4 },
  { startDate: '2026-04-01T00:00:00.000', growth: -2.2 },
  { startDate: '2026-05-01T00:00:00.000', growth: 7.5 },
  { startDate: '2026-06-01T00:00:00.000', growth: 7.9 },
];
const startDate = dimension({
  name: 'startDate',
  title: 'Start date',
  type: 'time',
  granularity: 'month',
});
const growth = measure({
  name: 'growth',
  title: 'Revenue growth',
  inputs: { suffix: '%', decimalPlaces: 1 },
});

<BarChart
  title="Revenue growth, month on month"
  dimension={startDate}
  measures={[growth]}
  results={results(rows)}
/>

Axis titles

A caption on each axis, for a chart that has to stand on its own in a report.

tsxDiffers from Usage
Show full code (31 lines)
import { ChartsProvider, BarChart, dimension, measure, results } from 'em-kit';

const industry = dimension({ name: 'industry', title: 'Industry' });
const customers = measure({
  name: 'customers',
  title: 'Customers',
  inputs: { abbreviateLargeNumber: true },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BarChart
        title="Customers by industry"
        dimension={industry}
        measures={[customers]}
        results={results(rows)}
        showValueLabels={false}
        xAxisLabel="Industry"
        yAxisLabel="Customers"
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { industry: 'Health', customers: 448 },
  { industry: 'Media', customers: 677 },
  { industry: 'Retail', customers: 741 },
  { industry: 'Tech', customers: 707 },
];
const industry = dimension({ name: 'industry', title: 'Industry' });
const customers = measure({
  name: 'customers',
  title: 'Customers',
  inputs: { abbreviateLargeNumber: true },
});

<BarChart
  title="Customers by industry"
  dimension={industry}
  measures={[customers]}
  results={results(rows)}
  showValueLabels={false}
  xAxisLabel="Industry"
  yAxisLabel="Customers"
/>

Fixed value range

A pinned value axis, so charts side by side share one scale. yAxisRangeMin and yAxisRangeMax pin the axis; values above the maximum are clipped.

tsxDiffers from Usage
Show full code (30 lines)
import { ChartsProvider, BarChart, dimension, measure, results } from 'em-kit';

const industry = dimension({ name: 'industry', title: 'Industry' });
const customers = measure({
  name: 'customers',
  title: 'Customers',
  inputs: { abbreviateLargeNumber: true },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BarChart
        title="Customers by industry"
        dimension={industry}
        measures={[customers]}
        results={results(rows)}
        yAxisRangeMin={0}
        yAxisRangeMax={2000}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { industry: 'Health', customers: 448 },
  { industry: 'Media', customers: 677 },
  { industry: 'Retail', customers: 741 },
  { industry: 'Tech', customers: 707 },
];
const industry = dimension({ name: 'industry', title: 'Industry' });
const customers = measure({
  name: 'customers',
  title: 'Customers',
  inputs: { abbreviateLargeNumber: true },
});

<BarChart
  title="Customers by industry"
  dimension={industry}
  measures={[customers]}
  results={results(rows)}
  yAxisRangeMin={0}
  yAxisRangeMax={2000}
/>

Long tail as “Other”

Rows sorted largest first: the top five as bars, and the rest added up into one “Other” bar. xAxisMaxItems: 6 keeps the first five rows in your order and adds up the rest, so sort the query largest first.

tsxDiffers from Usage
Show full code (36 lines)
import { ChartsProvider, BarChart, dimension, measure, results } from 'em-kit';

const account = dimension({ name: 'account', title: 'Account' });
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <BarChart
        title="Revenue by account"
        dimension={account}
        measures={[revenue]}
        results={results(rows)}
        xAxisMaxItems={6}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { account: 'Juniper', revenue: 176000 },
  { account: 'Kite', revenue: 152000 },
  { account: 'Harbor', revenue: 131000 },
  { account: 'Isle', revenue: 114000 },
  { account: 'Fjord', revenue: 96000 },
  { account: 'Grove', revenue: 84000 },
  { account: 'Dune', revenue: 78000 },
  { account: 'Ember', revenue: 64000 },
  { account: 'Birch', revenue: 60000 },
  { account: 'Cedar', revenue: 49000 },
  { account: 'Alder', revenue: 44000 },
];
const account = dimension({ name: 'account', title: 'Account' });
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});

<BarChart
  title="Revenue by account"
  dimension={account}
  measures={[revenue]}
  results={results(rows)}
  xAxisMaxItems={6}
/>

Props

Keyboard and screen readers: Accessibility.

PropTypeDefaultDescription
dimensionrequiredDimensionThe field whose values label the axis or the segments. Its name is the row key.
measuresrequiredMeasure[]The numeric fields to plot, one series each. Their inputs set the formatting.
resultsrequiredDataResponseYour query’s state: { isLoading, data, error }, where data is your rows. results(rows) builds it from an array.
showLegendbooleantrueShow the legend. A chart with one series shows none; entries wrap onto more lines when they do not fit.
showLogarithmicScalebooleanfalseUse a logarithmic value axis, for values that span several orders of magnitude.
showTooltipsbooleantrueShow a formatted tooltip on hover.
showValueLabelsbooleantruePrint each value on the chart.
xAxisLabelstringA title under the x-axis.
yAxisLabelstringA title beside the y-axis.
granularityGranularityOnly sets the size of the date range a click reports (dimensionTimeRange). The axis labels and the gap filling come from the time field, dimension({ granularity }), and this prop follows the field when left out. One of "second", "minute", "hour", "day", "week", "month", "quarter", "year".
setGranularity(granularity: Granularity) => voidCalled with the granularity the reader picks in the card. The picker only shows when the time field sets showGranularityDropdown: true in its inputs. Store the value, set it as the field’s granularity and pass rows at that granularity.
onBarClicked(args: BarChartOptionsClickArg) => voidCalled with the clicked bar’s dimension value and, on a time axis, its date range. Use it as a filter.BarChartOptionsClickArg = { dimensionValue: string | number | undefined; dimensionTimeRange: TimeRange; measureValues?: Record<string, unknown> | undefined; }
componentNamestringA name for this component, included in the interaction events it dispatches on the DOM, for your analytics.
trackingIdstringAn id included in the same events, to tell two instances apart.
titlestringThe card’s title. A "key|fallback" string is looked up in your translations.
descriptionstringSmaller text under the title. Translates like title.
tooltipstringText for an info icon beside the title.
hideMenubooleanfalseHide the card’s header: the title, description and menu.
menuOptions("csv" | "xlsx" | "png" | "maximize")[]["csv", "xlsx", "png", "maximize"]Which entries the card menu offers. Pass [] for none.
reverseXAxisbooleanfalseReverse the order of the x-axis.
xAxisMaxItemsnumberShow at most this many x values. The rest are added up into one “Other” value.
yAxisRangeMinnumberFix the lowest value on the y-axis. When unset, a bar, line or area chart’s axis includes zero, and a scatter or bubble chart’s fits the data.
yAxisRangeMaxnumberFix the highest value on the y-axis. When unset, it fits the data.

A blank default means the prop is unset unless you pass it.

TypeDefinition
Granularity"second" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year"
TimeRange{ from: Date | undefined; to: Date | undefined; relativeTimeString?: string; } | undefinedWhat a click’s TimeRange holds: Events.

Field options

Set in a field’s inputs, beside the common options:

OptionTypeSet onDescription
colorstringmeasuresA colour for this measure’s bars, in place of the theme’s.
showValueAsPercentagebooleanmeasuresLabel each value with its share of the total. The tooltip shows both. Default: false.