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

Provide a category column and a single numeric column:

SELECT
status AS "Status",
COUNT(*) AS "Tickets"
FROM tickets
GROUP BY status
ORDER BY COUNT(*) DESC;

Status supplies the slice labels and Tickets supplies the slice sizes. Choose Pie or Doughnut as the chart type.

Keep the slices few

Pie and doughnut charts are only readable with a handful of slices. If your query returns many categories, group the small ones together in SQL:

SELECT
CASE WHEN rn <= 5 THEN status ELSE 'Other' END AS "Status",
SUM(cnt) AS "Tickets"
FROM (
SELECT status, COUNT(*) AS cnt,
ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS rn
FROM tickets
GROUP BY status
) t
GROUP BY CASE WHEN rn <= 5 THEN status ELSE 'Other' END;

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

  • Use a single numeric series — pie/doughnut charts plot one value per slice.
  • Sort by size with ORDER BY so the largest slice leads.
  • For comparing many categories, prefer a bar chart instead.