d3.js - D3 Histogram - Date Based -


i have array of dates

["01/01/2001", "01/01/2001", "03/01/2001", "01/04/2001", "01/05/2001", "02/05/2001", "01/07/2001", "01/07/2001", "01/07/2001", "01/10/2001"] 

some duplicates , in no particular order, on varying timescale (1 week, 43 days, 2 years etc).

what want produce histogram (or bar chart) shows counts of "dates" in arbitrary # of buckets (like 20 buckets).

where there no dates in bucket shows 0 , total buckets contain dates.

basically example: http://bl.ocks.org/mbostock/3048450

but instead of showing random "seconds" need "dates".

like:

histogram of dates

i guess i'm looking change x scale domain range of dates in data.

so solution @larskotthoff suggested in comments.

var x = d3.time.scale().domain([firstdate, lastdate]).range([0, width]);  var data = d3.layout.histogram()         .bins(x.ticks(bins))           (values);  var formatdate = d3.time.format("%d/%m/%y"); var xaxis = d3.svg.axis()             .scale(x)             .orient("bottom")             .tickformat(formatdate); 

Comments