Pie and doughnut chart reference

Pie and doughnut examples

Contents: Use cases, Chart IDs, Minimal spec, Data, Options, Annotations, Sizing, Fixtures, Not for.

Share-of-total slices with inside/outside label cascade, doughnut center total, explode. Type pie. Aliases: doughnut, donut.

Use cases

Chart IDs

Minimal spec

{
  "type": "pie",
  "data": {
    "categories": [{ "id": "renewals", "label": "Renewals" }, { "id": "new", "label": "New" }],
    "series": [{ "id": "revenue", "label": "Revenue", "values": [70, 30] }]
  },
  "options": { "unit": "$k", "title": "Renewals contribute 70% of revenue", "source": "Illustrative data" }
}

Data

A cell is a number, null or a value object; see Value cell.

PathTypeRequiredMeaning
valueKindstringDefault valueKind for all series. One of 'fraction'.
categoriesarrayyesSlice categories in source order; sorting and topN may change the displayed order.
categories[].idstringyesCategory identity used to match keyed values and annotation anchors.
categories[].labelstringDisplayed category name; defaults to the category id and supports line breaks. A date id or date without a label prints a short date such as '4 Sep'.
categories[].datestringAccepted ISO 8601 date metadata; pie slices do not use a date axis.
categories[].footnoteinteger1-based reference into options.footnotes. The note it points at keeps that number, and notes the engine derives print unnumbered; this type draws no mark at the label, because a slice label composes the category name with its value and share and the number would land inside that phrase.
seriesarrayyesSlice values from the first non-reference series; additional series are ignored with a warning.
series[].valueKindstringMultiply numbers by 100 into pct cells; explicit pct cells stay in percent units. One of 'fraction'.
series[].idstringyesSeries identity used by keyed options, annotations and legend entries.
series[].labelstringDisplayed series name; defaults to the series id.
series[].values(cell | { categoryId, value: cell })[]yesValues in category order, or keyed entries pairing a categoryId with its value.
series[].scenariostringAC, PY, PL, FC (or ACT, BUD, FCST, LY for last year). Codes and aliases accept any case. Controls scenario labels and paint conventions.
series[].rolestringData series or comparison-only reference series; references are excluded from the main plotted data. One of 'data', 'reference'.
series[].colorRolestringTheme color role used for a single displayed slice; multi-slice charts use the selected slice ramp. One of good, bad, warn, neutral, neutralLight, highlight, total, others; series-N for step N of the theme ramp, 1-based (series-2 is color.series[1]); or status-<key> for a theme status color. A hex color goes in fill.
series[].unitstringUnit shown with this series values and used to check shared-scale compatibility.
series[].formatstringFormat-by-example for this series values, for example 1,234 or 1.2%.

Options

PathTypeValuesDefaultMeaning
labelsfalse | objectfalse (or another value of its type)Up to four displayed slices (eight without a legend) default to named outside labels with leaders in two columns; without a legend every label names its slice at any count. Explicit inside/outside settings take priority.
topNobject | integerDefaults to the seven largest slices plus Others, merged only when Others would hold three slices or more; an authored topN overrides the default. A positive integer n means { n }.
doughnutnumberHole radius as a fraction of outer radius. Inside labels cap the hole at 0.72; center totals include the declared unit.
rotatenumber0, 90, 180, 270Starting angle clockwise from 12 o'clock, in quarter turns. Defaults to 0 degrees.
explodeobjectSlice category ids mapped to outward offsets as fractions of the outer radius.
colorsstring'categorical', 'sequential'Slice color strategy. Default 'sequential': one ramp of the first series color in slice order, the first slice strongest, at every slice count. 'categorical' gives each slice its own theme hue. A highlight keeps its accent and steps the other slices into gray.
othersShadestring'quietest', 'apart'Sequential ramp beside an Others slice. Without an Others slice the ramp does not change. Default 'quietest'. 'quietest': Others is the quietest part, so every named step has more contrast against the background than Others and none matches it. 'apart': named steps only differ from Others, and some may be quieter. If Others is stronger than the first named step, the ramp falls back to 'apart' and the chart warns others-shade-unavailable.

