CompositeChart

Bars, lines and areas in one chart, to compare measures that work together. Use it when one number explains another, such as visits (bars) and conversion (line).

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

Give each item of series a type: bar, area or line. A series without a type is a line.

Right axis

Measures with different scales need their own axis. Turn on withRightYAxis and set yAxisId: 'right' on the series that uses it.

APIs

CompositeChart.Props

AttributeDescriptionTypeAccepted valuesDefault
dataone object per point on the x axisArray<Record<string, ...>>--
dataKeykey of data that holds the x axis labelstring--
serieswhat 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 number is written(value: number) => string-thousands separators, en-US
curvehow the lines join the pointsstring'linear', 'monotone', 'step'monotone
withDotsdraw a dot on each point of a lineboolean-true
connectNullsdraw lines through null valuesboolean-false
withRightYAxisadd a second y axis on the rightboolean-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
  type?: 'line' | 'bar' | 'area' // `line` when missing
  yAxisId?: 'left' | 'right' // `right` needs `withRightYAxis`
}

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 data and show the values in the tooltip.

When the series are different measures, repeat the key numbers in text next to the chart, or offer the same data in a Table.

Edit this page on GitHub