Java Code Examples for com.github.mikephil.charting.data.BarEntry#getVals()

The following examples show how to use com.github.mikephil.charting.data.BarEntry#getVals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StackedValueFormatter.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    if (!mDrawWholeStack && entry instanceof BarEntry) {

        BarEntry barEntry = (BarEntry) entry;
        float[] vals = barEntry.getVals();

        if (vals != null) {

            // find out if we are on top of the stack
            if (vals[vals.length - 1] == value) {

                // return the "sum" across all stack values
                return mFormat.format(barEntry.getVal()) + mAppendix;
            } else {
                return ""; // return empty
            }
        }
    }

    // return the "proposed" value
    return mFormat.format(value) + mAppendix;
}
 
Example 2
Source File: StackedBarsMarkerView.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {

    if (e instanceof BarEntry) {

        BarEntry be = (BarEntry) e;

        if(be.getVals() != null) {

            // draw the stack value
            tvContent.setText("" + Utils.formatNumber(be.getVals()[highlight.getStackIndex()], 0, true));
        } else {
            tvContent.setText("" + Utils.formatNumber(be.getVal(), 0, true));
        }
    } else {

        tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
    }
}
 
Example 3
Source File: StackedValueFormatter.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    if (!mDrawWholeStack && entry instanceof BarEntry) {

        BarEntry barEntry = (BarEntry) entry;
        float[] vals = barEntry.getVals();

        if (vals != null) {

            // find out if we are on top of the stack
            if (vals[vals.length - 1] == value) {

                // return the "sum" across all stack values
                return mFormat.format(barEntry.getVal()) + mAppendix;
            } else {
                return ""; // return empty
            }
        }
    }

    // return the "proposed" value
    return mFormat.format(value) + mAppendix;
}
 
Example 4
Source File: BarHighlighter.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected.
 *
 * @param old
 *            the old highlight object before looking for stacked values
 * @param set
 * @param xIndex
 * @param dataSetIndex
 * @param yValue
 * @return
 */
protected Highlight getStackedHighlight(Highlight old, BarDataSet set, int xIndex, int dataSetIndex, double yValue) {

	BarEntry entry = set.getEntryForXIndex(xIndex);

	if (entry == null || entry.getVals() == null)
		return old;

	Range[] ranges = getRanges(entry);
	int stackIndex = getClosestStackIndex(ranges, (float) yValue);

	Highlight h = new Highlight(xIndex, dataSetIndex, stackIndex, ranges[stackIndex]);
	return h;
}
 
Example 5
Source File: BarHighlighter.java    From iMoney with Apache License 2.0 5 votes vote down vote up
/**
 * Splits up the stack-values of the given bar-entry into Range objects.
 * 
 * @param entry
 * @return
 */
protected Range[] getRanges(BarEntry entry) {

	float[] values = entry.getVals();

	if (values == null)
		return null;

	float negRemain = -entry.getNegativeSum();
	float posRemain = 0f;

	Range[] ranges = new Range[values.length];

	for (int i = 0; i < ranges.length; i++) {

		float value = values[i];

		if (value < 0) {
			ranges[i] = new Range(negRemain, negRemain + Math.abs(value));
			negRemain += Math.abs(value);
		} else {
			ranges[i] = new Range(posRemain, posRemain + value);
			posRemain += value;
		}
	}

	return ranges;
}
 
Example 6
Source File: BarHighlighter.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected.
 *
 * @param old
 *            the old highlight object before looking for stacked values
 * @param set
 * @param xIndex
 * @param dataSetIndex
 * @param yValue
 * @return
 */
protected Highlight getStackedHighlight(Highlight old, IBarDataSet set, int xIndex, int dataSetIndex, double yValue) {

	BarEntry entry = set.getEntryForXIndex(xIndex);

	if (entry == null || entry.getVals() == null)
		return old;

	Range[] ranges = getRanges(entry);
	int stackIndex = getClosestStackIndex(ranges, (float) yValue);

	Highlight h = new Highlight(xIndex, dataSetIndex, stackIndex, ranges[stackIndex]);
	return h;
}
 
Example 7
Source File: BarHighlighter.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Splits up the stack-values of the given bar-entry into Range objects.
 * 
 * @param entry
 * @return
 */
