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

The following examples show how to use com.github.mikephil.charting.data.BarEntry#getNegativeSum() . 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: RealmBarDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 6 votes vote down vote up
@Override
protected void calcMinMax(BarEntry e) {

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

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

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

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

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

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

        calcMinMaxX(e);
    }
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
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 8
Source File: BarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BarData barData = mChart.getBarData();

    for (Highlight high : indices) {

        IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled()) {
            continue;
        }

        BarEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set)) {
            continue;
        }

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setStrokeWidth(Utils.convertDpToPixel(set.getHighlightLineWidth()));

        boolean isStack = (high.getStackIndex() >= 0 && e.isStacked()) ? true : false;

        final float y1;
        final float y2;

        if (isStack) {

            if (mChart.isHighlightFullBarEnabled()) {

                y1 = e.getPositiveSum();
                y2 = -e.getNegativeSum();

            } else {

                Range range = e.getRanges()[high.getStackIndex()];

                y1 = range.from;
                y2 = range.to;
            }
        } else {
            y1 = e.getY();
            y2 = 0.f;
        }

        prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);

        setHighlightDrawPos(high, mBarRect);

        c.drawRect(mBarRect, mHighlightPaint);
    }
}
 
Example 9
Source File: TimeBarChartRenderer.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BarData barData = mChart.getBarData();

    for (Highlight high : indices) {

        IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled()) {
            continue;
        }

        BarEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set)) {
            continue;
        }

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setStrokeWidth(Utils.convertDpToPixel(set.getHighlightLineWidth()));

        boolean isStack = (high.getStackIndex() >= 0 && e.isStacked()) ? true : false;

        final float y1;
        final float y2;

        if (isStack) {

            if (mChart.isHighlightFullBarEnabled()) {

                y1 = e.getPositiveSum();
                y2 = -e.getNegativeSum();

            } else {

                Range range = e.getRanges()[high.getStackIndex()];

                y1 = range.from;
                y2 = range.to;
            }
        } else {
            y1 = e.getY();
            y2 = 0.f;
        }

        prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);

        setHighlightDrawPos(high, mBarRect);

        c.drawLine(mBarRect.centerX(), mViewPortHandler.getContentRect().bottom, mBarRect.centerX(), 0, mHighlightPaint);
    }
}
 
Example 10
Source File: BarChartRenderer.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BarData barData = mChart.getBarData();

    for (Highlight high : indices) {

        IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        BarEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setAlpha(set.getHighLightAlpha());

        boolean isStack = (high.getStackIndex() >= 0  && e.isStacked()) ? true : false;

        final float y1;
        final float y2;

        if (isStack) {

            if(mChart.isHighlightFullBarEnabled()) {

                y1 = e.getPositiveSum();
                y2 = -e.getNegativeSum();

            } else {

                Range range = e.getRanges()[high.getStackIndex()];

                y1 = range.from;
                y2 = range.to;
            }

        } else {
            y1 = e.getY();
            y2 = 0.f;
        }

        prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);

        setHighlightDrawPos(high, mBarRect);

        c.drawRect(mBarRect, mHighlightPaint);
    }
}
 
Example 11
Source File: BarChartRenderer.java    From android-kline with Apache License 2.0 2 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BarData barData = mChart.getBarData();

    for (Highlight high : indices) {

        IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        BarEntry e = set.getEntryForXValue(high.getX(), high.getY());

        if (!isInBoundsX(e, set))
            continue;

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setAlpha(set.getHighLightAlpha());

        boolean isStack = (high.getStackIndex() >= 0  && e.isStacked()) ? true : false;

        final float y1;
        final float y2;

        if (isStack) {

            if(mChart.isHighlightFullBarEnabled()) {

                y1 = e.getPositiveSum();
                y2 = -e.getNegativeSum();

            } else {

                Range range = e.getRanges()[high.getStackIndex()];

                y1 = range.from;
                y2 = range.to;
            }

        } else {
            y1 = e.getY();
            y2 = 0.f;
        }

        prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);

        setHighlightDrawPos(high, mBarRect);

        c.drawRect(mBarRect, mHighlightPaint);
    }
}
 
Example 12
Source File: BarChartRenderer.java    From android-kline with Apache License 2.0 2 votes vote down vote up
@Override
    public void drawHighlighted(Canvas c, Highlight[] indices) {

        BarData barData = mChart.getBarData();

        for (Highlight high : indices) {

            IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());

            if (set == null || !set.isHighlightEnabled())
                continue;

            BarEntry e = set.getEntryForXValue(high.getX(), high.getY());

            if (!isInBoundsX(e, set))
                continue;

            Transformer trans = mChart.getTransformer(set.getAxisDependency());

            mHighlightPaint.setColor(set.getHighLightColor());
            mHighlightPaint.setAlpha(set.getHighLightAlpha());

            boolean isStack = (high.getStackIndex() >= 0 && e.isStacked()) ? true : false;

            final float y1;
            final float y2;

            if (isStack) {

                if (mChart.isHighlightFullBarEnabled()) {

                    y1 = e.getPositiveSum();
                    y2 = -e.getNegativeSum();

                } else {

                    Range range = e.getRanges()[high.getStackIndex()];

                    y1 = range.from;
                    y2 = range.to;
                }

            } else {
                y1 = e.getY();
                y2 = 0.f;
            }

            prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);

            setHighlightDrawPos(high, mBarRect);

//            c.drawRect(mBarRect, mHighlightPaint);
             /*重写高亮*/
            mHighlightPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
            c.drawLine(mBarRect.centerX(), mViewPortHandler.getContentRect().bottom, mBarRect.centerX(), 0, mHighlightPaint);
        }
    }