最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - d3 time format for YYYY-MM-DD ie. 2013-02-04 - Stack Overflow

programmeradmin3浏览0评论

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"

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"

Share Improve this question asked Feb 4, 2013 at 17:51 CQMCQM 44.3k77 gold badges230 silver badges370 bronze badges 4
  • Can you try using an alternative approach stackoverflow./questions/2587345/javascript-date-parse ? I usually use something like Date(Date.parse("2005-07-08"));. – user1477388 Commented Feb 4, 2013 at 17:54
  • Sounds like the error message is ing from somewhere else. Can you post a plete minimal example? – Lars Kotthoff Commented Feb 4, 2013 at 18:38
  • Is the lowercase 'day' in the object a mistake? Or is it supposed to be 'Day' as in the reference? – cmonkey Commented Feb 4, 2013 at 18:47
  • yeah, this was correct @cmonkey it was supposed to be lowercase day. I have another problem now – CQM Commented Feb 4, 2013 at 18:51
Add a ment  | 

1 Answer 1

Reset to default 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')

发布评论

评论列表(0)

  1. 暂无评论