Plus the shared options. This type does not accept labelPosition, valueAxis, hatchStrength. This type ignores animate, debug, rowLabels, categoryAxis, categoryLabels, secondaryAxis, bandFraction, valueAxis.show, valueAxis.gridlines, topN.threshold with an option-ignored warning.

Annotations

An annotation anchor is a category or item id string, or an object with categoryId plus optional seriesId, segmentId and edge (start, end, total); pointId addresses a scatter point. Category anchors, including from/to, take category ids, not category labels.

KindPurposeRequiredAnchorsOptional fieldsNotes
cagrDraws a growth arrow between two anchored points and computes the compound annual growth rate from their values and ISO-date span.from: AnchorRef (optional); to: AnchorRef (optional)suffix: string, default 'p.a.'. Text after the rate. period: boolean. Print the period before the rate from the anchors' category labels, '2014–2019: +5.8% p.a.'. Default true when the chart carries two or more CAGRs, so nested brackets are told apart by their text, false otherwise. An arrow's ends show its span, so an arrow prints the rate alone unless period is true. shape: bracket | arrow, default bracket. arrow draws one straight arrow over the marks with the rate in an oval on it, lifted until it clears them. Where no straight line clears the chart, the span is too short for the oval, a stack's inner layer is the anchor or the chart lays comparisons out itself, it draws the bracket and warns cagr-arrow-no-room.Omitted endpoints span the first to the last category, or the first to the last total on a waterfall. Resolved endpoints need a positive date interval from ISO dates or year-bearing labels and a positive start value; an end of zero reads -100%, and a start at or below zero or a negative end omits the rate and warns cagr-undefined. On a continuous time axis the years are the exact span between the two readings. An anchor on one series of several (seriesId, or a category of an unstacked line, which reads the first drawn series; on a stack a category reads the stack total) names that series in the label, "Product B +10.1% p.a.", and the arm runs from that series' segment or point. In text, ${value} prints the rate with its suffix, so "CAGR 2014–2019: ${value}" keeps the computed number.
diffDraws a level-difference arrow between two anchors and computes either percent change or their signed value difference.from, tofrom: AnchorRef; to: AnchorRefmode: relative | absolute | reversed | both, default relative. relative prints the percent change from 'from' to 'to', reversed the change from 'to' to 'from', absolute the value difference, both the value difference with the percent change beside it.Mode defaults to relative. Relative and reversed changes need a nonzero base; negative bases use its absolute magnitude and emit a warning. Absolute mode reports the raw value difference. A hidden label removes its arm.
notePlaces authored text at an anchored data element through collision avoidance, with an optional icon or status chip.at, textat: AnchorRef
calloutPlaces authored free text at an anchored data element, routing a leader when displaced and honoring the preferred side.at, textat: AnchorRefpreferSide: left | right | above | below. Side the solver tries first; the label keeps a leader when it moves. headline: string. A bold first line over the text, which then prints in plain type; ${value} in it prints the anchored value from the data. Example: "headline": "${value}", "text": "Peak in handheld-loom demand" prints 153 in bold over the words. arrow: boolean, default false. An arrow from the text to the anchored point, in the arrow standard of theme marks.arrow: the text stands far enough out for a 24 px shaft, level with the point right or left of it, or over or under it, where there is room. With no such seat it draws without the arrow and warns callout-arrow-no-room. Not with icon or status. Example: "arrow": true.
deltaComputes the signed difference between an anchored value and another anchor or literal, then places a collision-managed label at the first anchor.at, vsat: AnchorRef; vs: AnchorRef | numbermode: absolute | relative | both, default absolute. absolute prints at minus vs, relative the percent change from vs to at, both the two as '+149 (+36%)'. relative and both need a nonzero vs.
absReads the anchored data value and places its formatted absolute value in a collision-managed label.atat: AnchorRef
textPlaces authored text at a point through the label solver: on the point, or above, below, right or left of it. The text prints as written.at, textat: AnchorRef | { categoryId, value }A point is an anchor or { categoryId, value } with value in axis units. A value outside the plot, a chart with no value scale or an anchor that does not resolve warns bad-anchor and draws nothing; the axis does not grow. The text prints as written, ${value} included. It takes id and priority, and no other field.
lineDraws a straight line between two points or from a text annotation, in the ink and rule width of a bracket; a stretch that would cross text is cut.from, tofrom: AnchorRef | { categoryId, value } | { annotationId }; to: AnchorRef | { categoryId, value } | { annotationId }dashed: boolean, default false. Draws the line in the dash of a reference line.A point is an anchor or { categoryId, value } with value in axis units. A value outside the plot, a chart with no value scale or an anchor that does not resolve warns bad-anchor and draws nothing; the axis does not grow. An end { annotationId } names a text annotation: the line starts or ends at the nearest edge of that text, at every size, and is not drawn when the text is not. A { categoryId, value } end stands on the category's center. A stretch that would cross text is cut and warns draw-crosses-text. It takes dashed and id, and no other field.
arrowDraws a straight arrow between two points or from a text annotation to a point, in the theme arrow look (marks.arrow); a stretch that would cross text is cut.from, tofrom: AnchorRef | { categoryId, value } | { annotationId }; to: AnchorRef | { categoryId, value } | { annotationId }dashed: boolean, default false. Draws the shaft in the dash of a reference line.A point is an anchor or { categoryId, value } with value in axis units. A value outside the plot, a chart with no value scale or an anchor that does not resolve warns bad-anchor and draws nothing; the axis does not grow. An end { annotationId } names a text annotation: the arrow starts or ends at the nearest edge of that text, at every size, and is not drawn when the text is not. A { categoryId, value } end stands on the category's center. A stretch that would cross text is cut and warns draw-crosses-text. It takes dashed and id, and no other field.
boxDraws an unfilled box with two points as opposite corners, wrapping whole category bands, in the ink and rule width of a bracket; text inside the box stays free.from, tofrom: AnchorRef | { categoryId, value }; to: AnchorRef | { categoryId, value }dashed: boolean, default false. Draws the edges in the dash of a reference line.A point is an anchor or { categoryId, value } with value in axis units. A value outside the plot, a chart with no value scale or an anchor that does not resolve warns bad-anchor and draws nothing; the axis does not grow. from and to are opposite corners, the box has no fill, and text inside it stays free. A { categoryId, value } corner spans that category's whole band, so the box wraps whole bars, values and markers; from and to on one category wrap that category. A stretch that would cross text is cut and warns draw-crosses-text. It takes dashed and id, and no other field.

