Grouped bars with a line overlay
Use it to compare two things per period (money in against money out) and show a third derived number, such as the difference, as a line. Columns are clickable for drill-down.
How to use it
Paste the toolkit from Get the code into your page first, then call the chart like this.
const chart = barChart({
cats: months,
xlabel: monthName,
mode: 'grouped',
series: [
{ name: 'Money in', colour: 'var(--c3)', values: income },
{ name: 'Spending', colour: 'var(--c2)', values: spending }
],
lines: [{ name: 'Saved', colour: 'var(--ink)', values: saved }],
cap: 4200, // bars above this get a break and a ▲ label
onClick: i => openMonth(months[i]),
label: 'Money in, spending and saved by month'
});Options
What you can pass to this chart.
cats
Array of category labels, one per column group.
series
[{ name, values, colour }]. In grouped mode each series gets its own bar.
mode
'grouped' or 'stacked' (the default). See the stacked page.
lines
[{ name, values, colour }] drawn over the bars; may go below zero.
cap
Clip the axis. Bars above it get a zig-zag break and a ▲ label.
onClick
(index) => void. Makes each column a click target.
totals
false hides the value above each column (shown automatically for up to 14 columns).
xlabel
(category, isTooltip) => string. Called with one argument for the axis label and with true as the second for the tooltip. Note this differs from the line chart, whose second argument is the index.
tipfmt, yfmt, height
Formatters for the tooltip and the axis, and the height. The defaults format pounds, so pass your own for counts or another currency.
More charts like this
Other charts in the “Comparing” group.
Ranked bars
A top-N list with a bar per row, a detail line and optional click-through.
View chart →Waterfall
How a starting number becomes an ending number, step by step.
View chart →Diverging bars
What went up and what went down: bars either side of a zero line, biggest rise at the top.
View chart →Want charts or dashboards like these in your own product?
Tell me what you are trying to see and I can help work out the right approach, from the data behind it to the screen in front of people.