Guides

Chart.js to image on a server

Chart.js draws on a canvas, and a server has none. There are three ways to turn a Chart.js config into a PNG without a browser window: send the config to an HTTP API, draw it on a canvas library in Node, or drive a headless browser.

The three ways

WayWhat you installWhat you give up
An HTTP APINothing. One GET or POST returns the PNG.The config is JSON, so it cannot hold functions. The numbers go to the service.
A canvas library in NodeChart.js and a canvas package with a native binary.You own the fonts, the memory and the upgrades.
A headless browserPuppeteer and the Chrome it downloads.The largest of the three to deploy.

If the chart is already on a web page, chart.toBase64Image() returns it as a PNG data URL. That needs the browser the chart was drawn in, so it does not help a scheduled job, an email or a bot.

With an HTTP API

ChartPNG takes the config and answers with a PNG. No key is needed. Free images carry a small chartpng.dev watermark.

Line chart of orders from Monday to Friday
The image the three requests below return. Open the PNG. Open in the editor.

curl

curl -G https://chartpng.dev/chart \
  --data-urlencode 'c={"type":"line","data":{"labels":["Mon","Tue","Wed","Thu","Fri"],"datasets":[{"label":"Orders","data":[32,41,38,52,47]}]}}' \
  -d w=600 -d h=360 -d dpr=2 \
  -o chart.png

Node

import { writeFile } from 'node:fs/promises';

const config = {
  type: 'line',
  data: {
    labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
    datasets: [{ label: 'Orders', data: [32, 41, 38, 52, 47] }],
  },
};

const res = await fetch('https://chartpng.dev/chart', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ c: config, w: 600, h: 360, dpr: 2 }),
});
if (!res.ok) throw new Error((await res.json()).error);
await writeFile('chart.png', Buffer.from(await res.arrayBuffer()));

Python

import requests

config = {
    "type": "line",
    "data": {
        "labels": ["Mon", "Tue", "Wed", "Thu", "Fri"],
        "datasets": [{"label": "Orders", "data": [32, 41, 38, 52, 47]}],
    },
}

res = requests.post(
    "https://chartpng.dev/chart",
    json={"c": config, "w": 600, "h": 360, "dpr": 2},
    timeout=20,
)
if not res.ok:
    raise RuntimeError(res.json()["error"])
with open("chart.png", "wb") as f:
    f.write(res.content)

The same chart is also a URL you can put in an img tag with no code at all. The API reference has every parameter, and the Node client wraps the request above.

The GET URL

https://chartpng.dev/chart?w=600&h=360&dpr=2&c=%7B%22type%22%3A%22line%22%2C%22data%22%3A%7B%22labels%22%3A%5B%22Mon%22%2C%22Tue%22%2C%22Wed%22%2C%22Thu%22%2C%22Fri%22%5D%2C%22datasets%22%3A%5B%7B%22label%22%3A%22Orders%22%2C%22data%22%3A%5B32%2C41%2C38%2C52%2C47%5D%7D%5D%7D%7D

What a JSON config cannot carry

Limits

QuickChart is another API of this kind. It is open source under the AGPL, so you can also host it yourself. ChartPNG accepts its main URL parameter names: see Migrating from QuickChart.

With a canvas library in Node

The Chart.js documentation says it runs in Node.js with a canvas package, and names node-canvas and skia-canvas. This script uses @napi-rs/canvas, which installs with no system packages.

import { writeFile } from 'node:fs/promises';
import { createCanvas } from '@napi-rs/canvas';
import { Chart, registerables } from 'chart.js';

Chart.register(...registerables);

const canvas = createCanvas(600, 360);
const chart = new Chart(canvas, {
  type: 'line',
  data: {
    labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
    datasets: [{ label: 'Orders', data: [32, 41, 38, 52, 47] }],
  },
  // No browser: nothing to animate and no window to resize to.
  options: { animation: false, responsive: false },
});

await writeFile('chart.png', canvas.toBuffer('image/png'));
chart.destroy();

We ran this script on 20 Nov 2026 with chart.js 4.6.1 and @napi-rs/canvas 1.0.13 on Node 26, on macOS. It wrote a 600 by 360 PNG. Our tests run the same text.

chartjs-node-canvas wraps the same idea around node-canvas: version 5.0.0 on npm depends on canvas and asks for Chart.js 4.4.8 or later. Not tested here: we did not run chartjs-node-canvas, node-canvas or skia-canvas.

With a headless browser

Load a page that draws the chart with Chart.js, wait for it to finish, and take a screenshot with Puppeteer. The image is what a browser draws, with your CSS and web fonts around it.

The cost is the browser. Puppeteer downloads a Chrome of about 282 MB on Linux, which is more than the 250 MB a Vercel function may weigh unless you use the larger functions that are in beta. Not tested here: we did not run this way.

Which one to pick

Sources

Claims about other products, read at their source on 20 Nov 2026.