Sizing

Floor 120 × 320 px; fit content. Below 320 px high, down to the compact floor of 280 × 160 px, the chart draws in compact mode; belowMinimum: 'refuse' refuses there instead. Narrower than the compact floor, a pie draws while its circle keeps a radius of at least 36 px beside its labels.

Below the floor a render is refused with size-below-floor and the pixels it needs. measure returns the natural and comfortable size for a given spec; see Sizing in the manual.

Fixtures

IDKindUse case
streaming-genre-shareexampleMarket-share pie with named value · share labels in two columns
doughnut-device-revenueexampleDoughnut with center total and one exploded slice
ten-tiny-slicestortureTorture: one leader + ten tiny slices force the outside cascade and spread
dominant-slicetortureTorture: 92% dominant slice (large-arc path) with a callout on the rest
fifty-fiftytortureTorture: exact 50/50 split, rotated 90°, doughnut center total
topn-others-explodetortureTorture: topN Others (exploded, always last) + ignored second series
full-explode-envelopetortureTorture: full-range explode with shifted-circle outside labels
doughnut-four-channel-revenueexampleFour named outside labels and a center total with its unit
highlight-channelexampleHighlight keeps the named slice in color and grays the rest
device-revenue-rotation-90tortureDevice revenue doughnut rotated 90 degrees
device-revenue-rotation-180tortureDevice revenue doughnut rotated 180 degrees
device-revenue-rotation-270tortureDevice revenue doughnut rotated 270 degrees
others-renamedexampleThe aggregated slice named through strings.others
channel-spend-differenceexampleSearch spend exceeds Social by 80
slice-outline-offexampleA sequential ramp to a pale step, the Others slice in the theme color, no slice outlines
others-shade-apartexampleOthers only has to differ from the named slices (othersShade 'apart')
four-channels-full-labelstortureThe four channels with the full label density

Not for

Negative parts; pie divides a nonnegative whole. A negative slice is not drawn and the center total is left out.