Area Chart

Shows how amounts change over time, with the area under each line filled in.

linuxmacwindows

Usage

Code
import { AreaChart } from '@leverui/components';
Code
<AreaChart
  data={[
    { month: 'January', windows: 186, mac: 80 },
    { month: 'February', windows: 165, mac: 95 },
  ]}
  xKey="month"
  series={[
    { name: 'windows', color: 'teal.solid' },
    { name: 'mac', color: 'purple.solid' },
  ]}
  aria-label="Monthly operating system counts"
/>

Examples

Fill With Value

Split a signed product series into positive and negative fill colors.

Percent

Normalize each monthly stack to a percentage of its total.

linuxmacwindows

Axis Label

Label the category and value axes explicitly.

Dashed Area

Make one stacked series dashed while preserving the remaining strokes.

linuxmacwindows

Dots

Add point markers over a monthly stack with two larger Linux samples.

linuxmacwindows

Gradient

Fade each stacked series toward the category axis.

linuxmacwindows

Nulls

Compare gaps from nulls with a connected line.

<Area connectNulls={false} />

<Area connectNulls={true} />

Point Label

Label the numeric value at every sales point.

18640190195240175180185300
sales

Reference Area

Highlight the February through June interval in red.

linuxmacwindows

Reference Lines

Mark August as the summer sale guide.

linuxmacwindows

Types

Compare the eight curve interpolation modes.

<Area type="linear" />

<Area type="bump" />

<Area type="basis" />

<Area type="step" />

<Area type="stepBefore" />

<Area type="stepAfter" />

<Area type="natural" />

<Area type="monotone" />

Value Axis

Show both category and value axes beside a naturally curved stack.

Props

Data

PropDefaultTypeDescription
data—readonly CartesianDatum[]Rows to draw. Required.
xKey—stringField that holds the category. Required.
series—readonly CartesianSeries[]Number fields to draw. Required.

Areas

PropDefaultTypeDescription
stackedfalsebooleanStack the series.
percentfalsebooleanScale each stack to 100%.
curvelinearCartesianCurveLine shape.
connectNullsfalsebooleanDraw the line across missing values.
fillOpacity0.2numberFill opacity, 0 to 1.
gradientfalsebooleanFade the fill toward the bottom.
valueGradientfalsebooleanColor the area below zero red.
dotsfalsebooleanDraw a dot at each value.
pointLabelsfalsebooleanPrint each value at its point, with a dot.
pointLabelPositiontop'top' | 'right'Side of the point the value sits on.

curve values: linear, bump, basis, step, stepBefore, stepAfter, natural, monotone.

Stacked with connectNulls: a missing value in the middle of a series sits on the baseline of its stack.

Axes and grid

PropDefaultTypeDescription
showXAxistruebooleanShow category labels.
showYAxisfalsebooleanShow number labels on the left.
showAxisLinesfalsebooleanDraw axis lines and tick marks.
xAxisLabel—stringTitle below the X-axis.
yAxisLabel—stringTitle beside the Y-axis.
rightYAxisLabel—stringTitle beside the right Y-axis.
xTickFormatter—(value: string) => stringFormat each category label.
yTickFormatter—(value: number) => stringFormat each number label.
xTickValues—readonly string[]Only these categories get a label.
yTickValues—readonly number[]Exact numbers that get a label and a grid line.
xTickAngle0numberRotate category labels, in degrees.
xPadding—{ left?: number; right?: number }Space before the first and after the last category, in px.
yDomain—readonly [number, number]Lowest and highest number on the Y-axis.
rightYDomain—readonly [number, number]Lowest and highest number on the right Y-axis.
showGridtruebooleanShow the grid.
gridHorizontaltruebooleanShow horizontal grid lines.
gridVerticalfalsebooleanShow vertical grid lines.
gridDashedfalsebooleanDash the grid lines.

Set yDomain with yTickValues to put labels at exact numbers. More in Axis and Cartesian Grid.

Legend and tooltip

PropDefaultTypeDescription
showLegendfalsebooleanShow a legend.
legendPlacementbottom'bottom' | 'top-right'Legend position.
legendReversefalsebooleanReverse the legend order.
legendInteraction—'hover'Dim the other series on legend hover or focus.
tooltiptruebooleanShow values for the category under the pointer.
tooltipContent—(row, series) => JSX.ElementRender your own tooltip.

Reference marks

PropDefaultTypeDescription
referenceLines—object[]Vertical lines at named categories.
referenceArea—objectShaded band between two categories.
referenceValue—objectHorizontal line at one number.
referencePoint—objectMarker at one category and number.
MarkFields (? is optional)
referenceLinesx, label?, color?
referenceAreax1, x2, label?, color?
referenceValuey, label?, color?, strokeDasharray?
referencePointx, y, color?, radius?

x, x1, x2 are category names. y is a number on the Y-axis.

Size

PropDefaultTypeDescription
height—numberFixed height, in pixels.
maxHeight384numberTallest the chart grows when height is not set.
plotMargin—objectSpace around the plot, in pixels.

Without height, the chart keeps a 4:3 shape up to maxHeight.

plotMargin takes top, right, bottom, left, each zero or more. Example: plotMargin={{ top: 40, left: 40, right: 40 }}.

Other attributes and event handlers go to the root element.

Series options

FieldTypeDescription
namestringNumber field in your data. Required.
colorstringColor token such as teal.solid, or a CSS color. Required.
labelstringName in the legend and tooltip.
strokestringLine color, if different from color.
strokeWidthnumberLine thickness.
strokeDasharraystringDash pattern, such as 4 4.
strokeGradientStops{ offset: string; color: string }[]Colors the line blends through, top to bottom.
dotRadiusnumberDot size.
dotFillstringDot fill color.
dotStrokestringDot outline color.
dotStrokeWidthnumberDot outline thickness.
activeDotRadiusnumberSize of the dot under the pointer.
activeDotStrokestringOutline color of the dot under the pointer.
yAxis'left' | 'right'Y-axis the series uses.

Keyboard

The chart takes focus when the tooltip is on.

KeyAction
ArrowLeft ArrowRightPrevious or next category.
EscapeClose the tooltip.

Styling

Code
<AreaChart class="traffic-area" data={data} xKey="month" series={series} />
Code
.traffic-area {
  --leverui-cartesian-chart-legend-gap: 1rem;
  --leverui-cartesian-chart-tooltip-bg: #f0faf8;
}

.traffic-area .leverui-cartesian-chart__gridLine {
  stroke: #a6c9c0;
}

Variables

VariableDefaultDescription
--leverui-cartesian-chart-min-width280pxNarrowest the chart gets.
--leverui-cartesian-chart-legend-gap12pxSpace between legend items.
--leverui-cartesian-chart-tooltip-bgPanel colorTooltip background.
--leverui-chart-axis-line-colorBorder colorAxis line and tick mark color.

Grid variables are in Cartesian Grid.

Classes

Root: .leverui-area-chart and .leverui-cartesian-chart__root.

Parts, each prefixed with .leverui-cartesian-chart__: svg, axes, rightAxis, axisLine, axisTitle, gridLine, cursor, series, area, line, dot, pointLabel, referenceLine, referenceArea, referenceValue, referenceValueLabel, referencePoint, referenceLabel, legend, legendItem, legendSwatch, tooltip, tooltipItem, tooltipSwatch.