Minor bugfixes concerning selecting values. Added getAverage() method.
This commit is contained in:
parent
9c945acb2c
commit
1440a7c234
4 changed files with 26 additions and 5 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue