Skip to the page content

Mixed charts

Ten ways to put bars, lines and bands on one chart with Chart.js, each one colored by your theme.

10 charts

Add-on revenue this year

Months so far, then a forecast with its likely range.

Forecast with range
So far
$480k
Forecast
$703k
  • Revenue
  • Forecast
  • Likely range
Show config
datasets: [
  { type: 'bar', label: 'Revenue', data: actual },
  { type: 'line', label: 'Forecast', data: forecast, borderDash: [6, 5] },
  // The band: fill from the high line down to the low one.
  { type: 'line', label: 'High', data: high, fill: '+1', borderWidth: 0 },
  { type: 'line', label: 'Low', data: low, fill: false, borderWidth: 0 },
]

Cloud costs against budget

Monthly spend against the budget line; red months went over.

Budget vs actual
  • Spend
  • Budget
Show config
datasets: [
  { type: 'line', label: 'Budget', data: budget, stepped: 'middle', borderDash: [6, 5] },
  { type: 'bar', label: 'Spend', data: spend,
    backgroundColor: spend.map((v, i) => (v > budget[i] ? danger : series8)) },
]

Ticket resolution time

Dots are tickets; the line is the median.

Line and scatter
  • Ticket
  • Over 5 days
  • Middle half
  • Weekly median
Show config
type: 'scatter',
data: { datasets: [
  { label: 'Ticket', data: tickets },   // [{ x: week, y: days }]
  { type: 'line', label: 'Weekly median', data: medians },
  { type: 'line', data: upper, fill: '+1', borderWidth: 0 },
  { type: 'line', data: lower, borderWidth: 0 },
] }

Seat price and new seats

Price above, new seats below. A promo week lifted seats for good.

Multiple axes
  • Price
  • New seats
  • Promo week
Show config
scales: {
  // Listed bottom to top; the empty axis is a gap between the panels.
  seats: { stack: 'panel', stackWeight: 2, offset: true },
  gap:   { stack: 'panel', stackWeight: 0.35, ticks: { display: false } },
  price: { stack: 'panel', stackWeight: 1.6, offset: true },
}
// Each dataset picks its own: { yAxisID: 'price' } / { yAxisID: 'seats' }

Add-on revenue by product

Stacked bars show the split; the labeled line is the total.

Stacked with total
  • Travel Planner
  • Customer Portal
  • SMS credits
  • Total
Show config
scales: { x: { stacked: true }, y: { stacked: true } },
datasets: [
  ...products.map((p) => ({ type: 'bar', stack: 'revenue', ...p })),
  { type: 'line', label: 'Total', data: totals, stack: 'total' },
]

Daily trials

Four weeks of trials. The line is a 7-day average.

Moving average
  • Trials
  • 7-day average
Show config
const average = trials.map((_, i) => (i < 6 ? null
  : trials.slice(i - 6, i + 1).reduce((a, b) => a + b) / 7));
datasets: [
  { type: 'bar', data: trials, barPercentage: 0.5 },
  { type: 'line', data: average, fill: 'origin', tension: 0.45 },
]

Tickets against team capacity

The shaded area is what the team can answer. Only weekends go over.

Bar and area
  • Answered same day
  • Over capacity
  • Team capacity
Show config
datasets: [
  { type: 'bar', label: 'Answered', data: within, stack: 'tickets' },
  { type: 'bar', label: 'Over capacity', data: over, stack: 'tickets' },
  { type: 'line', label: 'Team capacity', data: capacity,
    stack: 'capacity', fill: 'start', stepped: 'middle' },
]

Why customers wrote to support

Sorted by count with a running total. Four reasons pass 80%.

Pareto
  • Share of messages
  • Running total
  • 80% mark
Show config
// Bars and running total share one 0 to 100% axis.
const share = counts.map((n) => (n / total) * 100);
const running = share.map((_, i) => share.slice(0, i + 1).reduce((a, b) => a + b));
scales: { y: { min: 0, max: 100 } }

Ad spend and trial conversion

Spend and conversion get an axis each. More spend, lower conversion.

Dual axis
  • Ad spend, left axis
  • Trials that paid, right axis
Show config
datasets: [
  { type: 'bar', label: 'Ad spend', yAxisID: 'spend' },
  { type: 'line', label: 'Trials that paid', yAxisID: 'rate' },
],
scales: {
  spend: { position: 'left', min: 0, max: 16, ticks: { stepSize: 4 } },
  rate:  { position: 'right', min: 0, max: 40, ticks: { stepSize: 10 },
           grid: { drawOnChartArea: false } },
}

New and returning customers

Bars are new, the line returning customers.

Bar and line
  • New
  • Returning
Show config
type: 'bar',
data: { labels, datasets: [
  { label: 'New', data: fresh },
  { type: 'line', label: 'Returning', data: returning,
    pointRadius: 4, pointBackgroundColor: surface },
] }