OPF
← All lessons

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.

Rendered result of step 1: Start with the actual values

Prepared render of this step. View full-size SVG.

1 / 4

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.33.0 · renderer 0.33.0 · Gallery 0.33.0

Prepared with the recorded installed packages; this identity does not certify registry provenance or native fidelity. Documentation source OpenPresentation/opf@9545016583cc. 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:

json
{
  "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:

text
Step,Before (min),After (min)
Sign-up,6.7,5.8
First deck,12.4,9.1
Export,3.2,2.5
sh
opf 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.pdf

With --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.alt or 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.

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.