protected Range[] getRanges(BarEntry entry) {

	float[] values = entry.getVals();

	if (values == null || values.length == 0)
		return null;

	float negRemain = -entry.getNegativeSum();
	float posRemain = 0f;

	Range[] ranges = new Range[values.length];

	for (int i = 0; i < ranges.length; i++) {

		float value = values[i];

		if (value < 0) {
			ranges[i] = new Range(negRemain, negRemain + Math.abs(value));
			negRemain += Math.abs(value);
		} else {
			ranges[i] = new Range(posRemain, posRemain + value);
			posRemain += value;
		}
	}

	return ranges;
}
 
Example 8
Source File: StackedBarActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {

	BarEntry entry = (BarEntry) e;

	if (entry.getVals() != null)
		Log.i("VAL SELECTED", "Value: " + entry.getVals()[h.getStackIndex()]);
	else
		Log.i("VAL SELECTED", "Value: " + entry.getVal());
}
 
Example 9
Source File: BarHighlighter.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * This method creates the Highlight object that also indicates which value of a stacked BarEntry has been selected.
 *
 * @param selectionDetail the selection detail to work with looking for stacked values
 * @param set
 * @param xIndex
 * @param yValue
 * @return
 */
protected Highlight getStackedHighlight(
		SelectionDetail selectionDetail,
		IBarDataSet set,
		int xIndex,
		double yValue) {

	BarEntry entry = set.getEntryForXIndex(xIndex);

	if (entry == null)
		return null;

	if (entry.getVals() == null) {
		return new Highlight(xIndex,
				entry.getVal(),
				selectionDetail.dataIndex,
				selectionDetail.dataSetIndex);
	}

	Range[] ranges = getRanges(entry);
	if (ranges.length > 0) {
		int stackIndex = getClosestStackIndex(ranges, (float)yValue);
		return new Highlight(
				xIndex,
				entry.getPositiveSum() - entry.getNegativeSum(),
				selectionDetail.dataIndex,
				selectionDetail.dataSetIndex,
				stackIndex,
				ranges[stackIndex]
		);
	}

	return null;
}
 
Example 10
Source File: BarHighlighter.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * Splits up the stack-values of the given bar-entry into Range objects.
 * 
 * @param entry
 * @return
 */
protected Range[] getRanges(BarEntry entry) {

	float[] values = entry.getVals();

	if (values == null || values.length == 0)
		return new Range[0];

	Range[] ranges = new Range[values.length];

	float negRemain = -entry.getNegativeSum();
	float posRemain = 0f;

	for (int i = 0; i < ranges.length; i++) {

		float value = values[i];

		if (value < 0) {
			ranges[i] = new Range(negRemain, negRemain + Math.abs(value));
			negRemain += Math.abs(value);
		} else {
			ranges[i] = new Range(posRemain, posRemain + value);
			posRemain += value;
		}
	}

	return ranges;
}
 
Example 11
Source File: RealmBarDataSet.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public void calcMinMax(int start, int end) {

    if (mValues == null)
        return;

    final int yValCount = mValues.size();

    if (yValCount == 0)
        return;

    int endValue;

    if (end == 0 || end >= yValCount)
        endValue = yValCount - 1;
    else
        endValue = end;

    mYMin = Float.MAX_VALUE;
    mYMax = -Float.MAX_VALUE;

    for (int i = start; i <= endValue; i++) {

        BarEntry e = mValues.get(i);

        if (e != null && !Float.isNaN(e.getVal())) {

            if (e.getVals() == null) {

                if (e.getVal() < mYMin)
                    mYMin = e.getVal();

                if (e.getVal() > mYMax)
                    mYMax = e.getVal();
            } else {

                if (-e.getNegativeSum() < mYMin)
                    mYMin = -e.getNegativeSum();

                if (e.getPositiveSum() > mYMax)
                    mYMax = e.getPositiveSum();
            }
        }
    }

    if (mYMin == Float.MAX_VALUE) {
        mYMin = 0.f;
        mYMax = 0.f;
    }
}
 
