Line chart with KPI tabs
A tab per measure showing its total; selecting a tab switches the plotted line.
Preview
Revenue and customers
Usage
import {
ChartsProvider,
LineChartWithKpiTabs,
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 },
});
const customers = measure({ name: 'customers', title: 'Customers' });
export const Example = () => (
<ChartsProvider>
<div style={{ height: 460 }}>
<LineChartWithKpiTabs
title="Revenue and customers"
xAxis={startDate}
measures={[revenue, customers]}
results={results(rows)}
resultsKpis={results(kpiRows)}
showValueLabels={false}
/>
</div>
</ChartsProvider>
);
const rows = [
{ startDate: '2026-03-01T00:00:00.000', revenue: 141619, customers: 469 },
{ startDate: '2026-04-01T00:00:00.000', revenue: 138438, customers: 410 },
{ startDate: '2026-05-01T00:00:00.000', revenue: 148882, customers: 428 },
{ startDate: '2026-06-01T00:00:00.000', revenue: 160625, customers: 476 },
];
const kpiRows = [{ revenue: 589564, customers: 1783 }];Install with npm install em-kit. Needs <ChartsProvider> once and a parent with a height: Quick start.
Examples
Filled
Each measure shaded under its line when its tab is selected.
Show full code (48 lines)
import {
ChartsProvider,
LineChartWithKpiTabs,
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, fillUnderLine: true },
});
const customers = measure({
name: 'customers',
title: 'Customers',
inputs: { fillUnderLine: true },
});
export const Example = () => (
<ChartsProvider>
<div style={{ height: 460 }}>
<LineChartWithKpiTabs
title="Revenue and customers"
xAxis={startDate}
measures={[revenue, customers]}
results={results(rows)}
resultsKpis={results(kpiRows)}
showValueLabels={false}
/>
</div>
</ChartsProvider>
);
const rows = [
{ startDate: '2026-03-01T00:00:00.000', revenue: 141619, customers: 469 },
{ startDate: '2026-04-01T00:00:00.000', revenue: 138438, customers: 410 },
{ startDate: '2026-05-01T00:00:00.000', revenue: 148882, customers: 428 },
{ startDate: '2026-06-01T00:00:00.000', revenue: 160625, customers: 476 },
];
const kpiRows = [{ revenue: 589564, customers: 1783 }];const revenue = measure({
name: 'revenue',
title: 'Revenue',
inputs: { currency: 'USD', abbreviateLargeNumber: true, fillUnderLine: true },
});
const customers = measure({
name: 'customers',
title: 'Customers',
inputs: { fillUnderLine: true },
});
<LineChartWithKpiTabs
title="Revenue and customers"
xAxis={startDate}
measures={[revenue, customers]}
results={results(rows)}
resultsKpis={results(kpiRows)}
showValueLabels={false}
/>Props
Keyboard and screen readers: Accessibility.
| Prop | Type | Default | Description |
|---|---|---|---|
xAxisrequired | Dimension | The dimension along the x-axis. A time dimension gets gap filling and date labels. | |
measuresrequired | Measure[] | The numeric fields to plot, one series each. Their inputs set the formatting. | |
resultsrequired | DataResponse | Your query’s state: { isLoading, data, error }, where data is your rows. results(rows) builds it from an array. | |
resultsKpisrequired | DataResponse | One row holding each measure’s total, shown as tabs above the chart. Clicking a tab plots that measure. | |
reverseXAxis | boolean | false | Reverse the order of the x-axis. |
showLegend | boolean | true | Show the legend. A chart with one series shows none; entries wrap onto more lines when they do not fit. |
showLogarithmicScale | boolean | false | Use a logarithmic value axis, for values that span several orders of magnitude. |
showTooltips | boolean | true | Show a formatted tooltip on hover. |
showValueLabels | boolean | true | Print each value on the chart. |
xAxisLabel | string | A title under the x-axis. | |
yAxisLabel | string | A title beside the y-axis. | |
yAxisRangeMax | number | Fix the highest value on the y-axis. When unset, it fits the data. | |
yAxisRangeMin | number | Fix 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. | |
xAxisMaxItems | number | Show at most this many x values. The rest are added up into one “Other” value. | |
granularity | Granularity | Only 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 | ( | Called 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. | |
onLineClicked | ( | Called with the clicked point’s dimension value and date range.LineChartOptionsClickArg = { dimensionValue: string | number | undefined; dimensionTimeRange: TimeRange; measureValue?: number | undefined; measureValues?: Record<string, unknown> | undefined; } | |
componentName | string | A name for this component, included in the interaction events it dispatches on the DOM, for your analytics. | |
trackingId | string | An id included in the same events, to tell two instances apart. | |
title | string | The card’s title. A "key|fallback" string is looked up in your translations. | |
description | string | Smaller text under the title. Translates like title. | |
tooltip | string | Text for an info icon beside the title. | |
hideMenu | boolean | false | Hide the card’s header: the title, description and menu. |
menuOptions | ( | ["csv", | Which entries the card menu offers. Pass [] for none. |
A blank default means the prop is unset unless you pass it.
| Type | Definition |
|---|---|
Granularity | "second" | |
TimeRange | { from: Date |What a click’s TimeRange holds: Events. |
Field options
Set in a field’s inputs, beside the common options:
| Option | Type | Set on | Description |
|---|---|---|---|
fillUnderLine | boolean | measures | Shade the area under the line. |
lineColor | string | measures | A colour for this measure’s line, in place of the theme’s. |
connectGaps | boolean | measures | Draw a missing value as zero, so the line carries on. When off, the line breaks at the gap. Default: false. |
dashedLine | boolean | measures | Draw the line dashed. Default: false. |