← All updates

Bar, line and pie charts in templates

New chart() builder draws bar, line and pie charts from your render data as native PDF vector graphics, with alt text generated from the values.

dslbuildercharts

Templates can now draw charts. The new chart() DSL builder takes rows from your data and renders a bar, line or pie chart as native PDF vector graphics. It stays sharp at any zoom and needs no image hosting. Until now, charts needed Markdown with a Mermaid block or hand-drawn vector() shapes.

chart({
  type: "bar", // "bar" | "line" | "pie"
  data: "{{monthly}}",
  x: "month",
  y: [
    { key: "revenue", label: "Revenue" },
    { key: "cost", label: "Cost" },
  ],
  width: 480,
  height: 220,
  title: "Revenue vs cost",
});

data is a {{template}} reference, so the chart is drawn from each render's data: the same template produces this month's chart on every call to /render. Several y fields give grouped bars or several lines, with a legend. Values can be numbers or formatted strings such as "$1,200", and a missing value leaves a gap instead of failing the render.

Every chart is tagged as a figure for PDF/UA. If you don't pass alt, the alt text is generated from the data: chart type, title, series and every plotted value. A screen reader then reads out the numbers the chart shows.

If the data path doesn't resolve, the chart shows "No data" and /preview returns a template warning that names the chart. Full option list: pdf-template-author.md §Charts.