ChartFrame
The frame every chart sits in: the title and what is measured, the legend, the plot with its states (first load, no data, failed), and the same numbers as a table.
import { ChartFrame, ChartSkeleton } from '@sypnia/ui/react'
On this page
Its four states
Choose a state.
Code
import { useState } from 'react';
import { ChartFrame, ChartSkeleton, SegmentedControl } from '@sypnia/ui/react';
// The frame every chart sits in: title, legend, the plot and its states. Choose a state to see each one.
type S = 'skeleton' | 'loading' | 'empty' | 'error';
export default function States() {
const [s, setS] = useState<S>('loading');
return (
<div className="sy-stack">
<SegmentedControl label="State" value={s} onChange={setS} options={[{ value: 'skeleton', label: 'Nothing known' }, { value: 'loading', label: 'First load' }, { value: 'empty', label: 'No data' }, { value: 'error', label: 'Failed' }]} />
{s === 'skeleton' ? <ChartSkeleton height={180} legend={2} />
: <ChartFrame title="Requests" subtitle="Per hour, last day" height={180} loading={s === 'loading'} isEmpty={s !== 'error'}
error={s === 'error' ? 'The numbers could not be read. Try again in a minute.' : undefined}><svg /></ChartFrame>}
</div>
);
} When to use it
Use it when
- Every chart of the library already sits in one; use it around a chart you draw yourself.
- Say the unit and the period in
subtitle: «Requests per hour, last day».
Do not use it when
- A number alone: use Stat.
For everyone
- The first load shows the axes and bars as skeletons, and the chart is
aria-busy. - «View as table» gives the same numbers to everyone.
- A failure says what happened in words.
Props
| ChartFrame | Type | Default |
|---|---|---|
titlerequired | ReactNode | |
emptyShown instead of the plot when there is nothing to draw. | ReactNode | |
error | ReactNode | |
height | number | 240 |
isEmpty | boolean | |
legendSeries to list in the legend. Not shown for a single series: the title already names it. | { label: string; line?: boolean; }[] | |
loadingNew data is on its way: the chart keeps its last drawing, dimmed. On the first load pass `loading` with no data. | boolean | |
skeletonWhat the plot shows on the first load instead of the default plot skeleton, when the chart's shape is not a plot with axes (rows of bars, a gauge). | ReactNode | |
subtitleWhat is plotted and in what unit: «Requests per minute, last 24 hours». | ReactNode | |
tableThe same numbers as a table, behind «View as table». | { columns: string[]; rows: (string | number)[][]; } |
| ChartSkeleton | Type | Default |
|---|---|---|
height | number | 240 |
legendHow many series the legend will list. | number | 0 |
tableWhether the chart will offer «View as table» under the plot (every LineChart, AreaChart and BarChart does). | boolean | true |