Date format in D3.js -


i have column (date) in csv stores date in "2003-02-01"(y-m-d). format date in month , year apr 2003. how do that?

var format = d3.time.format("%m-%y"); data.foreach(function(d,i) { d.date = format(d.date); }); 

i getting following error error: typeerror: n.getfullyear not function line: 5

the csv file contains values:

200,300,400,288,123,2003-01-01 300,700,600,388,500,2003-02-01 

what issue here?

javascript doesn't automatically recognize values in csv file dates, reading them in strings. d3's time functions make pretty easy convert them datetime objects:

> parsedate = d3.time.format("%y-%m-%d").parse > parsedate('2003-01-01') wed jan 01 2003 00:00:00 gmt-0600 (central standard time) 

to format dates want, need go other way, date object string:

> formatdate = d3.time.format("%b-%y") > formatdate(parsedate('2003-01-01')) "jan-2003" 

i recommend representing dates within program date objects , formatting them strings when need display them.


Comments