Population pyramid reference

Pyramid examples

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

Mirrored ordered bands on one shared scale: band geometry is validated for equal width and contiguity, and the youngest band is rendered at the bottom no matter which way the data was authored. Type pyramid. Aliases: age-pyramid, population-pyramid.

Use cases

Chart IDs

One form; its chart ID is pyramid.

Minimal spec

{
  "type": "pyramid",
  "data": {
    "bands": [
      { "id": "junior", "from": 0, "to": 5 },
      { "id": "senior", "from": 5, "to": 10 },
      { "id": "long", "from": 10, "to": 15 }
    ],
    "groups": [
      { "id": "north", "label": "North", "values": [40, 30, 20] },
      { "id": "south", "label": "South", "values": [35, 25, 15] }
    ]
  },
  "options": {
    "title": "North has more employees in every tenure band",
    "unit": "employees",
    "source": "Illustrative data"
  }
}

Data

PathTypeRequiredMeaning
bandsarrayyesContiguous ordered bands, each with inclusive lower and exclusive upper bounds; only the last may be open-ended.
bands[].idstringyesUnique ordered-band identity used by keyed group values.
bands[].fromnumberyesInclusive lower bound.
bands[].tonumberEXCLUSIVE upper bound; contiguity is bands[i].to === bands[i+1].from. Omit on the LAST band only, to declare it open-ended.
bands[].labelstringAuthored band caption; omission derives a caption from its bounds.
groupsarrayyesExactly two groups displayed on opposite sides using the same scale.
groups[].idstringyesGroup identity for one side of the population pyramid.
groups[].labelstringDisplayed group name; defaults to its id.
groups[].datestringISO observation date for dated group comparisons. CAGR needs a positive date interval; age-band bounds do not supply time.
groups[].valuesarrayyesCounts or amounts, one per band. Shares are DERIVED: a percent cell, a null, a negative or a non-finite value is refused with its own error code.
groups[].values[].bandIdstringyesBand id identifying this group value independently of array position.
groups[].values[].valuenumber | nullyesRaw count or amount for the band; percentages are derived. Null is refused during layout.
groups[].colorRolestringTheme color role for this group of pyramid bars. 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.

Options

PathTypeValuesDefaultMeaning
columnOverridesobjectSettings per generated column. Ids: label.
columnOverrides.*.widthnumberTrack width in px. It beats the width the type would pick.
columnOverrides.*.alignstring'left', 'right', 'center'Alignment of the column: its cell text and, unless headAlign is set, its head. Bars keep starting at the panel origin.
basisstring'count', 'shareOfTotal', 'shareOfGroup''count'Default 'count'. 'shareOfTotal' divides by the grand total across BOTH groups and all bands — never per group, which would hide the group-size imbalance a pyramid is read for. 'shareOfGroup' divides each side by its own total, so each side sums to 100%; 'shareOfTotal' on two groups that both carry a date draws 'shareOfGroup', because two snapshots have no common whole.
methodNotebooleanDefault false. true adds the method footnote stating the band convention: [from, to), youngest at the bottom, equal widths. An open-ended top band and the share base are required for interpretation and print regardless.

Plus the shared options. This type does not accept detailFields, valueAxis, hatchStrength, rounding. This type ignores animate, debug, rowLabels, categoryAxis, categoryLabels, secondaryAxis, sort, topN, valueAxis.show, valueAxis.gridlines 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.
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.
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.
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 280 × 270 px; fit fill. Below 270 px high, down to the compact floor of 280 × 180 px, the chart draws in compact mode; belowMinimum: 'refuse' refuses there instead.

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
germany-age-structureexampleA barrel, not a pyramid: the 45–54 cohorts are the widest rows
workforce-tenure-genderexampleWomen outnumber men below four years of tenure and are outnumbered above ten
torture-pyramid-degeneratetorture22 bands, one empty in both groups, a 10:1 group imbalance and an open top band
dated-population-comparisonexampleGrowth within the same age band across two observation dates
dated-share-differenceexampleEach snapshot is its own 100%, and a difference between shares is measured in percentage points
column-overridesexamplecolumnOverrides sets the width and alignment of the band column

Not for

More than two groups or unordered bands; pyramid mirrors two groups over contiguous ordered bands.