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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:25:09+00:00 2026-05-12T14:25:09+00:00

I have a bit of javascript that I am using to calculate the y-scale

  • 0

I have a bit of javascript that I am using to calculate the y-scale of a graph. I need to adjust the scale according to the value. This works but seems really verbose. Is there a more streamlined way to do this?

if (maxValue <= 20000){
    chartMaxY = 20000
}       
if (maxValue <= 10000){
    chartMaxY = 10000
}       
if (maxValue <= 5000){
    chartMaxY = 5000
}       
if (maxValue <= 2500){
    chartMaxY = 2500
}
if (maxValue <= 1000){
    chartMaxY = 1000
}
if (maxValue <= 500){
    chartMaxY = 500
}       
if (maxValue <= 250){
    chartMaxY = 250
}           
if (maxValue <= 100){
    chartMaxY = 100
}   
if (maxValue <= 50){
    chartMaxY = 50
}   
if (maxValue <= 10){
    chartMaxY = 10
}   
  • 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-12T14:25:10+00:00Added an answer on May 12, 2026 at 2:25 pm

    Same thing, possibly more succinct depending on your programming style.

    var keys = [10, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 20000];
    
    for (var i=0; i<keys.length; i++) {
        if (maxValue <= keys[i]) {
            chartMaxY = keys[i];
            break;
        }
    }
    

    The reverse order of key-values causes maxValue to only be set once, but note this does not modify values > 20000 (though neither did original)

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

Sidebar

Related Questions

I have a little bit of Javascript that almost works correctly. Here's the code:
I'm a bit of a javascript noob, but I have a general question that
I have a bit of JavaScript that builds some HTML for me and inserts
I have a bit of Javascript code that creates a save friendly version of
With some help from SO, I have a bit of javascript/jquery that cycles through
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
I have problems with the following bit of javascript/jquery code: this.droppable = function(){ $('.imageWindow
I have a file called bbUI.js which contains this bit of JavaScript. Outside of
I have a bit of JavaScript code that is specified in a configuration file
I've got this bit of css/javascript/html that uses jQuery 1.5 and jQuery-ui 1.8.9. It's

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.