Trouble Shooting Cannot Read Property 'length' of Undefined

Viewed 365

My d3 US map was working fine for a while, I was plotting circles from my csv data with no problem. It looked like this:

var url = "my_data.csv";

      d3.csv(url, function(error, rawData) {
                var data = rawData.map(function(d)
          {
            return {
                        File: d.File,
                Latitude: +d.Latitude,
                Longitude: +d.Longitude,
                Place: d.Location,
            };
          }).filter(d => projection([d.Longitude,d.Latitude]));

However, I noticed when I tried to parse the time dimension of the data, things got a little complicated. My parse of data containing dates failed citing the error: "Cannot read property 'length' of undefined". My dates are have the 1/22/2015 format, so I used the following (I also tried %x):

var parseTime = d3.time.format("%m/%d/%Y").parse;
var formatDate = d3.time.format("%m/%d/%Y");
var url = "my_data.csv";

      d3.csv(url, function(error, rawData) {
                var data = rawData.map(function(d)
          {
            return {
                        File: d.File,
                Latitude: +d.Latitude,
                Longitude: +d.Longitude,
                Place: d.Location,
                        Due: parseTime(d.Due),
                        //Notif: parseTime(d.Notification)
            };
          }).filter(d => projection([d.Longitude,d.Latitude]));

I check the existing literature relating to this error in D3 and it seems to have two main causes (that I'm aware of at least):

  • the data callback had an issue, as was the case here
  • or the data itself suffered a delimiter issue, as was the case here

I have parsed dated data before without (too many) issues, so at first I thought it could be the 2nd of the above causes -- the data has a delimiter issue. Perhaps a comma has been omitted or there were two commas, or instead of a comma there is a period or semi-colon.

My first step to troubleshoot was to take my data set (which was in the thousands) and delete everything except for about 80 observations, which is more manageable. After looking through the scaled-down data, everything seemed to be in order. And just to be safe I deleted everything except for 2 observations, and yet the error persisted. So, it looks like it was not a delimiter issue after all.

Question: This whole process created more questions than answers, I'm not sure how to proceed. Perhaps there is another cause of the error that I'm not aware of?

For reference, I have uploaded a minimalist block of my particular undefined 'length' issue.

1 Answers
Related