Chartjs-Jinja convert chat.js charts to images when rendering template

1👍

No, Jinja (or any similar template system) cannot convert JavaScript charts to images on the backend, because JavaScript runs in a browser, so you need a headless browser engine (or similar JS runtime) on the backend for the conversion. It’s doable, but it will make your environment more complicated since you’ll need to maintain a JS runtime as well along with the Python environment. If you want to go in this direction, have a look at chartjs-node-canvas that uses NodeJS to export a chart, or any headless browser.

However I highly recommend a different way: use a Python plotting library like Matplotlib. In an email you cannot even use any JS interactivity anyways, so a static plotting library is perfect for this task. Furthermore it’s Python, so no need to add a different runtime to your environment.

Leave a comment