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
Because it outsources rendering to QuickChart, an open-source web service, it requires almost no other dependencies and uses much less CPU. ... const ChartJsImage = require('chartjs-to-image'); // Generate the chart const chart = new ChartJsImage(); chart.setConfig({ type: 'bar', data: { labels: ['Hello world', 'Foo bar'], datasets: [{ label: 'Foo', data: [1, 2] }] }, }); // Save it chart.toFile('/tmp/mychart.png');
🌐
npm
npmjs.com › package › chartjs-to-image
chartjs-to-image - npm
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 ...
    » npm install chartjs-to-image
  
Published: Nov 11, 2023
Version: 1.2.2
Author: Ian Webster
🌐
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 ...
Starred by 13 users
Forked by 2 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
🌐
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
🌐
YouTube
youtube.com › chart js
3. How to Render Images in the chartjs-plugin-labels in Chart js - YouTube
04:40
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
🌐
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; });
🌐
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.
🌐
YouTube
youtube.com › chart js
How to Download Canvas as Image on Button Click in Chart JS - YouTube
11:50
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
Find elsewhere
🌐
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.
🌐
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.
🌐
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
🌐
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
🌐
CodeProject
codeproject.com › Tips › 1120045 › Export-Chart-js-Charts-as-Image
Export Chart.js Charts as Image - CodeProject
// // var url_base64jp = document.getElementById("myChart").toDataURL("image/jpg"); // Add one anchor tag in your HTML. // // <a id="link2" download="ChartJpg.jpg">Save as jpg</a> // Set that converted base64 string as a href for a anchor tag.
🌐
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.
🌐
CanvasJS
canvasjs.com › home › docs › charts › methods & properties › chart › exportchart()
exportChart - export the chart as image | CanvasJS JavaScript Charts
September 17, 2024 - Export the chart as image (jpg / png). Parameters: options: { format: String (“jpg” | “png”), toDataURL: Boolean (default false), fileName: String } Example: chart.exportChart({format: “jpg”}); Note: Chart should be rendered before you can use this method.
🌐
Stack Overflow
stackoverflow.com › questions › 77307050 › export-chart-js-as-image
Export chart.js as image
var 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);
🌐
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
🌐
CanvasJS
canvasjs.com › home › docs › charts › how to samples › position image over chart
Position Image Over Chart | CanvasJS Charts
September 17, 2024 - imageBottom = chart.axisX[0].bounds.y1; ... }); To summarize, you should first render the chart and then calculate pixel co-ordinates where images have to be placed (using convertValuetoPixel method) and then set top & left css properties of images....