Chartjs-Use dynamic data in Chart.js with Node.Js

1👍

you can stringify in nodejs code as below

router.get('/doughnut', function(req, res) {
  data = [65, 59, 20, 81, 56, 55, 40, 62, 85, 76, 65, 81];
  console.log('doughnut data',data);
  res.render('dashboard/doughnut', {
    title:'My First Doughnut Chart', 
    datai: JSON.stringify(data)
  });
});

and in .pug template you parse it like
var idata = JSON.parse('!{datai}'); 

https://github.com/hiralyshah/chartjs_mongoose_mongoDB

Leave a comment