All components (283)
Area chart
Data · AreaChart
What it is and when to use it
The same as LineChart, with the area under each line filled: the evolution of one or several series over the same categories, with the weight of each one in view. It shares the data, the scale, the legend and the table with LineChart and StackedBarChart.
The drawing is decoration and the table is the data: below it there is a real table (one row per category, one column per series), hidden from view unless tableVisible is set. Hovering a category shows the values of every series.
When to use it
- A volume that builds up over time: sales, visits, hours.
stackedstacks the series: the top edge is the total and each layer, what each one contributes. When stacking, a gap (null) counts as zero. Withoutstackedthe areas overlap, translucent, and two or three of them work best; anullis a gap and breaks the area there.- The axis always starts at zero, because an area that starts somewhere else exaggerates the differences;
minandmaxfix the scale by hand, to compare two charts. formatwrites the values (euros, percentages) on the axis, on hover, in the summary and in the table;categoryNameis the header of the first column of the table.
percentfills the height and shows the share of each series over the total of each category (it stacks by itself): the axis, the tooltip and the summary speak in percentages.renderTooltippaints the tooltip your way, andanimated(the default) draws the area from one side to the other when it appears and moves it when the data change.
When not to
- Comparing the shape of several series without a fill, or with the axis fitted to the data:
LineChart. - A few categories where the total of each one matters:
StackedBarChart. - Parts of a total at a single moment:
DonutChart.
Keyboard: Tab moves to the drawing (a single tab stop) and the arrow keys move from point to point; Home and End jump to the first and last, and Escape leaves. A spoken announcement gives each point with its position (“Feb, Web: 20. 2 of 3”). Up and down change series. With toggleSeries the legend is a row of buttons (Tab and Enter or Space hide or restore a series) and with onPointPress every value in a category tooltip is a button reached with Tab. The complete data is in the table.
Accessibility: the drawing is an image (role="img") with a written summary ("2 series, 9 points. Shop: from €4,200 to €7,800, peaking at €7,800 in Sep. …") and the table is always there for the screen reader. Colour is never the only clue: the legend (by default, only with more than one series) and the summary carry the name of each series.
Fine-tuning: CSS variables --amset-series-*: -axis, -cap, -footer, -height, -label and -stroke. The size moves the height (10, 14 or 18 rem); height wins if passed. The colour of each series comes from its tone, and the fill is that colour at 22 %.
What it looks like
- Store
- Online
- Wholesale
| Month | Store | Online | Wholesale |
|---|---|---|---|
| Jul | 6,900 | 5,100 | 1,900 |
| Aug | 5,200 | 5,600 | 2,400 |
| Sep | 7,800 | 6,300 | 2,800 |
<AreaChart
label="Total sales by channel"
categories={['Jul', 'Aug', 'Sep']}
series={canales}
categoryName="Month"
stacked
tableVisible
/>Props
Import it with import { AreaChart } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
categoriesrequired | readonly string[] | What goes on the bottom axis: the months, the days. One per value of each series. |
labelrequired | string | What is being measured. Required: a chart without a title does not inform. |
seriesrequired | readonly ChartSeries[] | — |
animated | boolean | Animates the drawing: lines are drawn from one side to the other, stacks grow from the base and, when the data change, segments and points slide to their new place instead of jumping. With reduced motion it is never animated. `true` by default. |
axes | boolean | Background lines with their number. |
categoryName | string | What the first column of the table is called. By default, "Period". |
className | string | Merged with the library classes; it does not replace them. |
format | (value: number) => string | — |
height | number | Height of the drawing in pixels. By default, that of the size. |
hiddenSeries | readonly string[] | The keys of the hidden series, when the chart's user keeps them. Without it, the chart keeps them itself. |
legend | boolean | The legend with the name of each series. By default, only if there is more than one. |
max | number | — |
min | number | Minimum and maximum of the axis set by hand, to compare two charts on the same scale. |
onHiddenSeriesChange | (hidden: readonly string[]) => void | Called with the hidden keys after a legend entry is pressed. |
onPointPress | (point: ChartPoint) => void | Makes every value pressable (in the tooltip of its category, also by keyboard and touch) and hands over the pressed point. |
percent | boolean | Each category adds up to 100 %: the share of each series over the total of its category is drawn (with `stacked` already on). The axis, the tooltip and the summary speak in percentages; the table and the tooltip total stay in the values. |
referenceBands | readonly ChartReferenceBand[] | Horizontal reference bands: an acceptable range. |
referenceLines | readonly ChartReferenceLine[] | Horizontal reference lines: a target, an average. |
renderTooltip | (info: ChartTooltipInfo) => ReactNode | Paints the tooltip that appears when passing over a category (and with the keyboard, when the series are pressable) instead of the built-in one. It receives the category, one row per series with its value already written and the total; if the row has to be pressable, whoever paints it adds that. It is only the view: the screen reader still receives the summary and the table. |
size | "sm" | "md" | "lg" | — |
stacked | boolean | The series are added on top of each other: the total area is the sum. By default, `false` (they overlap). |
tableVisible | boolean | Also shows the table. For the screen reader it is always there. |
toggleSeries | boolean | The legend stops being a label and each entry becomes a button that hides or restores its series. `false` by default. |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at storybook.amsetui.com:
