PHP given a series of arbitrary numbers, how can I choose a logical max value on a line graph?

Posted by stormist on Stack Overflow See other posts from Stack Overflow or by stormist
Published on 2010-05-11T18:49:14Z Indexed on 2010/05/11 18:54 UTC
Read the original article Hit count: 226

Filed under:
|
|

I am constructing a line graph in PHP. I was setting the max value of the line graph to the max value of my collection of items, but this ended up making the graph less readable you are unable to view the highest line on the graph as it intersects with the top of it. So what I need is basically a formula to take a set of numbers and calculate what the logical max value of on the line graph should be.. so some examples

3500
250
10049
45394
434
312
       Max value on line graph should probably be 50000

493
412
194
783
457 
344
     max value on line graph would ideally be 1000

545
649
6854
5485
11545 
      In this case, 12000 makes sense as max value

So something as simple as rounding upward to the nearest thousandth might work but I'd need it to progressively increase as the numbers got bigger. (50000 instead of 46,000 in first example) The maximum these numbers will ever be is about a million.

Any recommendations would be greatly appreciated, thank you.

© Stack Overflow or respective owner

Related posts about php

Related posts about math