Progressive OPF lesson
Make a comparison you can inspect
Use honest magnitude bars, visible units and one shared dataset for the chart and table.
Each preview is a prepared render of its complete OPF example. The selected step records its render toolchain separately from the editable source.
Step 1
Start with the actual values
A bar chart compares fictional values of 5.8 and 6.7 minutes. The value axis includes zero.
Try this
Change one numeric value while keeping the unit and the illustrative label.
Prepared render of this step. View full-size SVG.
Download or copy the complete OPF below, then paste it into the Playground to try the change. Prepared previews do not update live.
Loading OPF…
Next: Check your deck.
Preview versions: Core 0.37.1 · renderer 0.37.1 · Gallery 0.37.1
Prepared with the recorded installed packages; this identity does not certify registry provenance or native fidelity. Documentation source OpenPresentation/opf@9c9fadf14275. Render identity records.
Add a chart to a generated deck
To add a data chart to a slide you generate, give the slide a chart with a type and its data: one table of columns and rows. The first column is usually the category, and each row holds one value per column, in the same order. The deck stays JSON, so a script or a language model writes a chart the same way it writes a title. This is the smallest valid chart slide:
{
"slides": [
{
"title": "Revenue by quarter",
"chart": {
"type": "bar",
"data": {
"columns": ["Quarter", "Revenue"],
"rows": [["Q1", 12], ["Q2", 15], ["Q3", 18]]
}
}
}
]
}The steps above build on that: real values, named axes and units, data labels, and one dataset shared by a chart and a table.
From a CSV file
When the numbers already live in a spreadsheet export, opf ingest turns the rows into a chart or table slide, so nobody retypes them. These commands ran with OPF CLI 0.29.1 in a project set up as in the first local run:
Step,Before (min),After (min)
Sign-up,6.7,5.8
First deck,12.4,9.1
Export,3.2,2.5opf create deck.opf.json --title "Pilot results"
opf ingest task-times.csv --as chart --into deck.opf.json -i --chart-type bar --title "Task time, before and after" --dataset taskTimes
opf ingest task-times.csv --as table --into deck.opf.json -i --title "The same numbers" --dataset taskTimes
opf validate deck.opf.json --fail-on warning
opf convert deck.opf.json deck.pptx
opf convert deck.opf.json deck.pdfWith --dataset, the rows are stored once under the deck's datasets and both slides refer to taskTimes, as in step 4. The same inputs always give the same slide id and the same bytes, so re-running the script does not churn the file. Use --category and --series to choose which columns become categories and series.
Choose a chart type
The default catalog has 27 chart types. Besides bar, column, line, area, pie, doughnut and scatter, there are stacked and 100% stacked variants, combo, waterfall, funnel, histogram, pareto, box-and-whisker, radar, treemap and world. opf catalog chart-types lists them with the data mappings each one supports.
Make it readable
The lesson's rules hold for generated charts too:
- Compare magnitudes with bars on an axis that starts at zero.
- Name the quantity and its unit in the axis titles.
- Show values with data labels when readers need the exact numbers.
- State the point in words. The validator reports a chart with no alt text and no text beside it, and suggests
chart.altor a subtitle.
opf validate also catches the mistakes a generator makes most: a chart or table that names a dataset that does not exist, a mapping that names a missing column, and a value that is text instead of a number.
In PowerPoint and PDF
In this example, opf convert deck.opf.json deck.pptx writes the bar chart as a PowerPoint chart object with its data in an embedded worksheet, so it can be edited in PowerPoint. opf convert deck.opf.json deck.pdf draws the same chart into the PDF.
Targets and reference lines
New in OPF 0.34.0.
chart.referenceLinesneeds OPF 0.34.0 or later; OPF 0.33 and earlier reject it. Before 0.34, a title or subtitle that compared the data with a value ("stayed above 92%") drew a dashed line. 0.34 removed that inference: Upgrading to 0.34 shows how to keep such a line.
A target belongs in chart.referenceLines. Its numeric value uses the same units as its associated value axis; the label is optional plain text. Titles and subtitles never create reference lines or period bands. A label such as "Target 25%" does not supply the numeric value.
This example keeps the main data line solid and gives its target an independent dashed stroke. A second, dotted line marks the minimum. The series column's format: "0%" displays fractions as percentages: 0.25 means 25%, while 25 means 2500%.
{
"language": "en-US",
"slides": [
{
"title": "Conversion and target",
"text": "Conversion is improving. The target is 25%.",
"chart": {
"type": "line",
"alt": "Conversion rises from 18% to 23%, below the 25% target.",
"axisTitles": { "category": "Week", "value": "Conversion rate" },
"data": {
"columns": ["Week", { "name": "Conversion", "format": "0%" }],
"rows": [["W1", 0.18], ["W2", 0.21], ["W3", 0.23]]
},
"referenceLines": [
{
"value": 0.25,
"label": "Target 25%",
"stroke": { "color": "accent2", "width": 2, "dash": "dash" }
},
{
"value": 0.15,
"label": "Minimum 15%",
"labelPosition": "start",
"stroke": { "color": "#666666", "width": 1, "dash": "dot" }
}
]
}
}
]
}Each entry is independent. OPF preserves authored order, repeated values and values equal to data. Omitting referenceLines, or writing [], draws none. The default data-line stroke stays solid; styling a reference does not change it.
Defaults, labels and bounds
- Only
valueis required. It must be finite.axisdefaults to"value";stroke.dashdefaults to"dash",stroke.widthto 4/3 reference pixels, and its color to the chart-text neutral. Width is between 0 and 64 and uses the same reference-pixel scale as other OPF strokes: a 720-pixel short edge. Use"solid","dash"or"dot"for the stroke style. - Every reference expands its associated automatic axis bounds when needed. OPF chooses readable ticks beyond the data/reference extrema; a target above the observations stays visible. A width of zero, or
"stroke": "none", hides only the stroke: its value still affects bounds, and its optional label remains. - An omitted
labeldraws no label. A supplied label must contain nonblank text and is shown verbatim; percentage formatting does not rewrite it.dataLabels: falsedoes not remove a reference's own label. labelPositiondefaults to"end"and requires a label. Start/end are logical horizontal endpoints and mirror in RTL. On a horizontal bar chart they mean top/bottom of the vertical reference. A label never sits on a data line, marker, bar or area while a free place exists: OPF tries the preferred side of the line, then the opposite side, and when its own end has no free place it moves the label to the other end of the line (importing the PowerPoint file still returns the authoredlabelPosition). Only when both ends are blocked doesopf validatereportopf/chart-label-collision; the label then keeps its preferred place, and if it sits on a bar or an area it stands on a plate of the chart's surface color (a filled data label in PowerPoint), so it stays readable. Labels never shrink, disappear or move their line. Use a shorter label or enlarge the chart.
Nonempty reference arrays are supported on column, bar, line, line-with-markers, area and combo. Every other chart type, including the stacked and 100% stacked types, scatter, pie, radar and the specialized statistical/hierarchy/map types, rejects them with the error opf/chart-reference-unsupported-type at referenceLines: a reference is never dropped silently. Choose a supported chart type or remove the references. A bar reference is vertical because the bar's numeric axis is horizontal.
A reference on a secondary axis
Use axis: "secondary" only on a combo that actually plots a line series on that axis. The primary and secondary axes keep their own units and bounds. Here revenue uses the primary axis; both conversion and its target use the percentage axis. The named line and secondary series are real data columns, not extra reference entries.
{
"language": "en-US",
"slides": [
{
"title": "Revenue and conversion",
"text": "Revenue grows while conversion approaches its target.",
"chart": {
"type": "combo",
"alt": "Revenue increases; conversion reaches 23% against a 25% target.",
"lineSeries": ["Conversion"],
"secondaryAxis": ["Conversion"],
"axisTitles": {
"category": "Quarter",
"value": "Revenue (thousands)",
"secondary": "Conversion rate"
},
"data": {
"columns": ["Quarter", "Revenue", { "name": "Conversion", "format": "0%" }],
"rows": [["Q1", 12, 0.18], ["Q2", 15, 0.21], ["Q3", 18, 0.23]]
},
"referenceLines": [
{
"value": 0.25,
"axis": "secondary",
"label": "Conversion target",
"stroke": { "color": "accent2", "width": 2, "dash": "dash" }
}
]
}
}
]
}Editing an exported reference in PowerPoint
For vertical charts with at least two categories, OPF exports references as native line-series helpers with independent paint and native endpoint labels. They span the first through last category centers in both preview and export. They move and resize with the chart and follow manual axis edits. Each helper series is named after its reference's label ("Reference" when it has none, with " 2", " 3" added to keep names unique), so Edit Data shows the label as the column heading. PowerPoint keeps the helpers out of the chart's legend. Keynote lists them in the legend under those names and does not draw reference labels.
The embedded worksheet contains one repeated reference value per category, not a single dynamic target cell. Keep all those values equal when editing the target; adding categories requires extending its cells and range. Exported axis bounds are computed by OPF, so changing data in PowerPoint alone does not promise automatic rescaling.
Horizontal bars and single-category charts use full-plot slide-shape overlays instead. Those lines and labels do not follow later chart movement, resizing or plot/data/axis edits. Change the OPF and export again to keep them aligned.
Import recognizes verified OPF-owned constant helpers as reference lines rather than unintended data series or duplicate shapes. A helper edited into a nonconstant series remains ordinary data with a diagnostic. An uncertain or edited overlay is retained visibly once with a diagnostic rather than restoring a stale duplicate reference. Keep the OPF as the editable source, and inspect the requested PowerPoint result.
Questions
How do I get a language model to add charts?
Ask for the deck as OPF JSON and describe the chart in the brief: the measure, the unit and the comparison. The model writes chart.data as columns and rows. Validate the result before you render it; the LLM authoring guide shows how to constrain the model's JSON.
How do I keep a chart and a table in sync?
Put the rows in datasets and point both at the same id, as in step 4. Edit a row once and both views change.
Do I need a charting library or an office app?
No. The chart is data in the deck. opf convert draws it for SVG, PNG and PDF and writes the PowerPoint chart itself. The commands on this page ran on a machine with no PowerPoint or LibreOffice installed.
Can I build the chart from a spreadsheet?
Yes. Export the sheet as CSV or TSV and run opf ingest, as above. JSON rows work too, with --data-format json.