Excel Data
Date Percentage
04-03-22 (H) 80
05-03-22 (H) 55
06-03-22 (H) 20
07-03-22 (H) 49
08-03-22 (H) 61
09-03-22 (H) 73
TODAY (P) 23
11-03-22 (P) 64
Controller code
datavCenterSpacePredictionModelData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[3]]);
Passing this object to view
await res.render('dashboard', { vCenterSpace:datavCenterSpacePredictionModelData})
In my view I am not able to parse/loop through this data so that it can be passed on to chartjs object.
Chart object need labels and data
const zschart = new Chart(document.getElementById("chartjs-0"), {
"type": "line",
"data": {
"labels": ["04-03-22 (H)","05-03-22 (H)","06-03-22 (H)","07-03-22 (H)","08-03-22 (H)","09-03-22 (H)","TODAY (P)","11-03-22 (P)","12-03-22 (P)","13-03-22 (P)","14-03-22 (P)","15-03-22 (P)"],
"datasets": [{
"label": "Usage in %",
"data": [80,55,20,49,61,73,23,64,60,91,70,95],
"fill": false,
"borderColor": "rgb(75, 192, 192)",
"lineTension": 0.1
}]
},
"options": {}
});
when I am trying to get this value, is returning me object. I am checking type of object it is returning me string
var vCenterSpace = ('<%=vCenterSpace%>') //value of node js object into JS
alert(typeof(vCenterSpace ))
I want to dynamically pass these value as below.
These are hardcoded values
"labels": ["04-03-22 (H)","05-03-22 (H)","06-03-22 (H)","07-03-22 (H)",
"data": [80,55,20,49,61,73,23,64,60,91,70,95],
Its all getting messed up, not able to understand how this resolve this.