Skip to the page content

Bar charts

Thirteen ways to compare amounts with Chart.js, each one colored by your theme.

13 charts

Signups by channel

Each column is a month; the pieces show where signups came from.

Stacked
  • Search
  • Social
  • Content
  • Partner
Show config
options: {
  scales: { x: { stacked: true }, y: { stacked: true } },
}
// Round only the top piece of each column.
borderRadius: isTop ? { topLeft: 6, topRight: 6 } : 0

Q3 sales against target

A thin bar for what sold, a tick for target.

Bullet
  • Sales
  • Target
Show config
datasets: [
  { label: 'Sales', data, barPercentage: 0.34, grouped: false },
  { label: 'Track', data: max, barPercentage: 0.72, grouped: false },
],
options: { indexAxis: 'y' }
// A small plugin draws the target tick.

Orders this week

One bar a day, weekend in its own color. Switch weeks to compare.

Basic
Show config
new Chart(canvas, {
  type: 'bar',
  data: { labels, datasets: [{ label: 'Orders', data, borderRadius: 6 }] },
});
// Switching weeks: swap the data, then chart.update().

Why customers got in touch

Sideways bars, so long labels read in full. Last 30 days.

Horizontal
Show config
options: {
  indexAxis: 'y',
  scales: { x: { display: false } },
}

Net subscribers each month

New subscriptions minus cancellations; losing months dip below zero.

Negative values
  • Gained
  • Lost
Show config
backgroundColor: data.map((v) => (v < 0 ? danger : success))

Orders by category, quarter by quarter

Quarters side by side, so each plan's change reads easily.

Grouped
  • Q1
  • Q2
  • Q3
Show config
datasets: [
  { label: 'Q1', data, categoryPercentage: 0.7 },
  { label: 'Q2', data, categoryPercentage: 0.7 },
  { label: 'Q3', data, categoryPercentage: 0.7 },
]

Where orders are placed

Each column is 100%, so only the share moves. The app is gaining.

100% stacked
  • Web store
  • Mobile app
  • Point of sale
Show config
scales: {
  x: { stacked: true },
  y: { stacked: true, max: 100, ticks: { callback: (v) => v + '%' } },
}

Daily orders against the average

The dashed line is the 3-week average; days below it fade back.

Reference line
  • Above average
  • Below average
  • Average
Show config
backgroundColor: data.map((v) => (v >= avg ? full : faded)),
plugins: [{
  id: 'average',
  afterDatasetsDraw(chart) { /* dashed line at y(avg) */ },
}]

Typical order value

Each bar spans the middle 80% of orders.

Range
Show config
// Each value is a [low, high] pair.
data: [[24, 88], [26, 94], [29, 103], /* ... */],
borderSkipped: false,
borderRadius: 999

Monthly orders by region

Four small charts on one scale, Jan to Sep; September is solid.

Small multiples
Northeast426 in Sep
Midwest223 in Sep
West207 in Sep
South121 in Sep
Show config
// One chart per category, all sharing the same fixed scale.
scales: {
  x: { display: false },
  y: { display: false, min: 0, max: 450 },
}

Customers who bought again

Every bar carries its value, so the y-axis can go.

Data labels
Show config
plugins: [{
  id: 'values',
  afterDatasetsDraw(chart) {
    chart.getDatasetMeta(0).data.forEach((bar, i) =>
      chart.ctx.fillText(data[i] + '%', bar.x, bar.y - 7));
  },
}]

Orders shipped by city

Largest first; only the leader keeps the full color.

Sorted
Show config
const rows = cities.slice().sort((a, b) => b.orders - a.orders);
data: {
  labels: rows.map((r) => r.name),
  datasets: [{ data: rows.map((r) => r.orders) }],
}

Store revenue by month

Bars fade toward the base; turn gradients off and they go flat.

Gradient fill
Show config
backgroundColor(context) {
  const { ctx, chartArea } = context.chart;
  if (!chartArea) return color;
  const g = ctx.createLinearGradient(0, chartArea.top, 0, chartArea.bottom);
  g.addColorStop(0, color);
  g.addColorStop(1, lighter);
  return g;
}