xlsx/chart-pie

A PieChart added via ws.add_chart(...) on a worksheet produces a xl/charts/chart1.xml part whose <c:plotArea> carries a <c:pieChart> with a single <c:ser> bound to the category and value ranges.

Library verdicts: python-xlsx: — xlsxjs: pass

Metadata

Feature idxlsx/chart-pie
Formatxlsx
Categorycharts
Spececma-376-5-part-1 § 21.2.2.137 c:pieChart

XPath assertions

ID / partPredicateXPathpython-xlsxxlsxjs
chart-pie-present
xl/charts/chart1.xml
exist
The chart part must carry a <c:pieChart> element inside <c:plotArea>.
//c:pieChart
chart-pie-series-value-ref
xl/charts/chart1.xml
exist
The pie chart must have a series whose <c:val> points at a worksheet range via <c:numRef>/<c:f>. This confirms the chart is wired to sheet data.
//c:pieChart/c:ser/c:val/c:numRef/c:f

Render assertions

IDPredicateSelectorpython-xlsxxlsxjs
chart-pie-renderedcss_selector/ exist
A DOM node marked as a chart must be rendered. Most current xlsxjs-style renderers do not implement chart rendering — this assertion is expected to fail for those libraries and is the canonical fork signal.
.chart, [data-chart-type='pie'], [data-kind='chart'], svg.chart, .xlsx-chartpass
sheet-countcss_selector/ equal-count
Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet.
section.xlsx

Generator source

scripts/gen_chart_pie.py

#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/chart-pie.xlsx``.

A minimal one-sheet workbook with a three-slice data table
(Apples/30, Oranges/40, Bananas/20) and a PieChart anchored at
D1 bound to that data. Designed to satisfy the assertions in
``features/xlsx/chart-pie.json``.
"""

from __future__ import annotations

from pathlib import Path

from xlsx import Workbook
from xlsx.chart import PieChart, Reference

import datetime as _dt
_REPRODUCIBLE_DT = _dt.datetime(2000, 1, 1, 0, 0, 0)

_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "xlsx" / "chart-pie.xlsx"


def main() -> int:
    wb = Workbook()
    ws = wb.active
    ws["A1"] = "Apples"
    ws["B1"] = 30
    ws["A2"] = "Oranges"
    ws["B2"] = 40
    ws["A3"] = "Bananas"
    ws["B3"] = 20

    chart = PieChart()
    data = Reference(ws, min_col=2, min_row=1, max_row=3)
    cats = Reference(ws, min_col=1, min_row=1, max_row=3)
    chart.add_data(data, titles_from_data=False)
    chart.set_categories(cats)
    ws.add_chart(chart, "D1")

    _OUT.parent.mkdir(parents=True, exist_ok=True)
    wb.save(_OUT, zip_date_time=_REPRODUCIBLE_DT)
    print(_OUT)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "xlsx/chart-pie",
  "title": "Pie chart",
  "format": "xlsx",
  "category": "charts",
  "summary": "A PieChart added via ws.add_chart(...) on a worksheet produces a xl/charts/chart1.xml part whose <c:plotArea> carries a <c:pieChart> with a single <c:ser> bound to the category and value ranges.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "21.2.2.137",
    "element": "c:pieChart",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/DrawingML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/dml-chart.xsd",
    "notes": "ECMA-376 Part 1 clause 21.2.2.137 defines <c:pieChart>. Unlike <c:barChart>, the pie chart has no <c:barDir>/orientation — a pie is fundamentally radial, with a single implicit series. Its children are typically <c:varyColors val='1'/>, one or more <c:ser>, and <c:firstSliceAng> specifying the starting angle. python-xlsx's `from xlsx.chart import PieChart` emits this minimal shape. A companion 3D variant <c:pie3DChart> is specified separately in 21.2.2.138 and is NOT asserted here."
  },
  "fixtures": {
    "machine": "xlsx/chart-pie",
    "office": "xlsx/chart-pie"
  },
  "generator": {
    "python": "scripts/gen_chart_pie.py"
  },
  "assertions": [
    {
      "id": "chart-pie-present",
      "part": "xl/charts/chart1.xml",
      "namespaces": {
        "c": "http://schemas.openxmlformats.org/drawingml/2006/chart"
      },
      "xpath": "//c:pieChart",
      "must": "exist",
      "description": "The chart part must carry a <c:pieChart> element inside <c:plotArea>."
    },
    {
      "id": "chart-pie-series-value-ref",
      "part": "xl/charts/chart1.xml",
      "namespaces": {
        "c": "http://schemas.openxmlformats.org/drawingml/2006/chart"
      },
      "xpath": "//c:pieChart/c:ser/c:val/c:numRef/c:f",
      "must": "exist",
      "description": "The pie chart must have a series whose <c:val> points at a worksheet range via <c:numRef>/<c:f>. This confirms the chart is wired to sheet data."
    }
  ],
  "render_assertions": [
    {
      "id": "chart-pie-rendered",
      "kind": "css_selector",
      "selector": ".chart, [data-chart-type='pie'], [data-kind='chart'], svg.chart, .xlsx-chart",
      "must": "exist",
      "description": "A DOM node marked as a chart must be rendered. Most current xlsxjs-style renderers do not implement chart rendering — this assertion is expected to fail for those libraries and is the canonical fork signal."
    },
    {
      "id": "sheet-count",
      "kind": "css_selector",
      "selector": "section.xlsx",
      "must": "equal-count",
      "count": 1,
      "description": "Exactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet."
    }
  ]
}

Fixture

Download chart-pie.xlsx (6.2 KB)

Reference preview

Reference (machine, page 1 PNG)

xlsx/chart-pie page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

ECMA-376 Part 1 clause 21.2.2.137 defines <c:pieChart>. Unlike <c:barChart>, the pie chart has no <c:barDir>/orientation — a pie is fundamentally radial, with a single implicit series. Its children are typically <c:varyColors val='1'/>, one or more <c:ser>, and <c:firstSliceAng> specifying the starting angle. python-xlsx's `from xlsx.chart import PieChart` emits this minimal shape. A companion 3D variant <c:pie3DChart> is specified separately in 21.2.2.138 and is NOT asserted here.