Components · Stacked

Stacked area chart

Stacked areas showing how segments contribute to a total over time.

Open in playground

Preview

Customers by plan over time

Usage

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

const startDate = dimension({
  name: 'startDate',
  title: 'Start date',
  type: 'time',
  granularity: 'month',
});
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({
  name: 'customers',
  title: 'Customers',
  inputs: { abbreviateLargeNumber: true },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <AreaChart
        title="Customers by plan over time"
        xAxis={startDate}
        groupBy={plan}
        measure={customers}
        results={results(rows)}
        showValueLabels={false}
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { startDate: '2026-03-01T00:00:00.000', plan: 'Starter', customers: 236 },
  { startDate: '2026-03-01T00:00:00.000', plan: 'Growth', customers: 202 },
  { startDate: '2026-03-01T00:00:00.000', plan: 'Enterprise', customers: 31 },
  { startDate: '2026-04-01T00:00:00.000', plan: 'Starter', customers: 211 },
  { startDate: '2026-04-01T00:00:00.000', plan: 'Growth', customers: 168 },
  { startDate: '2026-04-01T00:00:00.000', plan: 'Enterprise', customers: 32 },
  { startDate: '2026-05-01T00:00:00.000', plan: 'Starter', customers: 212 },
  { startDate: '2026-05-01T00:00:00.000', plan: 'Growth', customers: 177 },
  { startDate: '2026-05-01T00:00:00.000', plan: 'Enterprise', customers: 39 },
  { startDate: '2026-06-01T00:00:00.000', plan: 'Starter', customers: 205 },
  { startDate: '2026-06-01T00:00:00.000', plan: 'Growth', customers: 220 },
  { startDate: '2026-06-01T00:00:00.000', plan: 'Enterprise', customers: 52 },
];

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

Examples

Axis titles

A caption on each axis.

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

const startDate = dimension({
  name: 'startDate',
  title: 'Start date',
  type: 'time',
  granularity: 'month',
});
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({
  name: 'customers',
  title: 'Customers',
  inputs: { abbreviateLargeNumber: true },
});

export const Example = () => (
  <ChartsProvider>
    <div style={{ height: 360 }}>
      <AreaChart
        title="Customers by plan over time"
        xAxis={startDate}
        groupBy={plan}
        measure={customers}
        results={results(rows)}
        showValueLabels={false}
        xAxisLabel="Start date"
        yAxisLabel="Customers"
      />
    </div>
  </ChartsProvider>
);

const rows = [
  { startDate: '2026-03-01T00:00:00.000', plan: 'Starter', customers: 236 },
  { startDate: '2026-03-01T00:00:00.000', plan: 'Growth', customers: 202 },
  { startDate: '2026-03-01T00:00:00.000', plan: 'Enterprise', customers: 31 },
  { startDate: '2026-04-01T00:00:00.000', plan: 'Starter', customers: 211 },
  { startDate: '2026-04-01T00:00:00.000', plan: 'Growth', customers: 168 },
  { startDate: '2026-04-01T00:00:00.000', plan: 'Enterprise', customers: 32 },
  { startDate: '2026-05-01T00:00:00.000', plan: 'Starter', customers: 212 },
  { startDate: '2026-05-01T00:00:00.000', plan: 'Growth', customers: 177 },
  { startDate: '2026-05-01T00:00:00.000', plan: 'Enterprise', customers: 39 },
  { startDate: '2026-06-01T00:00:00.000', plan: 'Starter', customers: 205 },
  { startDate: '2026-06-01T00:00:00.000', plan: 'Growth', customers: 220 },
  { startDate: '2026-06-01T00:00:00.000', plan: 'Enterprise', customers: 52 },
];
<AreaChart
  title="Customers by plan over time"
  xAxis={startDate}
  groupBy={plan}
  measure={customers}
  results={results(rows)}
  showValueLabels={false}
  xAxisLabel="Start date"
  yAxisLabel="Customers"
/>

Props

Not listed: resultsGroupOrder, resultsGroupOther, groupOrderCacheKey, setGroupOrderAndCacheKey and xAxisMaxItems, which the type accepts and the component does not read. Keyboard and screen readers: Accessibility.

PropTypeDefaultDescription
xAxisrequiredDimensionThe dimension along the x-axis. A time dimension gets gap filling and date labels.
groupByrequiredDimensionA second dimension that splits each axis value into one series per value.
measurerequiredMeasureThe numeric field to plot. Its inputs (prefix, suffix, decimalPlaces) set the formatting.
resultsrequiredDataResponseYour query’s state: { isLoading, data, error }, where data is your rows. results(rows) builds it from an array.
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.
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.
yAxisRangeMaxnumberFix the highest value on the y-axis. When unset, it fits the data.
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.
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.
onPointClicked(arg: AreaChartPointClickArg) => voidCalled with the clicked point’s dimension value, date range and measure value.AreaChartPointClickArg = { dimensionValue: string | number | undefined; dimensionTimeRange: TimeRange; measureValue: number | undefined; }
onAreaClicked(arg: AreaChartAreaClickArg) => voidCalled with the clicked area’s groupBy value.AreaChartAreaClickArg = { groupingDimensionValue: string | boolean | undefined; groupingDimensionTimeRange: TimeRange; }

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
connectGapsbooleanmeasureDraw a missing value as zero, so the line carries on. When off, the line breaks at the gap. Default: false.