I am trying to render a chart (using ChartJS
) as express response. The data points for the chart are stored in node as array. I have to pass it on to the chartJS fu
You need to use unescaped string interpolation and a stringify to turn your pug variable into a client-side browser variable:
var arrayForChart = !{JSON.stringify(arrayInPug)};
If the variable in express/pug is ['a', 'b', 'c']
then this will output:
var arrayForChart = ['a', 'b', 'c'];
Without the stringify you'll get something like this which will just throw an error in the browser as it's not valid JavaScript:
var arrayForChart = [Object object];