DataMatrix
DataMatrix pivots a flat list of records into a cross-tab: one field becomes the rows, another becomes the columns, and each cell aggregates the matching records by count or sum. Row, column, and grand totals are shown by default.
When to use
- Summarize records across two dimensions (e.g. Status × Region, Category × Month).
- Quick pivot/aggregation without a full BI tool.
Import
import { DataMatrix, AggregationType } from '@spartanfx/react';
Count example
Cross-tabulate items by xField (rows) and yField (columns), counting matches.
<DataMatrix
items={records}
xField="status"
yField="region"
aggregationType={AggregationType.count}
/>
Sum example
To sum a numeric field, set the aggregation type and point aggregationField at it.
<DataMatrix
items={sales}
xField="product"
yField="quarter"
aggregationType={AggregationType.sum}
aggregationField="amount"
xFieldLabel="Product"
yFieldLabel="Quarter"
/>
Key props
| Prop | Type | Notes |
|---|---|---|
items (required) | Record<string, unknown>[] | Records to pivot. |
xField (required) | string | Field for row headers. |
yField (required) | string | Field for column headers. |
aggregationType (required) | AggregationType | Count or Sum. |
aggregationField | string | Numeric field to sum (ignored for count). |
showTotals | boolean | Row/column/grand totals (default true). |
xFieldLabel / yFieldLabel | string | Axis display labels. |
blankLabel | string | Label for blank values (default (Blank)). |
See the full generated reference: DataMatrix API ↗.