Components · KPIs

KPI number

A single headline figure, formatted with the measure’s currency, prefix, suffix and locale.

Open in playground

Preview

Customers, last 30 days

476

Usage

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

const customers = measure({ name: 'customers', title: 'Customers' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ width: 360, height: 160 }}>
      <KpiNumber
        title="Customers, last 30 days"
        measure={customers}
        results={results(totalRows)}
      />
    </div>
  </ChartsProvider>
);

const totalRows = [{ customers: 476 }];

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

Examples

Compact

A large figure shortened to “1.2M”, still in the reader’s locale. abbreviateLargeNumber is a field option on the measure; the currency stays.

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

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

export const Example = () => (
  <ChartsProvider>
    <div style={{ width: 360, height: 160 }}>
      <KpiNumber
        title="Revenue, year to date"
        measure={revenue}
        results={results(totalRows)}
      />
    </div>
  </ChartsProvider>
);

const totalRows = [{ revenue: 837479 }];
const revenue = measure({
  name: 'revenue',
  title: 'Revenue',
  inputs: { currency: 'USD', abbreviateLargeNumber: true },
});

<KpiNumber
  title="Revenue, year to date"
  measure={revenue}
  results={results(totalRows)}
/>

const totalRows = [{ revenue: 837479 }];

Fixed font size

A set font size instead of auto-fitting the card, for a row of KPIs that should match. Without fontSize the number grows and shrinks to fill the card.

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

const customers = measure({ name: 'customers', title: 'Customers' });

export const Example = () => (
  <ChartsProvider>
    <div style={{ width: 360, height: 160 }}>
      <KpiNumber
        title="Customers, last 30 days"
        measure={customers}
        results={results(totalRows)}
        fontSize={40}
      />
    </div>
  </ChartsProvider>
);

const totalRows = [{ customers: 476 }];
const customers = measure({ name: 'customers', title: 'Customers' });

<KpiNumber
  title="Customers, last 30 days"
  measure={customers}
  results={results(totalRows)}
  fontSize={40}
/>

Props

Keyboard and screen readers: Accessibility.

PropTypeDefaultDescription
measurerequiredMeasureThe number to show. 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.
fontSizenumberFont size of the headline number in pixels. By default it grows and shrinks to fit the card.
displayNullAsstringText shown where a value is null, for example "–".
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.

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

Field options

KpiNumber reads only the common options in a field’s inputs.