0

I'm building a scatterplot in d3 v5 and, when I read my file, the dates are shifted back one day. They start in March 1st, but when I read the file it marks them as February 29. I'm thinking this has to do with the fact that 2020 is a leap year but I'm not entirely sure how to fix this since I started to program not that long ago. Here's an example of my csv file (date is stored as a date object), and the output when I read the csv using d3.

date,place,m50_index,percent_change
2020-03-01,Florida,71,-29
2020-03-02,Florida,99,-1
2020-03-03,Florida,100,0
2020-03-04,Florida,99,-1
2020-03-05,Florida,104,4
2020-03-06,Florida,111,11
2020-03-07,Florida,92,-8
2020-03-08,Florida,68,-32
2020-03-09,Florida,96,-4
2020-03-10,Florida,99,-1
2020-03-11,Florida,101,1
2020-03-12,Florida,102,2
2020-03-13,Florida,102,2
2020-03-14,Florida,75,-25
2020-03-15,Florida,52,-48
2020-03-16,Florida,76,-24
2020-03-17,Florida,66,-34
2020-03-18,Florida,55,-45
2020-03-19,Florida,56,-44
2020-03-20,Florida,61,-39
2020-03-21,Florida,26,-74
2020-03-22,Florida,10,-90
2020-03-23,Florida,33,-67
2020-03-24,Florida,29,-71
2020-03-25,Florida,31,-69
2020-03-26,Florida,28,-72
2020-03-27,Florida,27,-73
2020-03-28,Florida,8,-92
2020-03-29,Florida,1,-99
2020-03-30,Florida,15,-85
2020-03-31,Florida,17,-83
2020-04-01,Florida,20,-80
2020-04-02,Florida,23,-77
2020-04-03,Florida,17,-83
2020-04-04,Florida,4,-96
2020-04-05,Florida,0,-100
2020-04-06,Florida,9,-91
2020-04-07,Florida,12,-88

Javascript code and console output

    function scatterPlot(data) {

      const floridaData = d3
    .nest()
    .key(function(d) {
      return d.date;
    })
    .map(data);
  console.log(floridaData);
    }

    $Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time): Array(67)
0: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Florida", m50_index: 71, percent_change: -29}
1: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Alachua County", m50_index: 77, percent_change: -23}
2: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Baker County", m50_index: 72, percent_change: -28}
3: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Bay County", m50_index: 85, percent_change: -15}
4: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Bradford County", m50_index: 75, percent_change: -25}
5: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Brevard County", m50_index: 62, percent_change: -38}
6: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Broward County", m50_index: 66, percent_change: -34}
7: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Calhoun County", m50_index: 29, percent_change: -71}
8: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Charlotte County", m50_index: 64, percent_change: -36}
9: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Citrus County", m50_index: 64, percent_change: -36}
10: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Clay County", m50_index: 58, percent_change: -42}
11: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Collier County", m50_index: 77, percent_change: -23}
12: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Columbia County", m50_index: 87, percent_change: -13}
13: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "DeSoto County", m50_index: 64, percent_change: -36}
14: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Dixie County", m50_index: 45, percent_change: -55}
15: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Duval County", m50_index: 66, percent_change: -34}
16: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Escambia County", m50_index: 73, percent_change: -27}
17: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Flagler County", m50_index: 69, percent_change: -31}
18: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Franklin County", m50_index: 74, percent_change: -26}
19: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Gadsden County", m50_index: 70, percent_change: -30}
20: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Gilchrist County", m50_index: 53, percent_change: -47}
21: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Glades County", m50_index: 51, percent_change: -49}
22: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Gulf County", m50_index: 95, percent_change: -5}
23: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Hamilton County", m50_index: 104, percent_change: 4}
24: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Hardee County", m50_index: 60, percent_change: -40}
25: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Hendry County", m50_index: 49, percent_change: -51}
26: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Hernando County", m50_index: 63, percent_change: -37}
27: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Highlands County", m50_index: 70, percent_change: -30}
28: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Hillsborough County", m50_index: 76, percent_change: -24}
29: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Holmes County", m50_index: 70, percent_change: -30}
30: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Indian River County", m50_index: 75, percent_change: -25}
31: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Jackson County", m50_index: 73, percent_change: -27}
32: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Jefferson County", m50_index: 60, percent_change: -40}
33: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Lafayette County", m50_index: 84, percent_change: -16}
34: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Lake County", m50_index: 72, percent_change: -28}
35: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Lee County", m50_index: 66, percent_change: -34}
36: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Leon County", m50_index: 79, percent_change: -21}
37: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Levy County", m50_index: 59, percent_change: -41}
38: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Madison County", m50_index: 106, percent_change: 6}
39: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Manatee County", m50_index: 71, percent_change: -29}
40: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Marion County", m50_index: 64, percent_change: -36}
41: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Martin County", m50_index: 79, percent_change: -21}
42: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Miami-Dade County", m50_index: 68, percent_change: -32}
43: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Monroe County", m50_index: 129, percent_change: 29}
44: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Nassau County", m50_index: 67, percent_change: -33}
45: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Okaloosa County", m50_index: 72, percent_change: -28}
46: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Okeechobee County", m50_index: 78, percent_change: -22}
47: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Orange County", m50_index: 83, percent_change: -17}
48: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Osceola County", m50_index: 88, percent_change: -12}
49: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Palm Beach County", m50_index: 67, percent_change: -33}
50: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Pasco County", m50_index: 59, percent_change: -41}
51: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Pinellas County", m50_index: 66, percent_change: -34}
52: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Polk County", m50_index: 78, percent_change: -22}
53: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Putnam County", m50_index: 74, percent_change: -26}
54: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Saint Johns County", m50_index: 73, percent_change: -27}
55: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Saint Lucie County", m50_index: 62, percent_change: -38}
56: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Santa Rosa County", m50_index: 61, percent_change: -39}
57: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Sarasota County", m50_index: 74, percent_change: -26}
58: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Seminole County", m50_index: 68, percent_change: -32}
59: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Sumter County", m50_index: 69, percent_change: -31}
60: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Suwannee County", m50_index: 63, percent_change: -37}
61: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Taylor County", m50_index: 85, percent_change: -15}
62: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Union County", m50_index: 72, percent_change: -28}
63: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Volusia County", m50_index: 69, percent_change: -31}
64: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Wakulla County", m50_index: 35, percent_change: -65}
65: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Walton County", m50_index: 90, percent_change: -10}
66: {date: Sat Feb 29 2020 19:00:00 GMT-0500 (Eastern Standard Time), place: "Washington County", m50_index: 46, percent_change: -54}
Alonsoag
  • 45
  • 3
  • You probably need to change or check the time zone. 19:00 + 05:00 is 00:00 'the next day'. – Danny_ds Apr 10 '20 at 16:29
  • Hi Danny, I did notice that but I'm new to d3 and javascript and I really don't know how to do that. Any ideas on how I can implement that solution ? – Alonsoag Apr 10 '20 at 16:40
  • Checkout [`d3-time-format`](https://github.com/d3/d3-time-format). Googling around should help you also, many people have faced the exact same problem. – Mehdi Apr 10 '20 at 16:57
  • Hi Mehdi! It did, thank you ! – Alonsoag Apr 10 '20 at 17:05

0 Answers0