dealing with dates on d3.js axis dealing with dates on d3.js axis json json

dealing with dates on d3.js axis


You're trying to use d3.scale.linear() for dates, and that won't work. You need to use d3.time.scale() instead (docs):

// helper functionfunction getDate(d) {    return new Date(d.jsonDate);}// get max and min dates - this assumes data is sortedvar minDate = getDate(data[0]),    maxDate = getDate(data[data.length-1]);var x = d3.time.scale().domain([minDate, maxDate]).range([0, w]);

Then you don't need to deal with the time interval functions, you can just pass x a date:

.attr("d", d3.svg.line()    .x(function(d) { return x(getDate(d)) })    .y(function(d) { return y(d.jsonHitCount) }));

Working fiddle here: http://jsfiddle.net/nrabinowitz/JTrnC/