Components
Chart
Chart presents numeric series as either bar or line marks.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Bar Mark
Loading preview…
Code
'use client';
import { Chart } from '@swiftuijs/ui';
const monthlyRevenue = [
{ id: 'jan', label: 'Jan', value: 12 },
{ id: 'feb', label: 'Feb', value: 24 },
{ id: 'mar', label: 'Mar', value: 18 },
{ id: 'apr', label: 'Apr', value: 30 },
];
export default function Example() {
return (<Chart caption="Quarterly revenue" data={monthlyRevenue} label="Revenue" mark="bar" showValues></Chart>);
}Usage and limitations
- Use
mark="bar"for category comparisons - Use
mark="line"for trend visualization - Use
showValueswhen exact values should stay visible beside the graphic - Use
selectedDatumIdordefaultSelectedDatumIdwhen the surrounding UI needs a highlighted datum - Use
valueFormatterto keep visible values and accessibility labels aligned - Marks support keyboard selection with arrow keys,
Home, andEnd
More examples
Line Mark
Empty State
Selection
Line Selection
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
data | IChartDatum[] | Yes | — |
label | string | Yes | — |
caption | string | No | — |
mark | 'bar' | 'line' | No | — |
showValues | boolean | No | — |
emptyState | string | No | — |
height | number | No | — |
selectedDatumId | string | No | — |
defaultSelectedDatumId | string | No | — |
onSelectionChange | (datum: IChartDatum) => void | No | — |
valueFormatter | (value: number, datum: IChartDatum) => string | No | — |
Inherits additional props from IBaseComponent.