Skip to content

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
  1. Its four states
  2. When to use it
  3. For everyone
  4. Props

Its four states

Choose a state.

Requests
Per hour, last day
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

ChartFrameTypeDefault
titlerequired ReactNode
empty

Shown instead of the plot when there is nothing to draw.

ReactNode
error ReactNode
height number 240
isEmpty boolean
legend

Series to list in the legend. Not shown for a single series: the title already names it.

{ label: string; line?: boolean; }[]
loading

New data is on its way: the chart keeps its last drawing, dimmed. On the first load pass `loading` with no data.

boolean
skeleton

What 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
subtitle

What is plotted and in what unit: «Requests per minute, last 24 hours».

ReactNode
table

The same numbers as a table, behind «View as table».

{ columns: string[]; rows: (string | number)[][]; }
ChartSkeletonTypeDefault
height number 240
legend

How many series the legend will list.

number 0
table

Whether the chart will offer «View as table» under the plot (every LineChart, AreaChart and BarChart does).

boolean true
  1. Its four states
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms