Ir al contenido

ChartFrame

El marco en el que va cada gráfica: el título y qué se mide, la leyenda, el trazado con sus estados (primera carga, sin datos, falló) y los mismos números como tabla.

import { ChartFrame, ChartSkeleton } from '@sypnia/ui/react'

En esta página
  1. Sus cuatro estados
  2. Cuándo usarlo
  3. Para todos
  4. Props

Sus cuatro estados

Elige un estado.

Requests
Per hour, last day
Código
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>
  );
}

Cuándo usarlo

Úsalo cuando

  • Cada gráfica de la biblioteca ya va dentro de uno; úsalo alrededor de una gráfica que dibujes tú.
  • Di la unidad y el periodo en subtitle: «Peticiones por hora, último día».

No lo uses cuando

  • Un número solo: usa Stat.

Para todos

  • La primera carga muestra los ejes y las barras como skeletons, y la gráfica queda aria-busy.
  • «Ver como tabla» da los mismos números a todos.
  • Una falla dice qué pasó en palabras.

Props

ChartFrameTipoPor defecto
titleobligatorio 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)[][]; }
ChartSkeletonTipoPor defecto
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. Sus cuatro estados
  2. Cuándo usarlo
  3. Para todos
  4. Props

    Busca páginas, secciones y términos