KPI · Basic
KPI table
One row per metric: its trend, latest value, change and target side by side.
- Use when
- The latest value and trend of several metrics in different units, in one table
- Avoid when
- Readers need the exact changes of one metric over time (a line chart does that)
Try it
45
KPI table
Last 12 weeks, dashed line is the target
Hover over the chart, or Tab in and use the arrow keys to move between items. The numbers are sample data.
Variants
Named looks for this chart. Each one is the example above with a few options or fields changed. The CLI (ztd-charts example sparkTable --variant <id>) and the MCP server know the same names.
Best change first
Last 12 weeks, dashed line is the target
Change from the previous week
Last 12 weeks, dashed line is the target
Revenue by country, ranked
Code
SparkTable.tsx
import { ChartCard, SparkTable } from "ztd-charts";
const data = [
{"metric":"Revenue","week":"2026-07-06","value":171200,"target":190000},
{"metric":"Revenue","week":"2026-07-13","value":174900,"target":190000},
{"metric":"Revenue","week":"2026-07-20","value":173400,"target":190000},
{"metric":"Revenue","week":"2026-07-27","value":176800,"target":190000},
{"metric":"Revenue","week":"2026-08-03","value":178100,"target":190000},
{"metric":"Revenue","week":"2026-08-10","value":179900,"target":190000},
// … 66 more rows
];
export function Example() {
return (
<ChartCard number="45" title="KPI table" subtitle="Last 12 weeks, dashed line is the target" takeaway="Only p95 response time got worse" level="basic" replay>
<SparkTable
data={data}
label="metric"
x="week"
value="value"
target="target"
metrics={{"Revenue":{"format":"currency"},"Churn rate":{"unit":"%","better":"down"},"p95 response time":{"unit":"ms","better":"down"}}}
/>
</ChartCard>
);
}
Props
<SparkTable> takes these props. Rows marked Common work the same on every chart.
36 props
| Prop |
|---|
dataRequiredAn array of objects. Pass CSV, REST or database rows as they areobject[] |
labelRequiredRow name field (one row per metric)string | (d, i) => string |
xRequiredPeriod field (date, number or category). Every row shares the same period axisstring | (d, i) => any |
valueRequiredValue fieldstring | (d, i) => number |
targetTarget field. Each row uses its last filled valuestring | (d, i) => number |
metricsFormat, unit and better per row, keyed by row name, such as { "Churn rate": { "unit": "%", "better": "down" } }. Rows without an entry use the shared format, unit and betterobject |
better"up" when a higher value is better, "down" when lower is better (churn, latency). The change pill takes the accent only for a move in the good direction"up" | "down"Default "up" |
change"period" compares the first and last value of the visible periods, "previous" the last value with the one before it, "none" hides the column"period" | "previous" | "none"Default "period" |
changeLabelHeader of the change column. Default "Change" ("vs. previous" with change "previous")string |
sort"none" keeps the data order, "value" puts the largest latest value first, "change" the best change first (a fall counts as a gain for better: "down" rows)"none" | "value" | "change"Default "none" |
valueBarA bar beside each value, relative to the largest. Ignored when rows use different formats or unitsbooleanDefault false |
rowHeightRow height in pxnumberDefault 32 |
headerHeader row with the period range and the column namesbooleanDefault true |
aggregateHow rows with the same x (and series) combine: "sum" adds them, "mean" averages, "last" keeps the last row, "count" counts rows"sum" | "mean" | "last" | "count"Default "sum" |
dayFirstReads dates such as "05/03/2024", where either part could be the month, day first (5 March). Without it, a clear date in the column decides (25/03/2024), otherwise month first. true also reads "05.03.24" as day.month.yearboolean |
heightCommonHeight in px. Without it, each chart picks a default that fits its widthnumber |
widthCommonFixed width in px. Without it, the chart fits its parentnumber |
highlightCommonItem to highlight. An index, a name, an array, or "max" | "min" | "first" | "last" | "none"number | string | (number|string)[] | "max" … |
formatCommonValue format. "number" | "integer" | "percent" (values are already percents: 42 → "42%") | "ratio" (0.42 → "42%") | "compact" | "currency" (KRW for Korean locales, otherwise USD; for another currency pass Intl options with currency) | "decimal" or Intl.NumberFormat options"number" | "percent" | "compact" | … |
unitCommonUnit appended to values. For example "%" or "ms"string |
localeCommonLocale for numbers, dates and the text a chart writes itself (tooltips, screen reader sentences). "ko" or "ko-*" switches to Korean. Falls back to the ThemeProvider localestringDefault "en-US" |
animateCommonEntry and update animationbooleanDefault true |
durationCommonAnimation length (ms)number |
easingCommonMotion curve"spring" | "easeOut" | "easeInOut" | "linear"Default "spring" |
staggerCommonDelay between items as they enter (ms)number |
reducedMotionCommon"auto" follows the OS setting. true always turns motion offanyDefault "auto" |
animateOnViewCommonPlay when the chart scrolls into viewbooleanDefault true |
showLabelsCommonLabels drawn on the chart (values and names)booleanDefault true |
tooltipCommonShow tooltips. { template: "{label} · {value} · owner {owner}" } writes them: {label}, {value}, {series} or any other column of the row. \n starts a new line, and a line with an empty value is left outtooltipDefault true |
syncIdCommonCharts with the same syncId show the hovered x together (line, area, bar, candlestick, skyline). <ChartGrid sync> sets one for every chart inside itstring |
ariaLabelCommonName for screen readersstring |
descriptionCommonDescription for screen readers. Built from the data when omittedstring |
onHoverCommonRuns when hover or keyboard focus moves to another item(e: ChartEvent | null) => void |
onClickCommonRuns on click, Enter or Space(e: ChartEvent) => void |
replayKeyCommonReplays the entry animation when it changesstring | number |
themeCommonChanges theme tokens for this chart onlyPartial<ChartTheme> |