How to add new dataset in line chart of chart.js by iterating over dictionary in JavaScript?

I am trying to display linechart from charts.js where it shows the pass,fail and skipped test case reults in graph. Here i have hardcoded the number of data in a dataset. I want to add the datapoints by iterating through the object. Object looks like this

var temp = {"2020":[1,2,3],             "2021":[4,5,6]} 

And my javascript function for line chart below.

    function GetHealthReport(health,id) {     console.log(health);     var Date = Object.keys(health);      var ctxL = document.getElementById(id).getContext('2d');     var myLineChart = new Chart(ctxL, {         type: 'line',         data: {             labels: Date,             datasets: [                 {                     label:"Pass",                 data: [health[Date[0]][0],health[Date[1]][0],health[Date[2]][0],health[Date[3]][0],health[Date[4]][0]],                     backgroundColor: [                         'rgba(71,193,28,0.71)'                     ]                 },                 {                     label:"Failed",                     data: [health[Date[0]][1],health[Date[1]][1],health[Date[2]][1],health[Date[3]][1],health[Date[4]][1]],                     backgroundColor: [                         'rgba(212,0,13,0.71)'                     ]                 },                 {                     label:"Skipped",                     data: [health[Date[0]][2],health[Date[1]][2],health[Date[2]][2],health[Date[3]][2],health[Date[4]][2]],                     backgroundColor: [                         'rgba(228,78,231,0.56)'                     ]                 }             ]         },         options: {             responsive: true         }     });   } 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.