Histogram D3 - Date Based

I have an 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 of them are duplicated and do not have a special order for a certain time (1 week, 43 days, 2 years, etc.).

What I want to do is create a histogram (or histogram) that shows the number of β€œdates” in an arbitrary number of buckets (for example, 20 buckets).

If there are no dates in the bucket, it displays zero and the total for those buckets that contain dates.

Basically, as in this example: http://bl.ocks.org/mbostock/3048450

But instead of showing random "seconds" I need "dates".

how

Histogram of dates

I assume that I want to change the X-scale domain to a date range in my data.

+4
source share
1 answer

So, the solution for this is @LarsKotthoff, suggested in the 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); 
+6
source

Source: https://habr.com/ru/post/1492292/


All Articles