LineChart

Lines that follow one or more series across the same axis. Use it to show how a value changes over time.

Charts need Recharts. Install it once with yarn add recharts, then import from @bolio-ui/core/charts. The package stays out of your bundle until you use a chart.

General

Pass the rows in data, the key of the x axis in dataKey and one item of series per line.

Many series

Each series gets its own theme color, or the color you set. Add withLegend to name them.

Curve and dots

Use curve with linear, monotone or step, and turn the dots off with withDots={false}.

Value format

valueFormatter changes how a number reads on the y axis and in the tooltip.

APIs

LineChart.Props

AttributeDescriptionTypeAccepted valuesDefault
dataone object per point on the x axisArray<Record<string, ...>>--
dataKeykey of data that holds the x axis labelstring--
seriesthe lines to draw, one per key of dataChartSeries[]ChartSeries-
heightheight of the chart, in pixelsnumber-300
withLegendshow the legendboolean-false
withTooltipshow the values of a point on hover and focusboolean-true
withXAxisshow the x axisboolean-true
withYAxisshow the y axisboolean-true
withGridshow the horizontal grid linesboolean-true
valueFormatterhow a value is written on the y axis and in the tooltip(value: number) => string--
curvehow the line joins the pointsstring'linear', 'monotone', 'step'monotone
withDotsdraw a dot on each pointboolean-true
connectNullsdraw the line through null valuesboolean-false
...native props, passed to the rootHTMLAttributes'aria-label', 'className', ...-

ChartSeries

type ChartSeries = {
  name: string // key of `data` with the values
  label?: string // shown in the legend and the tooltip, `name` when missing
  color?: string // any CSS color, a theme color when missing
}

Ref

The ref points at the root div.

Accessibility

Name the chart with aria-label, or with aria-labelledby pointing at a heading. A named chart becomes a group. The chart can be focused. Arrow Left and Right then move through the points and show their values in the tooltip.

A chart is hard to read for screen reader users, so repeat the key numbers in text next to it, or offer the same data in a Table.

Edit this page on GitHub