Skip to the page content

Advanced charts

Thirteen dashboard charts that go past the basics, all drawn with Chart.js and colored by your theme.

13 charts

Subscription boxes shipped

A small plugin marks the latest week and prints its figure.

Custom plugin
  • Boxes a week
Show config
const ringNewest = {
  id: 'newestRing',
  afterDatasetsDraw: (chart) => {
    const point = chart.getDatasetMeta(0).data.at(-1);
    /* a ring at point.x, point.y, then a tag above it */
  },
};

Order service load

A new reading every second, last 24 kept.

Live stream

Streaming

Show config
setInterval(() => {
  const d = chart.data.datasets[0].data;
  d.push(nextReading());
  d.shift();
  chart.update('none');
}, 1000);

Contract value by region

Click a bar, or pick a region, to list the accounts behind it.

Drill-down
Accounts in the Northeast
Account ID Annual value
Show config
canvas.addEventListener('click', (event) => {
  const hits = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, true);
  if (hits.length) pickRegion(hits[0].index);
});

Failed checkouts, last 18 days

Numbered markers tie each change in the line to what happened that day.

Event markers
  1. 1Release 5.1
  2. 2Card gateway outage
  3. 3Bot filter turned on
  4. 4New checkout released
Show config
plugins: [{
  id: 'milestoneMarkers',
  afterDatasetsDraw({ ctx, chartArea, scales }) {
    for (const [order, { at }] of milestones.entries()) {
      const x = scales.x.getPixelForValue(at);
      /* a dashed rule from chartArea.top down, with order + 1 in a circle above */
    }
  },
}]

Orders by category

Pick one and the line moves to its numbers.

Dynamic data
Show config
button.addEventListener('click', () => {
  chart.data.datasets[0].data = categories[pick].orders;
  chart.update();   // Chart.js moves each point to its new value
});

Checkout response time

Zoom with the buttons or Ctrl and scroll, then drag to pan.

Zoom and pan

All 45 days

Show config
function show(from, to) {
  chart.options.scales.x.min = from;
  chart.options.scales.x.max = to;
  chart.update('none');
}

Last Friday, hour by hour

Two charts, one clock. Hover either to see the same hour in both.

Synced tooltips
  • Store sessions, 1,577 in the day
  • Orders, 86 in the day
Show config
a.canvas.addEventListener('pointermove', (e) => {
  const [hit] = a.getElementsAtEventForMode(e, 'index', { intersect: false }, true);
  if (!hit) return;
  const active = [{ datasetIndex: 0, index: hit.index }];
  b.setActiveElements(active);
  b.tooltip.setActiveElements(active, { x: 0, y: 0 });
  b.update('none');
});

When orders come in

Last week's 503 orders by day and hour. Darker is busier.

Heatmap
Show config
// One stacked horizontal bar per weekday, one segment per hour.
type: 'bar',
data: { labels: days, datasets: hours.map((h) => ({
  data: days.map(() => 1),
  backgroundColor: days.map((d) => shade(orders[d][h] / busiest)),
})) },
options: { indexAxis: 'y', scales: { x: { stacked: true, max: 24 }, y: { stacked: true } } }

Checkout funnel, last week

Each step sized by who reached it.

Funnel
Show config
// Floating bars centered on zero make the funnel shape.
data: steps.map((s) => [-s.count / 2, s.count / 2]),
options: { indexAxis: 'y', scales: { x: { display: false } } }

Orders every day, last 26 weeks

One square per day, shaded by orders. Busy Fridays stand out.

Calendar grid
Show config
// Seven rows (Monday to Sunday), one stacked segment per week.
type: 'bar',
data: { labels: weekdays, datasets: weeks.map((week) => ({
  data: weekdays.map(() => 1),
  backgroundColor: week.map((day) => level(day.orders)),
})) },
options: { indexAxis: 'y', scales: { x: { stacked: true }, y: { stacked: true } } }

Customers who came back

Rows are first-order months; columns, the share still ordering.

Cohort retention
Share of each month's new customers who ordered again in the months after
First order 1 mo 2 mo 3 mo 4 mo 5 mo 6 mo
Show config
// A plain table; each cell is tinted by its value and picks
// whichever text color reads best on that tint.
td.style.backgroundColor = mix(series1, surface, share);
td.style.color = contrast(text, td) >= contrast(surface, td) ? text : surface;

August to September revenue

Floating bars walk from one month's total to the next.

Waterfall
  • Month total
  • Added
  • Lost
Show config
// A bar can float: give it a [from, to] pair instead of a number.
data: [[0, 104], [104, 122.2], [122.2, 128.6], [128.6, 131.7],
       [127.4, 131.7], [119, 127.4], [0, 119]],
backgroundColor: steps.map((s) => s.total ? gray : s.up ? green : red),

September against target

Actual figure inside poor, fair and good bands, with a target mark.

Bullet

Store revenue

95% of target

$119k

Target $125k

Orders

104% of target

2,698

Target 2,600

Average order

98% of target

$44.10

Target $45.00

Delivered on time

96% of target

91%

Target 95%

Show config
type: 'bar',
options: { indexAxis: 'y', scales: { x: { min: 0, max }, y: { display: false } } },
data: { labels: [''], datasets: [
  { data: [[0, poor]], grouped: false, barPercentage: 1 },   // bands
  { data: [[poor, fair]], grouped: false, barPercentage: 1 },
  { data: [[fair, max]], grouped: false, barPercentage: 1 },
  { data: [actual], grouped: false, barPercentage: .4 },      // the actual bar
] },
// the target tick is a small afterDatasetsDraw plugin