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
🌐
QuickChart
quickchart.io › documentation › chart-js › image-export
How to download and export Chart.js images | QuickChart
chartjs-to-image is a node library that can export your chart to file or data URL. It's a little simpler to use than the above renderers.
🌐
npm
npmjs.com › package › chartjs-to-image
chartjs-to-image - npm
Convert Chart.js to image. Latest version: 1.2.2, last published: 2 years ago. Start using chartjs-to-image in your project by running `npm i chartjs-to-image`. There are 7 other projects in the npm registry using chartjs-to-image.
    » npm install chartjs-to-image
  
Published: Nov 11, 2023
Version: 1.2.2
Author: Ian Webster
Videos
March 26, 2016
🌐
GitHub
github.com › image-charts › chartjs-image-javascript
GitHub - image-charts/chartjs-image-javascript: Render Chart.JS chart as image
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 fs.write() directly (which is recommended).
Starred by 13 users
Forked by 2 users
Languages: JavaScript
🌐
GitHub
github.com › typpo › chartjs-to-image
GitHub - typpo/chartjs-to-image: Simple library for converting Chart.js to image on backend and frontend
This is a wrapper for exporting Chart.js as an image. It works on the server side as well as client side (although on the client you may prefer to use toBase64Image). The renderer is based on QuickChart, a free and open-source web service for generating static charts. View the main QuickChart repository here. ... This library provides a ChartJsImage ...
Starred by 50 users
Forked by 8 users
Languages: JavaScript
🌐
Stack Overflow
stackoverflow.com › questions › 20206038 › converting-chart-js-canvas-chart-to-image-using-todataurl-results-in-blank-im
Converting Chart.js canvas chart to image using .toDataUrl() results in blank image

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 stackoverflow.com
🌐
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 converting the chart to an image, you use ‘renderToDataURL’. This converts the chart into a base64 image URL. By default, it converts the image to png format. In the configuration, you pass the…
🌐
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 - A space to discuss and keep up software development and manage your software career · News and discussion of science and technology such as AI, VR, cryptocurrency, quantum computing, and more
🌐
Stack Overflow
stackoverflow.com › questions › 72173967 › render-chartjs-and-export-image-to-data-not-in-the-dom
Render chartjs and export image to data not in the DOM

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();

Answer from bogdanoff on stackoverflow.com
Find elsewhere
🌐
Chart.js
chartjs.org › docs › latest › developers › api.html
API | Chart.js
Use this to stop any current animation. This will pause the chart during any current animation frame. Call .render() to re-animate.
🌐
Chart.js
chartjs.org › docs
Chart.js | Documentation
Simple yet flexible JavaScript charting library for the modern web
🌐
Image-charts
documentation.image-charts.com › chart.js
Chart.js - Image-Charts documentation
How to use Chart.js server-side and generate images of chart.js charts.
🌐
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 - There is a very simple way to use chart.js on an HTML page, one just has to include the CDN URL in...
🌐
QuickChart
quickchart.io › documentation › use-chart-js-in-email
Using Chart.js in emails | QuickChart
You may also be interested in other ways to render Chart.js images. You too can render Chart.js in emails. Libraries like chartjs-to-image can be used to export Chart.js as an image on the server side.
🌐
QuickChart
quickchart.io
Open Source Chart Image API | QuickChart
Create a chart image with one API call and embed it anywhere. Send charts in email and other platforms. Open source, no watermarks, used by thousands of developers.
🌐
Chart.js
chartjs.org › docs › latest › configuration › canvas-background.html
Canvas background | Chart.js
In the two example plugins underneath here you can see how you can draw a color or image to the canvas as background. This way of giving the chart a background is only necessary if you want to export the chart with that specific background.
🌐
npm
npmjs.com › package › chart.js-image
chart.js-image - npm
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 fs.write() directly (which is recommended). //import ChartJSImage ...
    » npm install chart.js-image
  
Published: Jul 29, 2022
Version: 6.1.3
Author: Francois-Guillaume Ribreau
🌐
CodeSandbox
codesandbox.io › examples › package › chartjs-to-image
chartjs-to-image examples - CodeSandbox
Use this online chartjs-to-image playground to view and fork chartjs-to-image example apps and templates on CodeSandbox.
🌐
GitHub
github.com › chartjs › Chart.js › discussions › 10210
Save chart as image without filling the canvas · chartjs/Chart.js · Discussion #10210
Hi, I have a question: Is it possibile to generate a chart without filling the canvas. I would like to generate a chart and save it directly to an image and after fill an img element with the gener...
Author: chartjs