Widgets
Data Display
Components for structured data: Table and Chart
Table
A table built from rows and cells. A Table holds Table.Row elements, and each row holds Table.Cell elements.
<Table>
<Table.Row header>
<Table.Cell>
<Text value="Item" weight="medium" />
</Table.Cell>
<Table.Cell align="end">
<Text value="Price" weight="medium" />
</Table.Cell>
</Table.Row>
{items.map((item) => (
<Table.Row key={item.sku}>
<Table.Cell>
<Text value={item.name} />
</Table.Cell>
<Table.Cell align="end">
<Text value={item.price} tabularNums />
</Table.Cell>
</Table.Row>
))}
</Table>Table itself has no props.
Table.Row Props
| Prop | Type | Default | Description |
|---|---|---|---|
header | boolean | false | Makes the row a header row of column headings. |
Table.Cell Props
| Prop | Type | Default | Description |
|---|---|---|---|
width | number | string | — | Cell width. |
colSize | xs | sm | md | lg | xl | — | Preset width: 64, 96, 144, 192 or 240 px. width wins when both are set. |
colSpan | number | 1 | How many columns the cell covers. |
rowSpan | number | 1 | How many rows the cell covers. |
padding | number | string | — | Cell padding. |
align | start | center | end | start | Horizontal alignment of the content. |
vAlign | start | center | end | center | Vertical alignment of the content. |
Chart
Bar, line, area and pie charts. A chart can combine several series, such as bars for sales with a line for the target.
<Chart
data={weeklyOrders}
xAxis="week"
series={[
{ type: "bar", dataKey: "orders", label: "Orders", color: "blue" },
{ type: "line", dataKey: "returns", label: "Returns", color: "orange" }
]}
height={220}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | object[] | — | The data points, one object per point. |
series | object[] | — | What to draw. See Series options. |
xAxis | string | {dataKey, labels?, hide?} | — | The key for the x-axis. As an object, labels maps raw values to display names and hide hides the axis. |
yAxis | {domain} | automatic | Y-axis range: [min, max] or {min, max}, where each end is a number or "auto". |
showYAxis | boolean | false | Shows y-axis labels. |
showLegend | boolean | true | Shows the legend when a series has a label. |
showTooltip | boolean | true | Shows values on hover. |
tooltipValueFormatter | object | — | Formats tooltip numbers: style (decimal, currency, percent, unit), currency, unit, notation, minimumFractionDigits, maximumFractionDigits, locale. |
showGrid | boolean | true | Shows grid lines. |
showDots | boolean | false | Marks every point on line and area series. |
showHoverDots | boolean | true | Marks the hovered point. |
showValueLabels | boolean | false | Writes each value on the chart. |
valueLabelInterval | number | 1 | With value labels, labels every Nth point. |
valueLabelOffset | number | 0 | With value labels, the point to start from. |
barRadius | number | 4 | Corner rounding of bars. |
barGap | number | — | Space between bars in the same group. |
barCategoryGap | number | string | — | Space between groups of bars. |
scrollable | boolean | false | Lets a long chart scroll sideways. |
visiblePointCount | number | — | With scrollable, how many points fit in view. |
minPointWidth | number | 48 | With scrollable, the least width of each point in pixels. |
scrollToValue | string | number | — | With scrollable, the x-axis value to scroll to at the start. |
disableUserScroll | boolean | false | With scrollable, stops the visitor scrolling the chart. |
width | number | string | 100% | Chart width. |
height | number | string | 4:3 aspect ratio | Chart height. |
ariaLabel | string | Widget chart | Name read by screen readers. |
Chart also accepts the size props size, minWidth, maxWidth, minHeight, maxHeight, minSize, maxSize, aspectRatio and flex.
Series Options
| Prop | Type | Description |
|---|---|---|
type | bar | line | area | pie | How to draw the series. |
dataKey | string | The key in each data object that holds this series' values. |
label | string | Name in the legend and tooltip. |
color | color | Series color, such as blue, green-500 or a CSS color. Series without one take colors in turn from blue, purple, orange, green, red, yellow and pink. |
fillColor | color | Fill of an area series, when it should differ from color. |
stack | string | Series with the same stack name are stacked on each other. |
curveType | natural | linear | monotone | step | stepBefore | stepAfter | basis | bump and others | Line shape for line and area series. Defaults to natural. |