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
| Way | What you install | What you give up |
|---|---|---|
| An HTTP API | Nothing. 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 Node | Chart.js and a canvas package with a native binary. | You own the fonts, the memory and the upgrades. |
| A headless browser | Puppeteer 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.

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.pngNode
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%7DWhat a JSON config cannot carry
- Functions. Tick callbacks, tooltip callbacks and scriptable options are code. ChartPNG never runs code from a config: a function written as text is removed. Format the labels and the numbers before you send them.
- Time axes. A scale of type
timeneeds a date adapter, and ChartPNG has none. Send the dates as labels on a category axis. - Your own plugins. Only what the service has registered is drawn.
- Other chart types. ChartPNG draws bar, line, pie, doughnut, radar, polarArea, scatter and bubble.
Limits
- The config can be up to 16 KB, in a GET and in a POST.
- Width and height go from 50 to 2000 pixels, and
dpris 1 or 2. A free image has up to 4 megapixels. - From one IP address, each minute: 600
GET /chartand 50POST /chart. - With a GET the chart is in the URL, so anyone who has the URL can read the numbers. The privacy page says what is stored.
- No uptime promise. The status page shows the success rate, measured every hour.
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.
- Animation and responsive. The script turns both off because there is nothing to animate and no window to resize to. In our run the PNG was the same with them on.
- The background is transparent. In our run the corner pixel had an alpha of 0. Fill the canvas with a color before Chart.js draws if the image goes on a dark page or in an email.
- The fonts are the machine's. Chart.js asks for Helvetica Neue, Helvetica or Arial. A container without them draws the text in another font. Not tested here on Linux.
- Functions and plugins work. The config is your code, so callbacks, your own plugins and a date adapter are available.
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
- An HTTP API when the chart is plain data: a report, an email, a Slack message, a README.
- A canvas library when you need callbacks, your own plugins or a time axis, or when the numbers must not leave your network.
- A headless browser when the image has to match a page of your app, with its HTML and CSS.
Related guides
- Charts in emails: PNG, retina sizing, dark mode and alt text.
- Charts in Slack from n8n and AI agents: A Block Kit image block with a chart URL, the 3000 and 2000 character limits, n8n templates and agents.
- Migrating from QuickChart: Move your QuickChart URLs to ChartPNG and fix the configs that need it.
Sources
Claims about other products, read at their source on 20 Nov 2026.
- Chart.js runs in Node.js with a canvas package:
You can use Chart.js in Node.js for server-side generation of plots
www.chartjs.org - In a browser, toBase64Image gives the image of a chart that is already drawn:
This returns a base 64 encoded string of the chart in its current state.
www.chartjs.org - chartjs-node-canvas 5.0.0 depends on node-canvas and asks for Chart.js 4.4.8 or later:
A node renderer for Chart.js using canvas.
registry.npmjs.org - @napi-rs/canvas needs no system packages:
0 System dependencies!
github.com - Installing Puppeteer downloads a browser:
(~170MB macOS, ~282MB Linux, ~280MB Windows)
pptr.dev - A Vercel function has a size limit, with larger functions in beta:
250 MB, or 500 MB for Python. Large functions support up to 5 GB
vercel.com - QuickChart can be self-hosted under the AGPL:
QuickChart is open source, licensed under version 3 of the GNU AGPL.
github.com