Chart frame
ProThe card a chart sits in: its title names the chart, a switch shows the same numbers as a table, and it has empty, loading, pending and error states. Not an M3 component (@windmorph/react-pro).
import { ChartFrame } from '@windmorph/react-pro/charts';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
The card a chart sits in on a dashboard or a report: a title that names the chart, a line on what it shows, your own controls, and a switch to the chart's twin, a table of the same numbers. It also covers the times there is no picture to show: nothing to draw, the first numbers loading, new ones on the way, and a failure.
It is the core Card (filled by default; elevated and outlined too), so a card theme reaches it. M3 has no charts, so it follows M3's colour roles, type scale and springs instead of a spec. A chart that needs no title or table, such as a sparkline in a tile, can stand on its own.
Title and header
titleis a heading,h3unlessheadingLevelsays otherwise, and names every chart and list of figures inside, unless it has anaria-labeloraria-labelledbyof its own. A development build warns about a chart with neither a name nor a frame.descriptionsits under the title: the period, the unit, what is counted.actionsholds your own controls (a period switch, a menu), before the table switch.
Table view
- A line chart, a bar chart or a segmented bar inside gives the frame its numbers, as it formats them, and the frame offers a switch, "Show as a table" (
labels.showTable), pressed while the table shows. Lists, meters and stat tiles give none, since their figures are already printed, so the switch isn't there, nor is it while a chart has nothing to tabulate (no places, series or parts). With several charts inside, the table shows the first's. - The table is a plain
DataTablenamed by the title: the places or parts as row headers, the figures aligned at the end. It keeps the chart's height, its rows scrolling under the header, so the cards around it don't move. Narrower than 600px of its own width, it becomes a list of figures, one row per place or part. - The data table loads the first time it's asked for, or as the switch is pointed at or focused, so a frame that is only looked at never carries it. The switch comes once the chart has given its numbers, after the page's script runs.
- The chart stays in the page, hidden, while the table shows, so going back never replays its entrance. The view that shows, the table or the chart again (as the switch or a state that ends turns to it), fades in where it stands on an effects spring (
--wm-chart-frame-view-duration), only once the frame is on screen, so nothing fades as the page loads. showTableandonShowTableChangecontrol the view, ordefaultShowTablesets where it starts.tablereplaces the generated rows with your own{ columns, rows }of text, andtable={false}takes the switch away.
States
pending: new numbers are loading. The last picture stays, its marks dimmed and its words at full contrast, and the chart area isaria-busy; while the table shows, its loading bar shows over the rows too. Use it for a period change or a refresh. With anerrorshowing, Try again shows its progress indicator instead.loading: there is no picture yet. A placeholder fills the chart area and screen readers hearlabels.loading("Loading").error: your message in place of the chart, under an error icon, with a "Try again" button (labels.retry) when you passonRetry.empty: words, or anEmptyState, in place of the chart when there is nothing to draw. You decide when that is (empty={rows.length ? undefined : 'No orders yet'}), since the frame can't see into lists and meters.- The title stays in every state and the switch goes. One state shows at a time:
errorfirst, thenloading, thenempty, as aDataTableorders its states, so the pattern above never hides a first load or a failure. Anemptyorerrorgiven as a failedcond && 'Words'(false) is no state, as React draws nothing for it. minHeight(240px at the default text size, growing with larger text) is the chart area's least height around a line or bar chart, and for the loading placeholder, a state and the table view before anything has shown. A line or bar chart with nominHeightof its own fills it, its legend included. A reload, a state or the table keeps the height last shown, so nothing below moves as the chart comes back.- Around a list or a meter (a segmented list or bar, ranked or funnel bars, a meter, a stat tile) the frame is as tall as what it holds. Pass a
minHeightnear that height, so the first load's placeholder matches it, orminHeight={0}. It is done in CSS, so the server's HTML has the right height.
When not to use
A chart that needs no title or table, such as a sparkline in a tile, can stand on its own.
See also
- Line chart: Lines over time: one subject with a wash under it and others to compare with, read by pointer, finger and keyboard. Not an M3 component (@windmorph/react-pro).
- Bar chart: Columns over places: one series, or several stacked into a total, read by pointer, finger and keyboard. Not an M3 component (@windmorph/react-pro).
- Data table: Browse, sort, filter, select and act on records, from the browser or a server, with saved views and a compact form. Not an M3 component (@windmorph/react-pro).