The chart seem to be async so you will probably need to provide a callback when the animation has finished or else the canvas will be empty.

var options = {
    bezierCurve : false,
    onAnimationComplete: done  /// calls function done() {} at end
};
Answer from user1693593 on Stack Overflow
🌐
npm
npmjs.com › package › chartjs-to-image
chartjs-to-image - npm
November 11, 2023 - Uses the quickchart.io web service to create a fixed-length chart URL that displays the chart image. The Promise resolves with a URL such as https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401.
      » npm install chartjs-to-image
    
Published: Nov 11, 2023
Version: 1.2.2
🌐
GitHub
github.com › image-charts › chartjs-image-javascript
GitHub - image-charts/chartjs-image-javascript: Render Chart.JS chart as image · GitHub
Creates a file containing generated chart image and yield a promise. When file is a filename, asynchronously writes data to the file, replacing the file if it already exists. When file is a file descriptor, the behavior is similar to calling ...
Discussions

Converting Chart.js canvas chart to image using .toDataUrl() results in blank image
The tutorial (http://www.chartjs.org/docs/) devotes an entire 1 line on the topic: The canvas element also allows for saving the contents as a base 64 string, allowing saving the chart as an image. A canvas element has the method of toDataURL, which returns a base64 string of the image. However, when I do that, the image it renders ... More on stackoverflow.com
🌐 stackoverflow.com
Render chartjs and export image to data not in the DOM
I am using chart.js from a frontend react application. I need to create a plot with chart.js so that I can attach it to a powerpoint slide with pptxgen. This image does not have to be rendered visu... More on stackoverflow.com
🌐 stackoverflow.com
Export chart.js as image - javascript
I know that is complicated to generate a chart with different colors for different contexts. My approach when I have such cases is to render again the chart under a hidden div and to use this one when I have to generate the image. More on stackoverflow.com
🌐 stackoverflow.com
how to re render vuechartjs in composition API
Just add an incremental key to the component? Click the button, increment the counter will automatically re-render the component. https://michaelnthiessen.com/force-re-render/ More on reddit.com
🌐 r/vuejs
2
10
May 3, 2023
🌐
QuickChart
quickchart.io › documentation › chart-js › image-export
How to download and export Chart.js images | QuickChart
Although Chart.js was built for the frontend, it can be used in Node to generate Chart.js images thanks to several open-source projects. The most popular projects used for this purpose are ChartJsNodeCanvas and chartjs-node. These solutions are able to render charts to PNG and other formats.
🌐
GitHub
github.com › typpo › chartjs-to-image
GitHub - typpo/chartjs-to-image: Simple library for converting Chart.js to image on backend and frontend · GitHub
Uses the quickchart.io web service to create a fixed-length chart URL that displays the chart image. The Promise resolves with a URL such as https://quickchart.io/chart/render/f-a1d3e804-dfea-442c-88b0-9801b9808401.
Author: typpo
🌐
CodeSandbox
codesandbox.io › examples › package › chartjs-to-image
chartjs-to-image examples - CodeSandbox
chartjs-to-image custom scale support demo · keremilhan · inspiring-cookies-397zdo · LewisAlderman · graph export in pdf (forked) panku799 · graph export in pdf (forked) panku799 · chart.js image (forked) coderg01 · chart.js image (forked) krishna_kumar ·
🌐
Chart.js
chartjs.org › docs › latest › developers › api.html
API | Chart.js
myLineChart.toBase64Image(); // => returns png data url of the image on the canvas myLineChart.toBase64Image('image/jpeg', 1) // => returns a jpeg data url in the highest quality of the canvas
🌐
YouTube
youtube.com › chart js
3. How to Render Images in the chartjs-plugin-labels in Chart js - YouTube
3. How to Render Images in the chartjs-plugin-labels in Chart jsIn this video we will explore how to render images in the plugin chartjs-plugin-labels in Cha...
Published: October 23, 2021
Views: 4K
Find elsewhere
🌐
DEV Community
dev.to › noemelo › how-to-save-chart-as-image-chart-js-2l0i
How to save chart as image Chart.js - DEV Community
February 4, 2020 - //Download Chart Image document.getElementById("download").addEventListener('click', function(){ /*Get image of canvas element*/ var url_base64jp = document.getElementById("lineChart").toDataURL("image/jpg"); /*get download button (tag: <a></a>) */ var a = document.getElementById("download"); /*insert chart image url to download button (tag: <a></a>) */ a.href = url_base64jp; });
Top answer
1 of 2
3

its not possible to render without attaching canvas to dom, but you can hide it and it will work as expected.


const chartEl = document.createElement("canvas");
chartEl.setAttribute("width", "400");
chartEl.setAttribute("height", "400");
chartEl.style.display = "none";

document.body.append(chartEl);
let chart = new Chart(chartEl, {
  type: "bar",
  data: {
    datasets: [
      {
        barPercentage: 0.5,
        barThickness: 6,
        maxBarThickness: 8,
        minBarLength: 2,
        data: [10, 20, 30, 40, 50, 60, 70]
      }
    ]
  },
  options: {
    scales: {},
    animation: false
  }
});

chart.render();
console.log(chart.toBase64Image());
chartEl.remove();

2 of 2
2

The only way to render a chart without you specifically adding it to the dom is by making use of the offscreen-canvas as explained here in the documentation of chart.js: https://www.chartjs.org/docs/3.7.1/general/performance.html#parallel-rendering-with-web-workers-chromium-only

Downside is that the offscreen canvas API is only available in chromium based browsers.

Other approach you can take is by adding the canvas to the dom, let chart.js render to it, get the base64 representation and then remove the canvas directly after that like so:

let ctx = document.createElement("canvas")
document.documentElement.appendChild(ctx)
ctx.setAttribute("width", "400")
ctx.setAttribute("height", "400")
let chart = new Chart(ctx, {
  type: "bar",
  data: {
    labels: ['a', 'b', 'c', 'd', 'e', 'f', ' g'],
    datasets: [{
      barPercentage: 0.5,
      barThickness: 6,
      maxBarThickness: 8,
      minBarLength: 2,
      data: [10, 20, 30, 40, 50, 60, 70]
    }]
  },
  options: {
    scales: {}
  }
})

const base64 = chart.toBase64Image();

ctx.remove();

console.log(base64)
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.1/chart.js"></script>
</body>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
DEV Community
dev.to › ektaprasad › how-to-use-chartjs-with-nodejs-export-the-chart-as-an-image-f50
How to use Chart.js with Node.js and save it as an image - DEV Community
December 5, 2021 - For using the chartjs service, you will have to write: const canvasRenderService = new CanvasRenderService(width, height, chartCallback); Here you will be providing width, height, and the callback function.
🌐
DEV Community
dev.to › danelliot › render-a-chart-to-an-image-on-the-server-node-python-2026-19mf
Render a Chart to an Image on the Server (Node + Python, 2026) - DEV Community
June 6, 2026 - You gain: no node-gyp, no libcairo/libpango in your image, no Chromium-in-CI, no font-package debugging, no kaleido-version breakage. The canonical Node route renders Chart.js onto a node-canvas surface — no browser, but you inherit node-canvas's native Cairo/Pango dependency. // npm i chartjs-node-canvas chart.js // + system libs: apt-get install libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev import { ChartJSNodeCanvas } from "chartjs-node-canvas"; import { writeFileSync } from "fs"; const canvas = new ChartJSNodeCanvas({ width: 800, height: 400 }); const png = await canvas.renderToBuffer({ type: "bar", data: { labels: ["Q1","Q2","Q3","Q4"], datasets: [{ label: "Revenue", data: [482,591,623,705] }] }, }); writeFileSync("chart.png", png);
🌐
Medium
prasadekta.medium.com › using-chart-js-in-nodejs-and-exporting-it-as-image-81fb8a492058
Using Chart.js in Nodejs server and exporting it as an image. | by Ekta Prasad | Medium
May 20, 2023 - For using the chartjs service, you will have to write: const canvasRenderService = new CanvasRenderService(width, height, chartCallback); Here you will be providing width, height, and the callback function.
🌐
Stack Overflow
stackoverflow.com › questions › 77307050 › export-chart-js-as-image
Export chart.js as image - javascript
Copyvar options = { type: 'line', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 3], borderColor: 'pink' }, { label: '# of Points', data: [7, 11, 5, 8, 3, 7], borderColor: 'orange' } ] }, options: { plugins: { customCanvasBackgroundColor: { color: 'pink' } } }, plugins: [{ id: 'customCanvasBackgroundColor', beforeDraw: (chart, args, options) => { const { ctx } = chart; ctx.save(); ctx.globalCompositeOperation = 'destination-over'; ctx.fillStyle = options.color || '#99ffff'; ctx.fillRect(0, 0, chart.width, chart.height); ctx.restore(); } }] } var ctx = document.getElementById('chartJSContainer').getContext('2d'); new Chart(ctx, options);
🌐
YouTube
youtube.com › chart js
How to Download Canvas as Image on Button Click in Chart JS - YouTube
How to Download Canvas as Image on Button Click in Chart JSIn this video we will explore how to download canvas as image on button click in chart js. Chart j...
Published: January 19, 2022
Views: 8K
🌐
GitHub
github.com › chartjs › Chart.js › discussions › 10210
Save chart as image without filling the canvas · chartjs/Chart.js · Discussion #10210
Please reload this page. ... No you can not do that, you will always need to have a canvas on which it gets drawn. ... (Chromium browsers only) You can use the ofscreen canvas API to render the chart and then download it
Author: chartjs
🌐
HTML to Image
html2img.com › home › articles › chart.js server-side rendering as images (python guide)
Chart.js Server-Side Rendering as Images (Python Guide) | HTML to Image
April 12, 2026 - Render Chart.js charts on the server and get back a PNG. A cleaner alternative to chartjs-node-canvas or wrestling with matplotlib in Python.
🌐
Accreditly
accreditly.io › articles › how-to-render-charts-as-images-on-the-server
How to render charts as images on the server - Accreditly
September 5, 2026 - Three ways to render Chart.js and other charts as PNG images on the server: chartjs-node-canvas, Puppeteer, or an HTML to image API. Working code and honest trade-offs for emails, Slack and reports.