Created
July 9, 2014 18:29
-
-
Save lecho/7f0aa7e8cb4afc37d6a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Automatically calculates Y axis values. | |
private Axis calculateYAxis(int numberOfSteps) { | |
if (numberOfSteps < 2) { | |
throw new | |
IllegalArgumentException("Number or steps have to be grater or equal 2"); | |
} | |
List<Float> values = new ArrayList<Float>(); | |
final float range = mData.getMaxYValue() - mData.getMinYValue(); | |
final float tickRange = range / (numberOfSteps - 1); | |
final float x = (float) Math.ceil(Math.log10(tickRange) - 1); | |
final float pow10x = (float) Math.pow(10, x); | |
final float roundedTickRange = (float) Math.ceil(tickRange / pow10x) * | |
pow10x; | |
float value = mData.getMinYValue(); | |
while (value <= mData.getMaxYValue()) { | |
values.add(value); | |
value += roundedTickRange; | |
} | |
Axis yAxis = new Axis(); | |
yAxis.setValues(values); | |
return yAxis; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment