I am sending a request to create pdf in node.js. The dataVal is dynamic.
app.get("/RequestForPDF", async function (req, res) {
res.render("pdftemp1", {
dataVal: mydataArray,
author: "John Doe",
});
});
"mydataArray" is a list of int dataset. I want to create a bar chart using that data by chart.js in the client side but I am unable to access the dataset. Can you suggest me a way to get through this? This is the script tag of my pdftemp1.hbs file.
<script>
var ctx = document.getElementById("myChart").getContext("2d");
var chart = new Chart(ctx, {
type: "bar",
// The data for our dataset
data: {
labels: [
"Jun 2016",
"Jul 2016",
"Aug 2016",
"Sep 2016",
"Oct 2016",
"Nov 2016",
"Dec 2016",
"Jan 2017",
"Feb 2017",
"Mar 2017",
"Apr 2017",
"May 2017",
],
// Information about the dataset
datasets: [
{
label: "Rainfall",
borderColor: "royalblue",
data: {{ dataVal }}, // Here I am using the array dataVal
backgroundColor: "green",
},
],
},
// Configuration options
options: {
layout: {
padding: 10,
},
legend: {
position: "bottom",
},
title: {
display: true,
text: "Precipitation in Toronto",
},
scales: {
yAxes: [
{
scaleLabel: {
display: true,
labelString: "Precipitation in mm",
},
},
],
xAxes: [
{
scaleLabel: {
display: true,
labelString: "Month of the Year",
},
},
],
},
},
});
</script>