Skip to main content

Pie & Doughnut Charts

Pie and doughnut charts show how individual slices make up a whole. They are ideal for proportions — the share of customers per plan, sales per region, or tickets per status. A doughnut is the same chart with a hollow centre.

Building one​

A pie or doughnut chart draws one slice per dataset, and a slice's size is the value of its dataset's Datasource column in the first row of the result. So return one row with a column for each slice:

SELECT
SUM(CASE WHEN status = 'open' THEN 1 ELSE 0 END) AS "Open",
SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) AS "Pending",
SUM(CASE WHEN status = 'closed' THEN 1 ELSE 0 END) AS "Closed"
FROM tickets;

Choose Pie or Doughnut as the chart type in the chart settings and add a dataset for each column: its Label names the slice, its Color colours it and its Datasource is the column (Open, Pending, Closed).

Keep the slices few​

Pie and doughnut charts are only readable with a handful of slices. Each slice is a dataset you add, so return only a few columns and fold the small categories into an Other column in SQL.

Pie vs. doughnut​

The two are interchangeable — pick whichever reads better in your layout. The doughnut's empty centre works nicely on a compact dashboard tile.

Tips​

  • Only the first row is used — aggregate the result into one row.
  • The slices follow the order of the datasets: add the largest one first so it leads.
  • For comparing many categories, prefer a bar chart instead.