Skip to content

Blank charts on the second call #9

Closed
@chalomsuperlogica

Description

@chalomsuperlogica

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions