Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8641027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:25:20+00:00 2026-06-12T11:25:20+00:00

I have a date scale in d3 and I’m looking to cap the x.domain()[0]

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:25:22+00:00Added an answer on June 12, 2026 at 11:25 am

    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.

    var data = [
        {date: new Date(2011,11,31), amount: 200},
        {date: new Date(2012,0,1), amount: 100},
        {date: new Date(2012,0,2), amount: 300},
        {date: new Date(2012,0,3), amount: 400},
        {date: new Date(2012,1,1), amount: 400}
    ];
    
    var month = data.filter(function (d) { return d.date.getMonth() === 0; });
    
    var x = d3.time.scale()
        .domain(d3.extent(month, function(d) { return d.date; }))
        .range([0, width])
        .nice(d3.time.month);
    

    You can see an example of this at http://bl.ocks.org/3849376.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some date and I want to get last x day before this
I have a date and a time that I'm attempting to combine in Python.
I have a data frame that has dates, disk reads and disk writes data.
I have a time-series that I'm examining for data heterogeneity, and wish to explain
I have a data frame like this: Server Date Server Space 1 2010-01-30 server1
I have the following dataset with daily collected data. R> toydata date group coef
DB: SQL Server 2005 We have a table that has data in this manner:
Say we have the following simple data-frame of date-value pairs, where some dates are
I have a heat map which I use to visualize large scale GPS data
I have date 2012-04-02 10:01:00 am I want to show this date in with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.