DOCX
Charts
Add charts to documents — column, line, pie, doughnut, radar, bubble and more
Embed charts in documents using the chart property inside a paragraph's children. Charts are configured with a flat options object — pass type, categories, and series directly.
Basic Column Chart
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"chart": {
"type": "column",
"categories": ["Q1", "Q2", "Q3", "Q4"],
"series": [{ "name": "Sales", "values": [10, 20, 15, 25] }],
"title": "Quarterly Sales",
"transformation": { "width": "13.2cm", "height": "7.9cm" }
}
}
]
}
}
]
}
]
}
import { generateDocument } from "@office-open/docx";
await generateDocument({
sections: [
{
children: [
{
paragraph: {
children: [
{
chart: {
type: "column",
categories: ["Q1", "Q2", "Q3", "Q4"],
series: [{ name: "Sales", values: [10, 20, 15, 25] }],
title: "Quarterly Sales",
transformation: { width: "13.2cm", height: "7.9cm" },
},
},
],
},
},
],
},
],
});
Chart Types
The type property selects the chart kind:
| Type | Value |
|---|---|
| Column | "column" |
| Bar | "bar" |
| Line | "line" |
| Pie | "pie" |
| Area | "area" |
| Scatter | "scatter" |
| Doughnut | "doughnut" |
| Radar | "radar" |
| Bubble | "bubble" |
| Stock | "stock" |
| Surface | "surface" |
Set threeD: true to render column, bar, line, pie, or area as 3D variants.
Multi-Series Chart
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"chart": {
"type": "column",
"categories": ["Q1", "Q2", "Q3", "Q4"],
"series": [
{ "name": "Product A", "values": [10, 20, 15, 25] },
{ "name": "Product B", "values": [15, 10, 20, 30] }
],
"transformation": { "width": "13.2cm", "height": "7.9cm" }
}
}
]
}
}
]
}
]
}
{
chart: {
type: "column",
categories: ["Q1", "Q2", "Q3", "Q4"],
series: [
{ name: "Product A", values: [10, 20, 15, 25] },
{ name: "Product B", values: [15, 10, 20, 30] },
],
transformation: { width: "13.2cm", height: "7.9cm" },
},
}
Line Chart
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"chart": {
"type": "line",
"categories": ["Jan", "Feb", "Mar", "Apr", "May"],
"series": [{ "name": "Revenue", "values": [100, 150, 200, 180, 250] }],
"transformation": { "width": "13.2cm", "height": "7.9cm" }
}
}
]
}
}
]
}
]
}
{
chart: {
type: "line",
categories: ["Jan", "Feb", "Mar", "Apr", "May"],
series: [{ name: "Revenue", values: [100, 150, 200, 180, 250] }],
transformation: { width: "13.2cm", height: "7.9cm" },
},
}
Pie Chart
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"chart": {
"type": "pie",
"categories": ["Desktop", "Mobile", "Tablet"],
"series": [{ "name": "Traffic", "values": [50, 35, 15] }],
"transformation": { "width": "10.6cm", "height": "7.9cm" }
}
}
]
}
}
]
}
]
}
{
chart: {
type: "pie",
categories: ["Desktop", "Mobile", "Tablet"],
series: [{ name: "Traffic", values: [50, 35, 15] }],
transformation: { width: "10.6cm", height: "7.9cm" },
},
}
Scatter Chart
Scatter charts use xValues and yValues instead of categories:
{
"sections": [
{
"children": [
{
"paragraph": {
"children": [
{
"chart": {
"type": "scatter",
"categories": [],
"series": [
{
"name": "Dataset 1",
"values": [],
"xValues": [1, 2, 3, 4, 5],
"yValues": [2, 4, 1, 5, 3]
}
],
"transformation": { "width": "13.2cm", "height": "7.9cm" }
}
}
]
}
}
]
}
]
}
{
chart: {
type: "scatter",
categories: [],
series: [
{
name: "Dataset 1",
values: [],
xValues: [1, 2, 3, 4, 5],
yValues: [2, 4, 1, 5, 3],
},
],
transformation: { width: "13.2cm", height: "7.9cm" },
},
}
Chart Options
| Option | Type | Description |
|---|---|---|
type | string | Chart type (see table above) |
categories | string[] | Category labels |
series | { name, values }[] | Series data |
transformation | { width, height } | Display dimensions |
title | string | Chart title |
showLegend | boolean | Show legend (default: true) |
style | number | Style preset (2–48) |
threeD | boolean | Enable 3D rendering |
floating | object | Floating positioning options |