score:14

Accepted answer

In D3 3.5, you could parse just the way you did, setting the time format...

var formatDate = d3.time.format("%d-%b-%y");

...and then using this time format to parse:

d.date = formatDate.parse(d.date);

But, using D3 4.0, you have to parse dates in a different way, using timeParse:

var parseTime = d3.timeParse("%d-%b-%y");

And, then, modifying your accessor function:

function type(d) {
  d.date = parseTime(d.date);
  d.Flux = +d.Flux;
  return d;
}

score:0

The api has changed. For me the solution was:

var parseTime = d3.timeParse("%Y-%m")
parseTime("2018-09")
=> Sat Sep 01 2018 00:00:00 GMT-0400 (Eastern Daylight Time)

If you want to go the other way, Date class to string:

var formatTime = d3.timeFormat("%Y-%m")
formatTime(new Date)
=> "2020-09"

Related Query

More Query from same tag