Server-side chart rendering with static SVG
renderStaticSVG turns a chart spec into an SVG string in Node, with no browser. The output works with JavaScript off but has no tooltips or animation.
Made with OpenChart. How to build this bar chart
From late 2019 to mid-2026, house prices rose 85.9% in Maine and 14.6% in DC. A chart of that gap might need to reach an RSS reader, an email or a browser with JavaScript off, and none of those can run chart code, so the chart has to arrive as a finished image.
A static site build or a report generator can run the library, and drawing the chart there saves the reader’s browser the work. renderStaticSVG takes a chart spec and returns an SVG string on the server, with no browser or DOM. Every chart on this page is rendered that way at build time, and a reader without JavaScript sees only that.
Made with OpenChart. How to build this bar chart
Calling renderStaticSVG
Import it from the static entry of the vanilla package and give it a spec and a size:
import { writeFile } from "node:fs/promises";
import { renderStaticSVG } from "@opendata-ai/openchart-vanilla/static";
import { spec } from "./house-prices.js";
const svg = renderStaticSVG(spec, {
width: 720,
height: 420,
idPrefix: "house-prices-light",
darkMode: "off",
});
await writeFile("house-prices.svg", svg);It runs in plain Node, where window and document don’t exist, with no setup. The house price chart comes out at about 15 KB, 2 KB gzipped, and the same spec and options give the same bytes every time.
idPrefix namespaces the ids inside the SVG, so give each figure in a document its own.
Temporal axes can depend on the server’s timezone, so build with TZ=UTC if dates have to match between machines.
The server has no fonts to measure, so it estimates how wide each piece of text is, and a long title can break at a different word than it does in the live chart. Pass measureText, a function that returns the width of a string at a font size and weight, if line breaks must match.
Dark mode
The server has no color scheme to detect, and darkMode: "auto" gives the light version. Render the chart twice, once with "off" and once with "force", using different prefixes, and let your page’s CSS show the one that matches the reader. That is what this site does for every figure.
Limits of static output
A static SVG has no animation, no scripts, no tooltips, no keyboard navigation and no hidden data table. It does keep role="img" and a label built from the chart’s title, which for the chart above reads “Bar chart showing House prices rose 85.9% in Maine from 2019 to 2026 and 14.6% in DC (10 data points)”. Write the finding in a caption and put the values in an HTML table, as the accessibility post describes.
It also supports fewer specs than the live library. Charts, layered charts, bar lists, tile maps and geographic maps work. Tables, Sankey diagrams and network graphs do not.
Adding the live chart
A reader who needs to hover for exact values or step through points from the keyboard needs the live chart. Most pages want both. Ship the static SVG so the page has a chart immediately and without JavaScript, then mount the live chart over it from the same spec.
PNG output
The output is always SVG. Where a link preview or an email needs a raster image, convert it with a rasterizer such as sharp; the machine needs the chart’s font installed, because the SVG names its font without embedding it. To export from a live chart in the browser instead, see export.
The spec
The spec is plain JSON, so the same file can feed the server render and a live createChart call in the browser. The chart below maps net to the horizontal axis, state to the vertical axis, and a direction field to color.
Made with OpenChart. How to build this bar chart
The direction field is added when the rows are prepared, as “Net gain” or “Net loss”. The color scale’s domain fixes that order, and theme.colors.categorical gives each a light and a dark color, so losses stay orange on every render and their outside labels stay readable on both pages. Sorting net in ascending order puts the largest loss first, and labels prints each value on its bar. The anatomy of a spec explains the other blocks.
The static rendering docs give the default for every option, including precision, which sets how many decimals the SVG coordinates keep.