Example 12
Source File: RealmBarDataSet.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public void calcMinMax(int start, int end) {

    if (mValues == null)
        return;

    final int yValCount = mValues.size();

    if (yValCount == 0)
        return;

    int endValue;

    if (end == 0 || end >= yValCount)
        endValue = yValCount - 1;
    else
        endValue = end;

    mYMin = Float.MAX_VALUE;
    mYMax = -Float.MAX_VALUE;

    for (int i = start; i <= endValue; i++) {

        BarEntry e = mValues.get(i);

        if (e != null && !Float.isNaN(e.getVal())) {

            if (e.getVals() == null) {

                if (e.getVal() < mYMin)
                    mYMin = e.getVal();

                if (e.getVal() > mYMax)
                    mYMax = e.getVal();
            } else {

                if (-e.getNegativeSum() < mYMin)
                    mYMin = -e.getNegativeSum();

                if (e.getPositiveSum() > mYMax)
                    mYMax = e.getPositiveSum();
            }
        }
    }

    if (mYMin == Float.MAX_VALUE) {
        mYMin = 0.f;
        mYMax = 0.f;
    }
}
 
Example 13
Source File: BarChart.java    From Notification-Analyser with MIT License 4 votes vote down vote up
@Override
protected void drawValues() {

    // if values are drawn
    if (mDrawYValues && mCurrentData.getYValCount() < mMaxVisibleCount * mScaleX) {

        ArrayList<BarDataSet> dataSets = ((BarData) mCurrentData).getDataSets();

        float posOffset = 0f; float negOffset = 0f;

        // calculate the correct offset depending on the draw position of
        // the value
        if (mDrawValueAboveBar) {
            posOffset = -Utils.convertDpToPixel(5);
            negOffset = Utils.calcTextHeight(mValuePaint, "8") * 1.5f;
        } else {
            posOffset = Utils.calcTextHeight(mValuePaint, "8") * 1.5f;
            negOffset = -Utils.convertDpToPixel(5);
        }

        for (int i = 0; i < mCurrentData.getDataSetCount(); i++) {

            BarDataSet dataSet = dataSets.get(i);
            ArrayList<BarEntry> entries = dataSet.getYVals();

            float[] valuePoints = generateTransformedValuesBarChart(entries, i);

            // if only single values are drawn (sum)
            if (!mDrawValuesForWholeStack) {

                for (int j = 0; j < valuePoints.length * mPhaseX; j += 2) {

                    if (isOffContentRight(valuePoints[j]))
                        break;

                    if (isOffContentLeft(valuePoints[j]) || isOffContentTop(valuePoints[j + 1])
                            || isOffContentBottom(valuePoints[j + 1]))
                        continue;

                    float val = entries.get(j / 2).getVal();

                    drawValue(val, valuePoints[j],
                            valuePoints[j + 1] + (val >= 0 ? posOffset : negOffset));
                }

                // if each value of a potential stack should be drawn
            } else {

                for (int j = 0; j < (valuePoints.length - 1) * mPhaseX; j += 2) {

                    if (isOffContentRight(valuePoints[j]))
                        break;

                    if (isOffContentLeft(valuePoints[j]) || isOffContentTop(valuePoints[j + 1])
                            || isOffContentBottom(valuePoints[j + 1]))
                        continue;

                    BarEntry e = entries.get(j / 2);

                    float[] vals = e.getVals();

                    // we still draw stacked bars, but there is one
                    // non-stacked
                    // in between
                    if (vals == null) {

                        drawValue(e.getVal(), valuePoints[j],
                                valuePoints[j + 1] + (e.getVal() >= 0 ? posOffset : negOffset));

                    } else {

                        float[] transformed = new float[vals.length * 2];
                        int cnt = 0;
                        float add = e.getVal();

                        for (int k = 0; k < transformed.length; k += 2) {

                            add -= vals[cnt];
                            transformed[k + 1] = (vals[cnt] + add) * mPhaseY;
                            cnt++;
                        }

                        transformPointArray(transformed);

                        for (int k = 0; k < transformed.length; k += 2) {

                            drawValue(vals[k / 2], valuePoints[j],
                                    transformed[k + 1] + (vals[k / 2] >= 0 ? posOffset : negOffset));
                        }
                    }
                }
            }
        }
    }
}