A BarChart added via ws.add_chart(...) on a worksheet produces a xl/charts/chart1.xml part whose <c:plotArea> carries a <c:barChart> with a <c:barDir val='col'/> (default orientation — python-xlsx emits a vertical column chart for BarChart).
Library verdicts: python-xlsx: — xlsxjs: pass
| Feature id | xlsx/chart-bar |
|---|---|
| Format | xlsx |
| Category | charts |
| Spec | ecma-376-5-part-1 § 21.2.2.16 c:barChart |
| ID / part | Predicate | XPath | python-xlsx | xlsxjs |
|---|---|---|---|---|
chart-bar-directionxl/charts/chart1.xml | existThe chart part must carry <c:barChart>/<c:barDir> with val='bar' or val='col'. Both are spec-valid orientations of a bar chart; python-xlsx emits 'col' (vertical columns) for its BarChart default. | //c:barChart/c:barDir[@val='bar' or @val='col'] | — | — |
chart-bar-series-value-refxl/charts/chart1.xml | existThe bar chart must have at least one series whose <c:val> points at a worksheet range via <c:numRef>/<c:f>. This confirms the chart is wired to sheet data, not an embedded literal cache. | //c:barChart/c:ser/c:val/c:numRef/c:f | — | — |
| ID | Predicate | Selector | python-xlsx | xlsxjs |
|---|---|---|---|---|
chart-bar-rendered | css_selector/ existA 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='bar'], [data-chart-type='column'], [data-kind='chart'], svg.chart, .xlsx-chart | — | pass |
sheet-count | css_selector/ equal-countExactly one rendered sheet section. Catches renderers that emit zero sheets (hard failure) or duplicate a sheet. | section.xlsx | — | — |
scripts/gen_chart_bar.py
#!/usr/bin/env python3
"""Generate ``fixtures/xlsx/chart-bar.xlsx``.
A minimal one-sheet workbook with a three-row data table
(Q1/10, Q2/20, Q3/30) and a BarChart anchored at D1 bound to
that data. python-xlsx's BarChart emits a <c:barChart> with
<c:barDir val='col'/> (vertical columns) by default. Designed
to satisfy the assertions in ``features/xlsx/chart-bar.json``.
"""
from __future__ import annotations
from pathlib import Path
from xlsx import Workbook
from xlsx.chart import BarChart, 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-bar.xlsx"
def main() -> int:
wb = Workbook()
ws = wb.active
ws["A1"] = "Q1"
ws["B1"] = 10
ws["A2"] = "Q2"
ws["B2"] = 20
ws["A3"] = "Q3"
ws["B3"] = 30
chart = BarChart()
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())
{
"$schema": "../manifest.schema.json",
"id": "xlsx/chart-bar",
"title": "Bar / column chart",
"format": "xlsx",
"category": "charts",
"summary": "A BarChart added via ws.add_chart(...) on a worksheet produces a xl/charts/chart1.xml part whose <c:plotArea> carries a <c:barChart> with a <c:barDir val='col'/> (default orientation — python-xlsx emits a vertical column chart for BarChart).",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "21.2.2.16",
"element": "c:barChart",
"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.16 defines <c:barChart>; its child <c:barDir val='bar'/> means horizontal (rows/bars) and val='col' means vertical (columns). Both shapes share the <c:barChart> element — the orientation is carried by <c:barDir>. python-xlsx's `from xlsx.chart import BarChart` defaults to vertical columns (barDir='col'), matching the openpyxl lineage. The XPath below accepts either 'bar' or 'col' so the assertion is robust across writer choices, but records the observed python-xlsx value in the sibling xl/charts/chart1.xml fixture."
},
"fixtures": {
"machine": "xlsx/chart-bar",
"office": "xlsx/chart-bar"
},
"generator": {
"python": "scripts/gen_chart_bar.py"
},
"assertions": [
{
"id": "chart-bar-direction",
"part": "xl/charts/chart1.xml",
"namespaces": {
"c": "http://schemas.openxmlformats.org/drawingml/2006/chart"
},
"xpath": "//c:barChart/c:barDir[@val='bar' or @val='col']",
"must": "exist",
"description": "The chart part must carry <c:barChart>/<c:barDir> with val='bar' or val='col'. Both are spec-valid orientations of a bar chart; python-xlsx emits 'col' (vertical columns) for its BarChart default."
},
{
"id": "chart-bar-series-value-ref",
"part": "xl/charts/chart1.xml",
"namespaces": {
"c": "http://schemas.openxmlformats.org/drawingml/2006/chart"
},
"xpath": "//c:barChart/c:ser/c:val/c:numRef/c:f",
"must": "exist",
"description": "The bar chart must have at least one series whose <c:val> points at a worksheet range via <c:numRef>/<c:f>. This confirms the chart is wired to sheet data, not an embedded literal cache."
}
],
"render_assertions": [
{
"id": "chart-bar-rendered",
"kind": "css_selector",
"selector": ".chart, [data-chart-type='bar'], [data-chart-type='column'], [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."
}
]
}
