Minor bugfixes concerning selecting values. Added getAverage() method.

This commit is contained in:
Philipp Jahoda 2014-05-23 17:03:10 +02:00
parent 9c945acb2c
commit 1440a7c234
4 changed files with 26 additions and 5 deletions

View file

@ -131,7 +131,7 @@ public class BarChart extends BarLineChartBase {
int index = mIndicesToHightlight[i];
// check outofbounds
if (index < mYVals.size()) {
if (index < mYVals.size() && index >= 0) {
mHighlightPaint.setAlpha(120);

View file

@ -865,6 +865,9 @@ public abstract class BarLineChartBase extends Chart {
double touchPointIndex = pts[0];
double base = Math.floor(touchPointIndex);
// touch out of chart
if(touchPointIndex < 0 || touchPointIndex > getValueCount()-1) return -1;
int index = (int) base;
@ -875,7 +878,7 @@ public abstract class BarLineChartBase extends Chart {
index = (int) base + 1;
}
}
return index;
}

View file

@ -623,7 +623,7 @@ public abstract class Chart extends View {
*/
public boolean valuesToHighlight() {
return mIndicesToHightlight == null || mIndicesToHightlight.length == 0
|| mIndicesToHightlight[0] == -1 ? false : true;
|| mIndicesToHightlight[0] < 0 ? false : true;
}
/**
@ -811,6 +811,24 @@ public abstract class Chart extends View {
return mYMin;
}
/**
* returns the average value of all values the chart holds
*
* @return
*/
public float getAverage() {
return getYValueSum() / mYVals.size();
}
/**
* returns the number of values the chart holds
*
* @return
*/
public int getValueCount() {
return mYVals.size();
}
/**
* returns the center point of the chart
*
@ -1098,7 +1116,7 @@ public abstract class Chart extends View {
* @return
*/
public String getXValue(int index) {
if (mXVals == null || mXVals.size() >= index)
if (mXVals == null || mXVals.size() <= index)
return null;
else
return mXVals.get(index);

View file

@ -117,7 +117,7 @@ public class LineChart extends BarLineChartBase {
int index = mIndicesToHightlight[i];
// check outofbounds
if (index < mYVals.size()) {
if (index < mYVals.size() && index >= 0) {
float[] pts = new float[] {
index, mYChartMax, index, mYChartMin,