2

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. enter image description here

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

David
  • 472
  • 10
  • 22
  • Could you prepare a working example of your chart? Unfortunately, the posted one is not working. – Wojciech Chmiel Mar 11 '19 at 11:29
  • @WojciechChmiel yes, it fixed. – David Mar 11 '19 at 11:31
  • 1
    You are looping from 0 to `totalDays` (which is 20) and pushing those values to idealBurn array. Then building a chart based on this array with 20 values from 1 to 20. The chart is perfectly fine, your calculations not. – Wojciech Chmiel Mar 11 '19 at 13:31

0 Answers0