KPI tiles
On this page
A KPI tile shows one headline number, how it changed against the previous period, and a small
trend line. phApp.kpi() draws it from your numbers, colouring the change by whether it's good or
bad.


Figure 1: Three KPI tiles drawn by phApp.kpi() and a plain stat tile
phApp.kpi() comes with ph-app-charts.js.
<section class="ph-grid-4" aria-label="Key figures">
<div id="kpi-orders"></div>
<div id="kpi-declined"></div>
<div id="kpi-revenue"></div>
<div id="kpi-uptime"></div>
</section>
phApp.kpi('#kpi-orders', {
label: 'Orders',
value: 5974,
format: phApp.format.number,
delta: 0.12, // a fraction: 0.12 is +12%
deltaLabel: 'vs last fortnight',
trend: [380, 421, 455, 468 /* … */],
});
phApp.kpi('#kpi-declined', {
label: 'Declined',
value: 214,
delta: 0.08,
deltaLabel: 'vs last fortnight',
lowerIsBetter: true, // a rise shows red
trend: declined,
});
| Option | Default | What it does |
|---|---|---|
label | (required) | What the number is |
value | (required) | A number (formatted with format) or text |
format | toLocaleString() | Formats the value |
delta | none | The change as a fraction (0.12 is 12%). Shown as "▲ 12%" or "▼ 3%". |
deltaLabel | none | What the change is against: "vs last fortnight" |
lowerIsBetter | false | Shows a rise in red and a fall in green |
trend | none | Numbers for the sparkline under the value |
color | first chart colour | The sparkline's colour |
The change is green when it's good, red when it's bad, and grey at zero. phApp.kpi() returns
{ update(next), destroy() }.
Plain stat tiles
Without a trend or computed change, write the tile in HTML:
<div class="ph-stat">
<div class="ph-stat-label">Uptime</div>
<div class="ph-stat-value">99.82%</div>
<div class="ph-stat-meta"><span class="ph-delta ph-delta--flat">0.0%</span> vs last week</div>
</div>
| Class | What it is |
|---|---|
.ph-stat | The tile |
.ph-stat-label / .ph-stat-value / .ph-stat-meta | The label, the number (26px bold) and the line under it |
.ph-delta--up / --down / --flat | A green, red or grey change |
React
import { KpiCard } from 'ph-app-kit-react/charts';
import { StatCard, DeltaBadge, format } from 'ph-app-kit-react';
<KpiCard label="Orders" value={format.number(5974)} series={trend} subtitle={<DeltaBadge current={5974} prev={5334} />} />
<StatCard label="Uptime" value="99.82%" />
Guidelines
- At most four tiles in a row (
.ph-grid-4). - Compare like with like: the change uses the same period as the value.
- Say what the change is against in
deltaLabel. - Use
lowerIsBetterfor things you want fewer of: declines, errors, churn.
Related
- Charts
- Page patterns: the dashboard