Chartjs-Node Module

Header Image

My last post talked about the details of how you can render Chart.js charts on the server, making it useful for emails, slack notifications and more.

Now it gets even easier. I just published a simple node module, chartjs-node which takes out all the guess work and lets you draw Chartjs charts with just a couple lines of code.

First you’ll need to npm install chart.js since it’s a peer dependency:

npm install chart.js --save

Install Cairo for your system then just require up the module and create a new ChartjsNode object by defining the chart dimensions:

Now just use the drawChart function to draw the chart by passing a Chart.js configuration object. Every API returns a Promise object:

And that’s pretty much it. Easy charting in Node.js.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>