Guide
Charts in PDF reports: one HTTPS GET per chart
Invoices, monthly statements and data exports are written by a report generator, not by a browser. A UrlChart URL turns the chart into a single PNG fetched over HTTPS, which the generator embeds at a physical size it controls. No browser, no canvas and no font set in the report build.
Why a chart library is awkward here
A JavaScript chart library needs a document to draw into. At PDF generation time there is no DOM and no canvas, so a pipeline that insists on a library-rendered chart has two options and pays for both in the build image.
- Run a headless browser per document. Every render starts a browser process: startup time per document, a memory footprint that stays resident, fonts that have to be installed in the container, and a whole browser in the deployment image that needs patching like the rest of the stack.
- Re-draw the chart on the PDF primitives. Axes, tick positions, label collisions, the legend, series colours, number formatting and the print box all have to be written by hand — the same work the library was going to do, in a place where nothing is visible until the PDF is opened.
Neither route makes export fidelity easy. Text drawn through the PDF layer is subject to font substitution: a face that exists on the build machine and not in the reader is re-mapped and the metrics shift. Layout reflow moves a figure when the page breaks inside it, and a wide chart either shrinks below legibility or overflows the page. A vector chart survives zooming but not substitution; a raster chart survives substitution but not zooming. Deciding which failure is acceptable per document is work that has nothing to do with the numbers in the report.
What the image URL removes from the pipeline
- One request. The builder does a GET on an https URL and holds PNG bytes. Any language with an HTTP client can do it: Node, Python, Java, Go, PHP, a shell script.
- Language-agnostic. No SDK, no charting package, no native dependency such as node-canvas or Cairo compiled into the report image.
- Deterministic. The URL holds the whole chart: type, canvas, data, labels, colours. The same URL returns the same bytes, so a report regenerated next month from the same stored URL reproduces the same figure — and a diff between two PDFs is a diff in the data, not in the renderer version.
- Immutable. Successful renders are cached and served as immutable, so the fetch is cheap on every repeat run.
- No fonts in the image path. The text inside the chart is rasterised by the render service with its own installed faces. The report build stores pixels and needs nothing installed.
A real render
The URL is the entire chart. Keep it as a constant in the report code, or build it from the period being reported:
https://urlchart.com/chart?cht=bvs&chs=720x360&chd=t:42,55,48,71,63,80,58,66,74,69,85,92&chxl=0:|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec&chxt=x,y&chco=2f5fe0&chtt=Monthly+revenue+2026
Size the chart in pixels, not in percent
chs is the render size in pixels, fixed at render time: a PNG has no notion of a page. Do the arithmetic once, in the report code, and keep the number beside it.
- A4 is 210 mm wide. With roughly 20 mm margins the content column is about 170 mm; with 10 mm margins, 190 mm.
- At 96 dpi a millimetre is 3.78 px, so 170–190 mm of content width is roughly 640–720 px.
- A 720 px render therefore fills a 190 mm column almost one-to-one, and lands at about 108 dpi in a 170 mm column. No scaling by the PDF engine is the case where the chart looks exactly as designed.
- Set
widthandheighton the placement to the same numbers, so the layout reserves the box before the image arrives — an HTML-to-PDF engine lays the page out before it fetches.
Resolution is baked into the PNG
The render is the resolution. To print crisply, ask for a larger canvas and let the engine scale it down to the physical width: for that 190 mm column, a 1440 px render is about 192 dpi where a 720 px render is about 96 dpi.
Know what the free tier actually serves. Anonymous requests are capped at 1000 px per side and 1,000,000 total pixels, so a chs=1440x720 request is served as 1000x500 and the reduction is reported in the X-UrlChart-Meta response header instead of silently pretending the canvas matched. A paid key raises the cap to 3000 px per side and 9 MP, which covers a 2x column. There is no separate DPI parameter: resolution is the pixel count divided by the physical width you choose.
Never stretch a small render up. A 400 px chart placed across 170 mm is about 60 dpi of ink: the viewer and the printer scale pixels, so the labels blur rather than gain detail.
Legibility at print size
Font size and tick density are part of the render, not of the PDF, so they are decided when you pick chs:
- Pick the canvas for the physical box first, then check that the tick labels still fit at that width.
- When they do not, drop text before you shrink type: shorten long axis labels (
chxl), label every second tick, or move the long names into the report table beside the figure. - A chart laid out for a 400 px box and then placed across 170 mm carries its labels as stretched pixels — soft at any zoom, and small once the figure is scaled to the column. Re-render at the target width instead of scaling a small render.
Caching, and how to change a chart
- Successful renders are cached and served with
Cache-Control: public, max-age=31536000, immutable. - A repeat render of the same URL is a cache hit and is not a metered unique render, so regenerating a report from stored URLs costs requests, not credits.
_,cb,cachebustandtare stripped before rendering, so they cannot bust the cache and never create a second render.- To change a chart, change a rendered parameter — the data, the title, a colour. That produces new bytes at a new URL.
Embedding it in the flows you already have
- An HTML-to-PDF engine fetches the
<img src>while it converts the template. You place the tag; the engine makes the request. - A report library that takes bytes fetches the URL itself and places the image at the physical size you pass in — which is where the pixel arithmetic above pays off.
- When the data is not public, do not leave a long-lived
?key=in a document that gets forwarded. Use a signed URL with an expiry: after it lapses the request fails closed to the free tier, and rotating or revoking the key invalidates every signature minted with it. The parameters are in the docs.
Next: Getting started · chart examples · Pricing · Drop-in Tester