math - Finding the y-axis for points on a line graph made with PHP's imageline() -


i'm making line graph php using imagecreate() , imageline(). im' trying figure out how calculation find y-axis each point on graph.

here few values go in graph:

$values[jan] = .84215; $values[feb] = 1.57294; $values[mar] = 3.75429; 

here example of line graph. x-axis labels positioned @ vertical middle of x-axis lines. gap between x-axis lines 25px.

how calculation find y-axis values in array above?

5.00 4.75 4.50 4.25 4.00 3.75 3.50 3.25 3.00 2.75 2.50 2.25 2.00 1.75 1.50 1.25 1.00 0.75 0.50 0.25 0.00      jan  feb  mar  apr  may  jun  jul  aug  sep  oct  nov  dec 

you need way map floating point number between [0.00 5.00] y-axis points.

the granularity of y-axis 0.25. can divide input 0.25 exact point on y-axis. value between 2 point example input 0.3 , 0.3/0.25 1.2 , there not 1.2 on y-axis.

to solve associate range +|-0.125 each y-axis number. 1.0 have range 0.75 1.25, input input/0.25 falling in [0.75 1.25] have 1.00 y-axis point.

in php can as:

$y_cord = ceil ( $input / 0.25 - 0.125) * 0.25; 

you can see mapping of random dataset here.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -