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

The following examples show how to use com.github.mikephil.charting.data.BarEntry#getY() . 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: BarChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * The passed outputRect will be assigned the values of the bounding box of the specified Entry in the specified DataSet.
 * The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data.
 *
 * @param e
 * @return
 */
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;

    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        bounds.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float left = x - barWidth / 2f;
    float right = x + barWidth / 2f;
    float top = y >= 0 ? y : 0;
    float bottom = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(outputRect);
}
 
Example 2
Source File: HorizontalBarChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;
    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float top = x - barWidth / 2f;
    float bottom = x + barWidth / 2f;
    float left = y >= 0 ? y : 0;
    float right = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(bounds);

}
 
Example 3
Source File: BarChart.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * The passed outputRect will be assigned the values of the bounding box of the specified Entry in the specified DataSet.
 * The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data.
 *
 * @param e
 * @return
 */
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;

    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        bounds.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float left = x - barWidth / 2f;
    float right = x + barWidth / 2f;
    float top = y >= 0 ? y : 0;
    float bottom = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(outputRect);
}
 
Example 4
Source File: HorizontalBarChart.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;
    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float top = x - barWidth / 2f;
    float bottom = x + barWidth / 2f;
    float left = y >= 0 ? y : 0;
    float right = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(bounds);

}
 
Example 5
Source File: BarChart.java    From android-kline with Apache License 2.0 6 votes vote down vote up
/**
 * The passed outputRect will be assigned the values of the bounding box of the specified Entry in the specified DataSet.
 * The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data.
 *
 * @param e
 * @return
 */
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;

    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        bounds.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float left = x - barWidth / 2f;
    float right = x + barWidth / 2f;
    float top = y >= 0 ? y : 0;
    float bottom = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(outputRect);
}
 
Example 6
Source File: HorizontalBarChart.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;
    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float top = x - barWidth / 2f;
    float bottom = x + barWidth / 2f;
    float left = y >= 0 ? y : 0;
    float right = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(bounds);

}
 
Example 7
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 8
Source File: BarHighlighter.java    From StockChart-MPAndroidChart with MIT License 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 high the Highlight to work with looking for stacked values
 * @param set
 * @param xVal
 * @param yVal
 * @return
 */
public Highlight getStackedHighlight(Highlight high, IBarDataSet set, float xVal, float yVal) {

    BarEntry entry = set.getEntryForXValue(xVal, yVal);

    if (entry == null) {
        return null;
    }

    // not stacked
    if (entry.getYVals() == null) {
        return high;
    } else {
        Range[] ranges = entry.getRanges();

        if (ranges.length > 0) {
            int stackIndex = getClosestStackIndex(ranges, yVal);

            MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(high.getX(), ranges[stackIndex].to);

            Highlight stackedHigh = new Highlight(
                    entry.getX(),
                    entry.getY(),
                    (float) pixels.x,
                    (float) pixels.y,
                    high.getDataSetIndex(),
                    stackIndex,
                    high.getAxis()
            );

            MPPointD.recycleInstance(pixels);

            return stackedHigh;
        }
    }

    return null;
}
 
Example 9
Source File: BarHighlighter.java    From Ticket-Analysis with MIT License 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 high the Highlight to work with looking for stacked values
 * @param set
 * @param xVal
 * @param yVal
 * @return
 */
public Highlight getStackedHighlight(Highlight high, IBarDataSet set, float xVal, float yVal) {

    BarEntry entry = set.getEntryForXValue(xVal, yVal);

    if (entry == null)
        return null;

    // not stacked
    if (entry.getYVals() == null) {
        return high;
    } else {
        Range[] ranges = entry.getRanges();

        if (ranges.length > 0) {
            int stackIndex = getClosestStackIndex(ranges, yVal);

            MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(high.getX(), ranges[stackIndex].to);

            Highlight stackedHigh = new Highlight(
                    entry.getX(),
                    entry.getY(),
                    (float) pixels.x,
                    (float) pixels.y,
                    high.getDataSetIndex(),
                    stackIndex,
                    high.getAxis()
            );

            MPPointD.recycleInstance(pixels);

            return stackedHigh;
        }
    }

    return null;
}
 
Example 10
Source File: BarHighlighter.java    From android-kline 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 high the Highlight to work with looking for stacked values
 * @param set
 * @param xVal
 * @param yVal
 * @return
 */
public Highlight getStackedHighlight(Highlight high, IBarDataSet set, float xVal, float yVal) {

    BarEntry entry = set.getEntryForXValue(xVal, yVal);

    if (entry == null)
        return null;

    // not stacked
    if (entry.getYVals() == null) {
        return high;
    } else {
        Range[] ranges = entry.getRanges();

        if (ranges.length > 0) {
            int stackIndex = getClosestStackIndex(ranges, yVal);

            MPPointD pixels = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(high.getX(), ranges[stackIndex].to);

            Highlight stackedHigh = new Highlight(
                    entry.getX(),
                    entry.getY(),
                    (float) pixels.x,
                    (float) pixels.y,
                    high.getDataSetIndex(),
                    stackIndex,
                    high.getAxis()
            );

            MPPointD.recycleInstance(pixels);

            return stackedHigh;
        }
    }

    return null;
}
 
Example 11
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 12
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 13
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 14
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 15
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);
        }
    }