3

I am getting

Uncaught TypeError: Cannot read property 'length' of undefined

from my console at this line

var parseDate = d3.time.format("%Y-%m-%d").parse;

data.forEach(function(d) { d.Day = parseDate(d.Day); });

here is how my date is formatted in my json object day: "2013-02-04"

CQM
  • 42,592
  • 75
  • 224
  • 366
  • Can you try using an alternative approach http://stackoverflow.com/questions/2587345/javascript-date-parse ? I usually use something like `Date(Date.parse("2005-07-08"));`. – user1477388 Feb 04 '13 at 17:54
  • Sounds like the error message is coming from somewhere else. Can you post a complete minimal example? – Lars Kotthoff Feb 04 '13 at 18:38
  • Is the lowercase 'day' in the object a mistake? Or is it supposed to be 'Day' as in the reference? – cmonkey Feb 04 '13 at 18:47
  • yeah, this was correct @cmonkey it was supposed to be lowercase day. I have another problem now – CQM Feb 04 '13 at 18:51

1 Answers1

6

I suspect the case of 'day' is incorrect. I can execute:

var parseDate = d3.time.format("%Y-%m-%d").parse;
parseDate( "2013-02-03" )

Without issue (it shows the correct Date). Likely, you need to change the code to:

data.forEach(function(d) { d.day = parseDate(d.day); });

(note, lowercase 'd' in 'day')

cmonkey
  • 4,256
  • 1
  • 26
  • 46