Skip to content

Chart: emit single-level c:strRef categories and relative chart rel targets#1465

Open
eliasaronson wants to merge 1 commit into
gitbrent:masterfrom
eliasaronson:fix/idiomatic-chart-categories-and-relative-targets
Open

Chart: emit single-level c:strRef categories and relative chart rel targets#1465
eliasaronson wants to merge 1 commit into
gitbrent:masterfrom
eliasaronson:fix/idiomatic-chart-categories-and-relative-targets

Conversation

@eliasaronson

@eliasaronson eliasaronson commented Jul 4, 2026

Copy link
Copy Markdown

Change Summary

Two small changes to how charts are serialized so the output matches what PowerPoint itself writes, improving compatibility with other consumers (Google Slides, LibreOffice, and OOXML parsers) with no change to how PowerPoint renders the charts.

Change Description

  1. src/gen-charts.ts — categories: bar/line/area charts wrote single-level string categories as <c:multiLvlStrRef> (the multi-level form). This now emits the idiomatic single-level <c:strRef> when there is exactly one category level, falling back to <c:multiLvlStrRef> only for genuine multi-level categories. This mirrors the pie/doughnut category code, which already uses <c:strRef>.

  2. src/gen-xml.ts — relationship target: the slide→chart relationship Target was written as an absolute /ppt/charts/chartN.xml. PowerPoint writes this relative (../charts/chartN.xml). The target is now relativized in the slide .rels, while the [Content_Types].xml Override PartName (which requires the absolute form) is left unchanged.

Both prior forms are valid OOXML that PowerPoint tolerates, but they diverge from PowerPoint's own output.

Change Type

  • Bug fix
  • New feature
  • Documentation update

No new/changed public properties or APIs, so no core-interfaces.ts / types/index.d.ts / demo changes are required.

Motivation and Context

Charts produced by pptxgenjs render correctly in PowerPoint but:

  • Google Slides / LibreOffice mis-render the category axis (caused by the single-level multiLvlStrRef).
  • Strict OOXML parsers (e.g. pptxtojson) either can't read the category labels or drop the chart entirely — the latter because they resolve the absolute relationship target to an invalid path.

Aligning both to PowerPoint's idiomatic output fixes these while leaving PowerPoint rendering identical.

Verification

  • npm run build compiles cleanly with the changes.
  • Verified end-to-end that a generated bar chart now round-trips through an OOXML parser: the <c:cat> is a single-level <c:strRef>, the slide rel target is ../charts/chart1.xml, and category labels + values parse correctly.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in the changed areas
  • "Run All Demos" browser check — not run (headless); please verify in CI/demo

…argets

Bar/line/area charts wrote single-level string categories as
c:multiLvlStrRef, and the slide->chart relationship Target as an absolute
/ppt/charts/chartN.xml. Both are valid OOXML that PowerPoint tolerates,
but they differ from what PowerPoint itself produces (and from the
pie/doughnut category code, which already uses c:strRef). Consequences in
other consumers: Google Slides and LibreOffice mis-render the category
axis, and strict parsers (e.g. pptxtojson) fail to read the labels or drop
the chart entirely.

- gen-charts.ts: emit single-level c:strRef when there is one category
  level; fall back to c:multiLvlStrRef only for genuine multi-level
  categories.
- gen-xml.ts: relativize the chart relationship Target in the slide rels
  to ../charts/chartN.xml, leaving the absolute Content_Types PartName
  (which requires the absolute form) unchanged.

No change to how PowerPoint renders these charts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant