Skip to the page content

Pie charts

Thirteen ways to split a whole with Chart.js, each one colored by your theme.

13 charts

September MRR by product

Click a slice or a name in the list to see its numbers.

Select a slice

Pro

$360,800

Share of MRR
41%
Accounts
790
Per account
$456.71
Against August
Up 6%
Show config
data: { datasets: [{ data, offset: (c) => (c.dataIndex === picked ? 16 : 0) }] },
options: {
  onClick(e, items, chart) {
    if (items.length) select(items[0].index);   // then chart.update()
  },
}

Accounts by region

Each share is printed on its own slice.

Slice labels
  • Northeast
  • Midwest
  • West
  • South
Show config
afterDatasetsDraw(chart) {
  chart.getDatasetMeta(0).data.forEach((arc, i) => {
    const { x, y } = arc.tooltipPosition();
    ctx.fillStyle = readableOn(colors[i]);   // white or black
    ctx.fillText(share[i] + '%', x, y);
  });
}

Why orders came back

The reason worth acting on is pulled out.

Pulled-out slice
  • Damaged in transit
  • Everything else
Show config
offset: [0, 18, 0, 0, 0],
layout: { padding: 20 }   // room for the slice to move

Deliveries against the promise

Half a circle, so the total fits below it.

Half pie
  • On time
  • A day late
  • Later
Show config
{ type: 'pie', options: { rotation: -90, circumference: 180 } }

Where store visits came from

This week beside the same week in August, in the same colors.

Two periods
  • Search
  • Direct
  • Email
  • Social
  • Referral
Same week, August8,420 visits
This week9,030 visits
Show config
// Two charts, one color list, the same label order.
new Chart(augCanvas, { type: 'pie', data: { labels, datasets: [{ data: aug, backgroundColor }] } });
new Chart(sepCanvas, { type: 'pie', data: { labels, datasets: [{ data: sep, backgroundColor }] } });

Signups by channel

Four slices, a thin gap, nothing else.

Basic
  • Search
  • Social
  • Content
  • Partner
Show config
new Chart(canvas, {
  type: 'pie',
  data: { labels, datasets: [{ data, backgroundColor, borderColor: surface }] },
});

How customers paid

Labels sit outside on short lines, so thin slices stay readable.

Outside labels
Show config
layout: { padding: { left: 90, right: 90 } },
// afterDatasetsDraw: a line from each slice's edge, then
// the name and share, nudged apart when two would touch.

Sales by state

The five biggest keep a color; the other nine share one gray slice.

Top five and other
  • California 34%
  • Texas 18%
  • New York 14%
  • Colorado 11%
  • Florida 8%
  • 9 others 15%
Show config
const sorted = rows.sort((a, b) => b.value - a.value);
const top = sorted.slice(0, 5);
const other = sorted.slice(5).reduce((sum, r) => sum + r.value, 0);
data: [...top.map((r) => r.value), other]

Accounts by team size

The same pie four times, with the legend on each side.

Legend placement
position: 'top'
position: 'right'
position: 'bottom'
position: 'left'
Show config
plugins: {
  legend: { display: true, position: 'right', labels: { usePointStyle: true } },
}

Subscribers by delivery rhythm

Your own colors: shades of one hue.

Custom colors
  • Weekly
  • Biweekly
  • Monthly
  • Paused
Show config
backgroundColor: ['#9b6de0', '#b999e9', '#d1bcf1', '#e5d9f7']

Where orders were placed

The total sits on a pill in the middle.

Center text
  • Website
  • App
  • Phone
  • In the shop
Show config
afterDraw(chart) {
  const { x, y } = chart.getDatasetMeta(0).data[0];   // the pie's center
  drawLabel(ctx, x, y, '503 orders');                 // surface fill, text color
}

Workspaces by plan

Point at a slice and it slides outward.

Lift on hover
  • Free
  • Basic
  • Pro
  • Max
  • On trial
  • Past due
Show config
datasets: [{ data, hoverOffset: 16 }],
options: { animation: { animateRotate: true, animateScale: true } }

Add-ons and how they bill

Add-on in the middle, its billing split around it.

Nested rings
  • Routing: annual, monthly
  • Portal: annual, monthly
  • SMS: bundle, top-up
Show config
type: 'pie',
datasets: [
  { data: parts },        // first dataset is the outer ring
  { data: categories },   // last one fills the middle
]