Skip to content
Advertisement

Is there a way to store a chart as an image directly to server using Chart.js? [closed]

Currently, I’m using html2canvas and able to first convert the chart produced using Chartjs to base64Image and then save it to a folder on the server. But, this requires me to first render the image in the browser. I want to be able to save the chart as an image without requiring it to first load on the client side. So, basically the script would run on server side and directly store the image on the server.

Advertisement

Answer

You can use https://www.image-charts.com/ with this you can send your config as as an api request and you get the image back so you will have to call this on your server to save it.

Example: https://image-charts.com/chart.js/2.8.0?bkg=white&c=%7B%22type%22:%22line%22,%22data%22:%7B%22datasets%22:%5B%7B%22type%22:%22line%22,%22fill%22:false,%22backgroundColor%22:%22rgba(255,%2024,%201,%201)%22,%22borderColor%22:%22rgba(255,%2024,%201,%201)%22,%22pointRadius%22:0,%22data%22:%5B67.0,65.0,70.0,81.0,83.0,81.0,79.0,74.0,78.0,77.0%5D,%22label%22:%22Output%22%7D%5D,%22labels%22:%5B%2200%22,%2205%22,%2210%22,%2215%22,%2220%22,%2225%22,%2230%22%5D%7D,%22options%22:%7B%22tooltips%22:%7B%22intersect%22:false%7D,%22scales%22:%7B%22xAxes%22:%5B%7B%22gridLines%22:%7B%22display%22:false%7D%7D%5D,%22yAxes%22:%5B%7B%22gridLines%22:%7B%22display%22:false%7D%7D%5D%7D%7D%7D

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement