Closed
Description
Thanks for the great package!
I'm trying to run chartjs-node-canvas
over express. The graph is rendered correctly on the first time I access the URL, but is blank on the second and subsequent calls. A minimal working example would be:
const express = require("express")
const { CanvasRenderService } = require('chartjs-node-canvas');
let app = express()
const configuration = {
type: 'bar',
data: {
labels: ['Red', 'Blue'],
datasets: [{
label: '# of Votes',
data: [12, 19],
backgroundColor: [
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
]
}]
}
};
const mkChart = async (params) => {
const canvasRenderService = new CanvasRenderService(800, 800)
return await canvasRenderService.renderToBuffer(configuration);
}
app.get('/chart', async function (req, res) {
var image = await mkChart(req.query)
res.type("image/png")
res.send(image)
})
app.listen(3061, () => {
})
Metadata
Metadata
Assignees
Labels
No labels