score:0

you are looking for a library like chartjs-node-canvas or chartjs-node. these solutions render charts to png or other image formats.

here's what a chart render looks like in chartjs-node-canvas:

const { canvasrenderservice } = require('chartjs-node-canvas');

const width = 400; //px
const height = 400; //px
const canvasrenderservice = new canvasrenderservice(width, height, (chartjs) => { });

(async () => {
    const configuration = {
        // add your chart.js config here
    };
    const image = await canvasrenderservice.rendertobuffer(configuration);
    const dataurl = await canvasrenderservice.rendertodataurl(configuration);
    const stream = canvasrenderservice.rendertostream(configuration);
})();

you would still need to build your own web server. if you prefer a chart api that includes the rendering web server, you can use something like quickchart, which is an open-source project of mine that wraps chartjs-node-canvas and renders your chart.js charts.

in that case your code might look like this:

const quickchart = require('quickchart-js');

const mychart = new quickchart();
mychart
  .setconfig({
    type: 'bar',
    data: { labels: ['hello world', 'foo bar'], datasets: [{ label: 'foo', data: [1, 2] }] },
  })
  .setwidth(800)
  .setheight(400);

const chartimageurl = mychart.geturl();
// download the url...

Related Query

More Query from same tag