I have a date scale in d3 and I’m looking to cap the x.domain()[0] to the first day of the month and x.domain()[1] to the last day of the month. Assume that the data set is something like
data : [
{date: '2011-12-31', amount: 200},
{date: '2012-01-01', amount: 100},
{date: '2012-01-02', amount: 300},
{date: '2012-01-03', amount: 400},
{date: '2012-02-01', amount: 400}
]
Its a contrived example but basically under this scenario cap the domain to the month of January. Looking for an easy d3esque solution.
I think what you are looking for is the
.nice()function which makes a domain start and end on nice values (in your case, the first and last of the month). You will still need to filter your data, I don’t think there is any magic to automatically determine that you want to show January in this case vs December or February.You can see an example of this at http://bl.ocks.org/3849376.