Java Code Examples for com.github.mikephil.charting.data.BarEntry#getX()
The following examples show how to use
com.github.mikephil.charting.data.BarEntry#getX() .
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 |
/** * 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 |
@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 |
/** * 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 |
@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 |
/** * 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 |
@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: BarHighlighter.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 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 8
Source File: BarHighlighter.java From Ticket-Analysis with MIT License | 5 votes |
/** * 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 android-kline with Apache License 2.0 | 5 votes |
/** * 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: HorizontalBarChartRenderer.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Override protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) { Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mBarBorderPaint.setColor(dataSet.getBarBorderColor()); mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth())); final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f; float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); // draw the bar shadow before the values if (mChart.isDrawBarShadowEnabled()) { mShadowPaint.setColor(dataSet.getBarShadowColor()); BarData barData = mChart.getBarData(); final float barWidth = barData.getBarWidth(); final float barWidthHalf = barWidth / 2.0f; float x; for (int i = 0, count = Math.min((int) (Math.ceil((float) (dataSet.getEntryCount()) * phaseX)), dataSet.getEntryCount()); i < count; i++) { BarEntry e = dataSet.getEntryForIndex(i); x = e.getX(); mBarShadowRectBuffer.top = x - barWidthHalf; mBarShadowRectBuffer.bottom = x + barWidthHalf; trans.rectValueToPixel(mBarShadowRectBuffer); if (!mViewPortHandler.isInBoundsTop(mBarShadowRectBuffer.bottom)) { continue; } if (!mViewPortHandler.isInBoundsBottom(mBarShadowRectBuffer.top)) { break; } mBarShadowRectBuffer.left = mViewPortHandler.contentLeft(); mBarShadowRectBuffer.right = mViewPortHandler.contentRight(); c.drawRect(mBarShadowRectBuffer, mShadowPaint); } } // initialize the buffer BarBuffer buffer = mBarBuffers[index]; buffer.setPhases(phaseX, phaseY); buffer.setDataSet(index); buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency())); buffer.setBarWidth(mChart.getBarData().getBarWidth()); buffer.feed(dataSet); trans.pointValuesToPixel(buffer.buffer); final boolean isSingleColor = dataSet.getColors().size() == 1; if (isSingleColor) { mRenderPaint.setColor(dataSet.getColor()); } for (int j = 0; j < buffer.size(); j += 4) { if (!mViewPortHandler.isInBoundsTop(buffer.buffer[j + 3])) { break; } if (!mViewPortHandler.isInBoundsBottom(buffer.buffer[j + 1])) { continue; } if (!isSingleColor) { // Set the color for the currently drawn value. If the index // is out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j / 4)); } c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mRenderPaint); if (drawBorder) { c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mBarBorderPaint); } } }
Example 11
Source File: BarChartRenderer.java From Ticket-Analysis with MIT License | 4 votes |
protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) { Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mBarBorderPaint.setColor(dataSet.getBarBorderColor()); mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth())); final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f; float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); // draw the bar shadow before the values if (mChart.isDrawBarShadowEnabled()) { mShadowPaint.setColor(dataSet.getBarShadowColor()); BarData barData = mChart.getBarData(); final float barWidth = barData.getBarWidth(); final float barWidthHalf = barWidth / 2.0f; float x; for (int i = 0, count = Math.min((int)(Math.ceil((float)(dataSet.getEntryCount()) * phaseX)), dataSet.getEntryCount()); i < count; i++) { BarEntry e = dataSet.getEntryForIndex(i); x = e.getX(); mBarShadowRectBuffer.left = x - barWidthHalf; mBarShadowRectBuffer.right = x + barWidthHalf; trans.rectValueToPixel(mBarShadowRectBuffer); if (!mViewPortHandler.isInBoundsLeft(mBarShadowRectBuffer.right)) continue; if (!mViewPortHandler.isInBoundsRight(mBarShadowRectBuffer.left)) break; mBarShadowRectBuffer.top = mViewPortHandler.contentTop(); mBarShadowRectBuffer.bottom = mViewPortHandler.contentBottom(); c.drawRect(mBarShadowRectBuffer, mShadowPaint); } } // initialize the buffer BarBuffer buffer = mBarBuffers[index]; buffer.setPhases(phaseX, phaseY); buffer.setDataSet(index); buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency())); buffer.setBarWidth(mChart.getBarData().getBarWidth()); buffer.feed(dataSet); trans.pointValuesToPixel(buffer.buffer); final boolean isSingleColor = dataSet.getColors().size() == 1; if (isSingleColor) { mRenderPaint.setColor(dataSet.getColor()); } for (int j = 0; j < buffer.size(); j += 4) { if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2])) continue; if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j])) break; if (!isSingleColor) { // Set the color for the currently drawn value. If the index // is out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j / 4)); } c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mRenderPaint); if (drawBorder) { c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mBarBorderPaint); } } }
Example 12
Source File: HorizontalBarChartRenderer.java From Ticket-Analysis with MIT License | 4 votes |
@Override protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) { Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mBarBorderPaint.setColor(dataSet.getBarBorderColor()); mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth())); final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f; float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); // draw the bar shadow before the values if (mChart.isDrawBarShadowEnabled()) { mShadowPaint.setColor(dataSet.getBarShadowColor()); BarData barData = mChart.getBarData(); final float barWidth = barData.getBarWidth(); final float barWidthHalf = barWidth / 2.0f; float x; for (int i = 0, count = Math.min((int)(Math.ceil((float)(dataSet.getEntryCount()) * phaseX)), dataSet.getEntryCount()); i < count; i++) { BarEntry e = dataSet.getEntryForIndex(i); x = e.getX(); mBarShadowRectBuffer.top = x - barWidthHalf; mBarShadowRectBuffer.bottom = x + barWidthHalf; trans.rectValueToPixel(mBarShadowRectBuffer); if (!mViewPortHandler.isInBoundsTop(mBarShadowRectBuffer.bottom)) continue; if (!mViewPortHandler.isInBoundsBottom(mBarShadowRectBuffer.top)) break; mBarShadowRectBuffer.left = mViewPortHandler.contentLeft(); mBarShadowRectBuffer.right = mViewPortHandler.contentRight(); c.drawRect(mBarShadowRectBuffer, mShadowPaint); } } // initialize the buffer BarBuffer buffer = mBarBuffers[index]; buffer.setPhases(phaseX, phaseY); buffer.setDataSet(index); buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency())); buffer.setBarWidth(mChart.getBarData().getBarWidth()); buffer.feed(dataSet); trans.pointValuesToPixel(buffer.buffer); final boolean isSingleColor = dataSet.getColors().size() == 1; if (isSingleColor) { mRenderPaint.setColor(dataSet.getColor()); } for (int j = 0; j < buffer.size(); j += 4) { if (!mViewPortHandler.isInBoundsTop(buffer.buffer[j + 3])) break; if (!mViewPortHandler.isInBoundsBottom(buffer.buffer[j + 1])) continue; if (!isSingleColor) { // Set the color for the currently drawn value. If the index // is out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j / 4)); } c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mRenderPaint); if (drawBorder) { c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mBarBorderPaint); } } }
Example 13
Source File: BarChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) { Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mBarBorderPaint.setColor(dataSet.getBarBorderColor()); mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth())); final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f; float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); // draw the bar shadow before the values if (mChart.isDrawBarShadowEnabled()) { mShadowPaint.setColor(dataSet.getBarShadowColor()); BarData barData = mChart.getBarData(); final float barWidth = barData.getBarWidth(); final float barWidthHalf = barWidth / 2.0f; float x; for (int i = 0, count = Math.min((int)(Math.ceil((float)(dataSet.getEntryCount()) * phaseX)), dataSet.getEntryCount()); i < count; i++) { BarEntry e = dataSet.getEntryForIndex(i); x = e.getX(); mBarShadowRectBuffer.left = x - barWidthHalf; mBarShadowRectBuffer.right = x + barWidthHalf; trans.rectValueToPixel(mBarShadowRectBuffer); if (!mViewPortHandler.isInBoundsLeft(mBarShadowRectBuffer.right)) continue; if (!mViewPortHandler.isInBoundsRight(mBarShadowRectBuffer.left)) break; mBarShadowRectBuffer.top = mViewPortHandler.contentTop(); mBarShadowRectBuffer.bottom = mViewPortHandler.contentBottom(); c.drawRect(mBarShadowRectBuffer, mShadowPaint); } } // initialize the buffer BarBuffer buffer = mBarBuffers[index]; buffer.setPhases(phaseX, phaseY); buffer.setDataSet(index); buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency())); buffer.setBarWidth(mChart.getBarData().getBarWidth()); buffer.feed(dataSet); trans.pointValuesToPixel(buffer.buffer); final boolean isSingleColor = dataSet.getColors().size() == 1; if (isSingleColor) { mRenderPaint.setColor(dataSet.getColor()); } for (int j = 0; j < buffer.size(); j += 4) { if (!mViewPortHandler.isInBoundsLeft(buffer.buffer[j + 2])) continue; if (!mViewPortHandler.isInBoundsRight(buffer.buffer[j])) break; if (!isSingleColor) { // Set the color for the currently drawn value. If the index // is out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j / 4)); } c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mRenderPaint); if (drawBorder) { c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mBarBorderPaint); } } }
Example 14
Source File: HorizontalBarChartRenderer.java From android-kline with Apache License 2.0 | 4 votes |
@Override protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) { Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); mBarBorderPaint.setColor(dataSet.getBarBorderColor()); mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth())); final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f; float phaseX = mAnimator.getPhaseX(); float phaseY = mAnimator.getPhaseY(); // draw the bar shadow before the values if (mChart.isDrawBarShadowEnabled()) { mShadowPaint.setColor(dataSet.getBarShadowColor()); BarData barData = mChart.getBarData(); final float barWidth = barData.getBarWidth(); final float barWidthHalf = barWidth / 2.0f; float x; for (int i = 0, count = Math.min((int)(Math.ceil((float)(dataSet.getEntryCount()) * phaseX)), dataSet.getEntryCount()); i < count; i++) { BarEntry e = dataSet.getEntryForIndex(i); x = e.getX(); mBarShadowRectBuffer.top = x - barWidthHalf; mBarShadowRectBuffer.bottom = x + barWidthHalf; trans.rectValueToPixel(mBarShadowRectBuffer); if (!mViewPortHandler.isInBoundsTop(mBarShadowRectBuffer.bottom)) continue; if (!mViewPortHandler.isInBoundsBottom(mBarShadowRectBuffer.top)) break; mBarShadowRectBuffer.left = mViewPortHandler.contentLeft(); mBarShadowRectBuffer.right = mViewPortHandler.contentRight(); c.drawRect(mBarShadowRectBuffer, mShadowPaint); } } // initialize the buffer BarBuffer buffer = mBarBuffers[index]; buffer.setPhases(phaseX, phaseY); buffer.setDataSet(index); buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency())); buffer.setBarWidth(mChart.getBarData().getBarWidth()); buffer.feed(dataSet); trans.pointValuesToPixel(buffer.buffer); final boolean isSingleColor = dataSet.getColors().size() == 1; if (isSingleColor) { mRenderPaint.setColor(dataSet.getColor()); } for (int j = 0; j < buffer.size(); j += 4) { if (!mViewPortHandler.isInBoundsTop(buffer.buffer[j + 3])) break; if (!mViewPortHandler.isInBoundsBottom(buffer.buffer[j + 1])) continue; if (!isSingleColor) { // Set the color for the currently drawn value. If the index // is out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j / 4)); } c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mRenderPaint); if (drawBorder) { c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mBarBorderPaint); } } }