I'm trying to calculate data for burndown chart for a course. The course has a start and end dates, exercises count and actual students start and finish dates. I have data JSON from the server with a course data. I process it. First of all, I'm calculating totalExcercisesCount
then counting the number of days student havs to finish the course. After all I get the next data object:
const chartDataObj = {
idealBurn: [],
actualBurn: [],
idealIncrement: 0,
totalExcercisesCount: 12,
totalExercisesDoneCount: 4,
timeLine: {
courseFrom: "2018-09-10",
courseTo: "2019-06-21",
start: "2018-09-11",
finish: "2018-10-01",
totalDays: 20,
}
}
After I'm building an ideal line and here comes the first problem. I'm trying to do next,
chartDataObj.idealIncrement = Math.floor(
chartDataObj.timeLine.totalDays / chartDataObj.totalExcercisesCount
);
for (i = 0; i <= chartDataObj.timeLine.totalDays - 1; i++) {
chartDataObj.idealBurn.push(chartDataObj.idealIncrement * (i + 1));
}
chartDataObj.idealBurn.reverse();
The problem is if the count of days much more then exercises I have a wrong ideal burn.
I have 12 exercises to complete but on the second day, it shows like 19. What am I doing wrong here?
And then I need to fill actual burn data. But the problem is, how to fill it according to dates exercises was complete and show it on the graph? I mean in my final dataObject I have just totalExercisesDoneCount
but in initial JSON I have info about dates when exercises was finished. Should I group them by dates or not?
I also have a codepen prepared with chart and all the code. Any help will be appreciated. Thanx