score:2

Accepted answer

Here's a plunk with the fixed code: http://plnkr.co/edit/Xj2ZyxqrY2PJVV0FML26

There were several issues here.

Firstly, your data wasn't sorted by date (earliest to latest), which was preventing the bisectYear function from working properly (it was always returning 1). Fixed by adding:

data.sort(function(a, b) { return a.Year - b.Year; });

Secondly, your date (year) values weren't being parsed to Date objects, which was causing a range of problems. Essentially, your time scale was running from 1891ms to 2014ms, rather than the years 1891 to 2014! I added this at the point where you read in the CSV:

data.forEach(function(d) {
    d.Year =  parseDate(d.Year)
    ...

with a new function to parse into a Date just based on the full year:

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

Related Query

More Query from same tag