-
Is there any way to make a server side png? I see chartjs-node but requires some funky installs of Cairo. I need to create backedn reports to email |
Beta Was this translation helpful? Give feedback.
Answered by
kurkle
Dec 17, 2021
Replies: 2 comments 3 replies
-
You can use quickChart |
Beta Was this translation helpful? Give feedback.
3 replies
-
I've used node-canvas before for this (based on cairo though). npm install canvas chart.js simple_test.js const fs = require('fs');
const {createCanvas} = require('canvas');
const Chart = require('chart.js');
const canvas = createCanvas(512, 512);
const ctx = canvas.getContext('2d');
const chart = new Chart(ctx, {/* chart config*/});
function writePng(canvas, name) {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(path.join(__dirname, name));
const stream = canvas.createPNGStream();
stream.pipe(file);
file.on('finish', () => {
console.log(name + ' created.');
resolve();
});
});
}
writePng(canvas, 'test.png').then(() => chart.destroy()); Instead of writing to file, you can use https://www.chartjs.org/docs/latest/developers/api.html#tobase64image-type-quality |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kpetrow
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've used node-canvas before for this (based on cairo though).
simple_test.js