I’m graphing some statistics which can be percentages, currency values or plain numbers.
I need to set the maximum value of the graph control’s axis to a nice, round number just a bit above the maximum value in the data set. (The graph control’s default value is not what I want).
Two things to note:
-
The value I set for the axis maximum should be minimum 5% above the dataset’s maximum value (the less above this the better).
-
I have 4 horizontal lines above the 0 Y-axis; so ideally the Y-axis maximum should divide nicely by 4.
Sample data might be:
200%, 100%, 100%, 100%, 75%, 50%, 9%
In this case, 220% would be acceptable as the maximum value.
$3500161, $1825223, $1671232, $110112
In this case, $3680000 might be ok. Or $3700000 I suppose.
Can anyone suggest a nice formula for doing this? I might need to adjust settings, like the 5% margin might be changed to 10%, or I might need to change the 4 horizontal lines to 5.
Here is the code I use to create graph axes.
You can the nice
max_valueandmin_valueas calculated from the initialized forAxisgiven the mathematical min. max. values inx_minandx_max.Example:
new Axis(0,3500161)calculatesmax_value = 4000000.0new Axis(0,1825223)calculatesmax_value = 2000000.0new Axis(0,1671232)calculatesmax_value = 1800000.0new Axis(0, 110112)calculatesmax_value = 120000.0