Assembla home | Assembla project page
 

Ticket #3 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

How to find the range automagically

Reported by: achew22@gmail.com Assigned to:
Priority: normal Milestone: v1.0
Severity: normal Keywords:
Cc:

Description

Here is a little bit of code that I've been using so that I don't have to take a WAG at what is the best maximum

A little bit (the minimum stuff) was written and never tested so use at your risk

<code> $data = Set of data to be dealing with as a simple indexed array

//Calculate the maximum $max = 0; $min = $data[0]; //Set the minimum to the first value just in case foreach ($data as $count) {

if ($count > $max) {

$max = $count;

} if ($cont < $min) {

$min = $count;

}

}

// Do a little math to figure out the nearest .5 increment // sprintf is used to convert an integer into a string so that strlen will count this is done instead of typecasting because that wasn't returning anything for me (go figure) $increment = ((pow(10, strlen(sprintf("%d", $max)) - 1)) * .5);

// Count up to the increment right after the maximum $yMax = 0; $yMin = 0; while ($yMax < $max) {

$yMax += $increment;

} while ($yMin < $min) {

$yMin -= $increment;

}

$graph->set_y_max( $yMax ); $graph->set_y_min( $yMin );

</code>

This code will take a dataset in and manipulate 23,053 => 25,000 113 => 150 7,272 => 7,500 88 => 90 (Maybe not the best but I don't know how else to deal with it)

All I ask is that you keep it open source and keep my name in there

Sincerely, ~Andrew Allen

Attachments

Change History

05/31/08 04:24:21 changed by joaquin.win

  • status changed from new to closed.
  • resolution set to fixed.

(In [5]) Documenting functions. Closes #1 Now calculates automatically the right ranges for y-axis (setRange usage is not necesary now). Closes #3 many thanks to Andrew Allen


Add/Change #3 (How to find the range automagically)




Change Properties
Action