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

  • Home
  • SEARCH
  • 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 337253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:19:06+00:00 2026-05-12T10:19:06+00:00

I have been working on a project that requires a bar graph to be

  • 0

I have been working on a project that requires a bar graph to be populated with price results. The chart displays the number of items within a given price range. For instance, if on amazon there are 9 items within the price range of $0-$10 the x-axis would display $0-$10 and the y-axis would be populated with a value of 9.

My bar graph has 8 bars, all with similar price ranges. $0-$10, $10-$20, $20-$30… etc.

My question is this: What is the best way to define those individual points? There is no common price range between these items, so the x-axis cannot be static numbers. They must be dynamically calculated within the range of results.

As such, currently I am creating the x-axis points as follows:

I take the lowest result:
@numbers[0] = results[0];

And I take the highest result:
@numbers[8] = results[-1];

Then I find the median of the two:
@numbers[4] = (@numbers[0]+@numbers[8])/2;

I then repeat the process 6 more times

@numbers[2] = (@numbers[0]+@numbers[4])/2; @numbers[6] = (@numbers[4]+@numbers[8])/2; @numbers[1] = (@numbers[0]+@numbers[2])/2; @numbers[3] = (@numbers[2]+@numbers[4])/2; @numbers[5] = (@numbers[4]+@numbers[6])/2; @numbers[7] = (@numbers[6]+@numbers[8])/2;

This gives me the results I need, but it seems awfully repetitive and I would imagine there is a better way.

I tried creating a loop, but I could not write it in a less verbose manner.

Is there a quicker way to do this, or perhaps something more along the lines of DRY?

  • 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-12T10:19:07+00:00Added an answer on May 12, 2026 at 10:19 am

    Are your bins always of equal size? In your example, all share range=10. If so, then you could do:

    binspacing = overall range / (numberofbins-1);
    

    and the position of bin n would be the x-axis position of numbers[0] plus n times the binspacing.

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

Sidebar

Related Questions

I have a project i've been working on that requires me to retrieve the
I've been working on a project that requires draft/live versions of content and have
I have been working on a project that requires downloading a zipped file off
I have been working on a project in Eclipse that requires me to open
Hey so I have been working on a project that I want to be
I have a django project that I have been working on as a solo
I have a console project that I have been working on. I added log4net
I have a project on github that I have been working on before. However,
So I've been working on a project that requires offering the possibility to view
I'm working on a project that requires GUI, but I have no experience 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.