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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:26:41+00:00 2026-05-26T15:26:41+00:00

I have one page that displays a bar graph, and the values can vary

  • 0

I have one page that displays a bar graph, and the values can vary from a tiny range (0 to 30) to a large range (0 to 10000).

My problem is displaying it in a div that has a maximum height, in my case the bars can’t be more than 90px.

One example:

bar graph

Knowing that the maximum height is 90px, what I thought of doing is to check which is the highest bar (meaning this one is the 100%), and then the others are percentages of that one. This way I can control the height (the biggest will have 90px) of each and remain within the limis of the height.

My code so far: (the values in this code are not related to the image above)

$limitedHeight = 90;

$bar1 = 300;
$bar2 = 700;
$bar3 = 150;

$biggestBar = max(array($bar1, $bar2, $bar3));

//knowing this, I will force each bar to the limited height:
//first, for each, get the percentage:
$bar1Percent = intval(($bar1 * 100) / $biggestBar);
$bar2Percent = intval(($bar2 * 100) / $biggestBar);
$bar3Percent = intval(($bar3 * 100) / $biggestBar);

//then, force the new heights:
$bar1Height = intval(($bar1Percent * $limitedHeight) / 100);
$bar2Height = intval(($bar2Percent * $limitedHeight) / 100);
$bar3Height = intval(($bar3Percent * $limitedHeight) / 100);

//place the height into the bars:
echo '<div class="bar1" style="height: ' . $bar1Height . 'px"></div>
<div class="bar2" style="height: ' . $bar2Height . 'px"></div>
<div class="bar3" style="height: ' . $bar3Height . 'px"></div>';

My question:

Is this the right approach?
Or does anyone have a better solution?

(This solution could have one problem: if bar “A” is just “10”, and bar “B” is “1000”, the calculated (limited) height will have a huge difference, but I suppose it is what it is, the proportion is respected).

  • 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-26T15:26:42+00:00Added an answer on May 26, 2026 at 3:26 pm

    You can calculate a single scale factor that you apply to all bars:

    $scale = $limitedHeight / $biggestBar;
    
    $bar1Height = intval($bar1 * $scale);
    $bar2Height = intval($bar2 * $scale);
    $bar3Height = intval($bar3 * $scale);
    

    That will just simplify your calculations a little, but the overall approach seems sound. And the problem with the huge height difference is inevitable when you’re using a linear scale.

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

Sidebar

Related Questions

I currently have a page that displays player information from one table named tblplayers.
i am porting over a website from asp. i have one page that i
I have created one aspx Page from that i need to access the property
I have this web page I'm developing that displays multiple images of one product
On a page that I'm designing I have a form with one input of
i have a page that contains several submit buttons however i only want one
I have a page that is using jQuery tabs. Within one of my tabs
I have a page that contains several forms, by submitting each one of them,
I have a sharepoint page that loads six webparts, each one of them consumes
I have a nice page that does everything I need. However one of the

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.