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 6999285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:31:17+00:00 2026-05-27T20:31:17+00:00

I am looking for a good algorithm to generate nice major/minor tick intervals for

  • 0

I am looking for a good algorithm to generate nice major/minor tick intervals for a DateTime axis on custom charting component. I have read this previous question here, which discusses a nice way to calculate major/minor ticks and minimum/maximum values for a numerical axis. However, it is difficult to translate this into date axis calculations.

The reason is that some date ranges are in different bases to others, some are not even consistent time frames. Consider an axis range in several minutes. This calculation is fairly easy as you can divide the minutes up using a similar algorithm to that presented above. However what do you do when the same axis is asked to present data in the Years/Months, or Months/Week range?

The requirement for this axis are that it can calculate major/minor tick marks so that the chart is never too cluttered, with input data ranges in the milliseconds right up to months and years. It is intended to be used on a realtime chart so static presentation is not as important as ability to update quickly. My simplistic algorithm does this:

  • If range > 3 years, choose major=1 year, minor = 3month
  • If range > 1 year, choose major=3 month, minor=1 month
  • If range > 3 months, choose major=month, minor=nothing (I was considering week however since month is not divisible by week it looks odd)
  • If range > 1 week, choose major=1 day, minor=nothing
  • If range < 1 day, choose hours according to the nice numbers algorithm
  • If range < 1 hour, choose minutes
  • If range < 1 minute, choose seconds

etc…

As you can see its a lot of if-statements and possible to miss something out. In this approach I often end up with glitches at certain dates and I was wondering if there was an easy or common way to approach this problem.

Best regards,
Andrew

  • 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-05-27T20:31:18+00:00Added an answer on May 27, 2026 at 8:31 pm
    1. Have a sorted array of all possible ticks: 1 second, 1 minute, 1 hour, 1 day, 1 month, 1 year.
    2. Decide what is the minimum distance for major (min_dist_major) and for minor (min_dist_minor) tick. Those are constants and have values in pixels.
    3. Find the smallest major tick that is larger than min_dist_major when shown on monitor.
    4. Then find the smallest minor tick that is less than major tick but larger than min_dist_minor when shown on monitor. If minor tick can’t be found then it does not exist.

    You can expand your array with other ticks, such as 2 and 5 of every type.

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

Sidebar

Related Questions

I'm looking for a good algorithm that can give me the unique edges from
I am looking for good ideas for implementing a generic way to have a
I'm looking for a good algorithm to get all the elements in one array
I'm looking for any good tutorials on vectorizing (loops) in MATLAB. I have quite
I'm looking for a good algorithm / method to check the data quality in
I have heard of this algorithm, but is this algorithm good to use it
I am looking for an algorithm to generate pseudo random numbers in a three
I am looking for a good algorithm that can recommend content objects to user
I'm looking for a good (well-tested, fully-featured, and ideally with a nice interface) matrix
i'm designing a tag system and i'm looking for a good search algorithm. It

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.