* feat: live examples in the docs, which run, draw the document next to the code, and can be edited and downloaded The docs' code examples were plain snippets, often fragments that couldn't run. A code block marked ```ts live is now an example readers can see and change: the page runs it with docx, draws the document it makes next to the code with docx-preview, and offers the .docx to download. Clicking the code opens an editor (Monaco) that knows docx's types, the pages are drawn again as the code changes, and View closes the editor. Split, Code and Preview show the code and the pages side by side, or one of them. The demos a page includes are live too. Every example in the docs that builds or patches a document is now live: 443 of them, each a whole file with its imports, so it runs as written. Code about other things, such as installing, bundlers or servers, stays plain. Running them showed docs that were wrong, fixed here: - Landscape: docx swaps a landscape page's width and height itself, so the docs' swapped sizes made a tall page marked as landscape - Comments: `comments.children` takes plain objects, not `new Comment(...)` - Custom properties are text only - APIs that no longer exist: MathText, Row, `.then` on Packer.toStream, patchDocument(buffer, ...), createParagraph().heading1(), a border's `value`, TextRun's `.break()` - The templates and patcher examples read files that aren't in the repository. They now patch the templates in demo/assets, or make their own `npm run build.docs` copies docx's browser builds into docs/live-examples/lib, so the docs use the docx they describe, and the Pages workflow runs it. The folder is gitignored, and cspell and ESLint skip it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ * docs: the bullet examples draw a bullet, and the patcher's usage writes the patched document "ὠ" is U+1F60, a Greek omega, since \u takes four hex digits, so the two live bullet examples on the numbering page drew it as each item's bullet. They use "•" now. The patcher's usage example now awaits patchDocument and writes the document it makes, as the example after it does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
4.4 KiB
Chart Colours
Charts are drawn in the colours of the document's theme, as in Word. This page shows the colours a chart takes, and how to choose your own.
The Theme's Colours
Each series takes the next of the theme's six accent colours. In the theme docx writes, Office's, they are:
| Series | Theme colour | Colour |
|---|---|---|
| 1 | accent1 |
Blue |
| 2 | accent2 |
Orange |
| 3 | accent3 |
Grey |
| 4 | accent4 |
Gold |
| 5 | accent5 |
Blue |
| 6 | accent6 |
Green |
After the sixth series, the six colours come round again in darker and lighter shades, as in Word.
The slices of a pie or doughnut chart take the accent colours in the same way, one for each category.
Colours from the theme change when the document's theme does, as they do in Word. Give the document a theme of its own to change every chart's colours at once. See Themes.
A Colour of Your Own
Give a series a color of its own:
- a 6-digit hex colour, such as
"1F4E79"; - or one of the theme's colours, lighter or darker if you like, as Word's colour menus offer them:
{ theme: "accent2", lighter: 40 }is "Orange, Accent 2, Lighter 40%".
import { Document, Paragraph } from "docx";
import { ChartRun } from "docx/charts";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new ChartRun({
type: "column",
categories: ["Jan", "Feb", "Mar"],
series: [
{ name: "Planned", values: [30, 80, 40], color: "1F4E79" },
{ name: "Extra", values: [5, 20, 15], color: { theme: "accent2", lighter: 40 } },
],
}),
],
}),
],
},
],
});
The colour is the colour of the series' bars, line, area, points or bubbles. Bubbles are drawn in it a quarter see-through, as Office draws them. A line can have a colour of its own too, apart from its markers: see Lines.
Bar Colours
A series of bars takes colors, with a colour for single bars, in the order of the categories:
import { Document, Paragraph } from "docx";
import { ChartRun } from "docx/charts";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new ChartRun({
type: "column",
categories: ["Mon", "Tue", "Wed", "Thu"],
series: [{ name: "Tickets", values: [42, 57, 38, 71], colors: [undefined, undefined, undefined, "70AD47"] }],
}),
],
}),
],
},
],
});
A bar without a colour, or with undefined, keeps the series' colour. See Column and Bar Charts.
Slice Colours
A pie or doughnut series takes colors, with a colour for each slice, in the order of the categories:
import { Document, Paragraph } from "docx";
import { ChartRun } from "docx/charts";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new ChartRun({
type: "pie",
categories: ["North", "South", "East", "West"],
series: [
{ name: "Share", values: [40, 25, 20, 15], colors: ["1F4E79", "2E75B6", undefined, { theme: "accent6" }] },
],
}),
],
}),
],
},
],
});
A slice without a colour, or with undefined, keeps the theme's colour. See Pie and Doughnut Charts.
The Rest of the Chart
The chart's background, text, axes and gridlines are in the look Word gives a new chart: a white background, dark grey text and light grey lines, from the theme's light1 and dark1 colours. Chart Fonts and Fills shows how to give the text, the background and the border colours of their own.