Java Code Examples for com.github.mikephil.charting.data.BarEntry#getVal()
The following examples show how to use
com.github.mikephil.charting.data.BarEntry#getVal() .
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 iMoney with Apache License 2.0 | 6 votes |
/** * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be * found in the charts data. * * @param e * @return */ public RectF getBarBounds(BarEntry e) { BarDataSet set = mData.getDataSetForEntry(e); if (set == null) return null; float barspace = set.getBarSpace(); float y = e.getVal(); float x = e.getXIndex(); float barWidth = 0.5f; float spaceHalf = barspace / 2f; float left = x - barWidth + spaceHalf; float right = x + barWidth - spaceHalf; float top = y >= 0 ? y : 0; float bottom = y <= 0 ? y : 0; RectF bounds = new RectF(left, top, right, bottom); getTransformer(set.getAxisDependency()).rectValueToPixel(bounds); return bounds; }
Example 2
Source File: BarChart.java From Stayfit with Apache License 2.0 | 6 votes |
/** * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be * found in the charts data. * * @param e * @return */ public RectF getBarBounds(BarEntry e) { IBarDataSet set = mData.getDataSetForEntry(e); if (set == null) return null; float barspace = set.getBarSpace(); float y = e.getVal(); float x = e.getXIndex(); float barWidth = 0.5f; float spaceHalf = barspace / 2f; float left = x - barWidth + spaceHalf; float right = x + barWidth - spaceHalf; float top = y >= 0 ? y : 0; float bottom = y <= 0 ? y : 0; RectF bounds = new RectF(left, top, right, bottom); getTransformer(set.getAxisDependency()).rectValueToPixel(bounds); return bounds; }
Example 3
Source File: BarChart.java From NetKnight with Apache License 2.0 | 6 votes |
/** * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be * found in the charts data. * * @param e * @return */ public RectF getBarBounds(BarEntry e) { IBarDataSet set = mData.getDataSetForEntry(e); if (set == null) return null; float barspace = set.getBarSpace(); float y = e.getVal(); float x = e.getXIndex(); float barWidth = 0.5f; float spaceHalf = barspace / 2f; float left = x - barWidth + spaceHalf; float right = x + barWidth - spaceHalf; float top = y >= 0 ? y : 0; float bottom = y <= 0 ? y : 0; RectF bounds = new RectF(left, top, right, bottom); getTransformer(set.getAxisDependency()).rectValueToPixel(bounds); return bounds; }
Example 4
Source File: BarChart.java From Notification-Analyser with MIT License | 6 votes |
/** * Returns the bounding box of the specified Entry in the specified DataSet. * Returns null if the Entry could not be found in the charts data. * * @param e * @param dataSetIndex * @return */ public RectF getBarBounds(BarEntry e) { BarDataSet set = mOriginalData.getDataSetForEntry(e); if (set == null) return null; float barspace = set.getBarSpace(); float y = e.getVal(); float x = e.getXIndex(); float spaceHalf = barspace / 2f; float left = x + spaceHalf; float right = x + 1f - spaceHalf; float top = y >= 0 ? y : 0; float bottom = y <= 0 ? y : 0; RectF bounds = new RectF(left, top, right, bottom); transformRect(bounds); return bounds; }
Example 5
Source File: BarHighlighter.java From NetKnight 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 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 6
Source File: HorizontalBarChart.java From iMoney with Apache License 2.0 | 4 votes |
@Override public RectF getBarBounds(BarEntry e) { BarDataSet set = mData.getDataSetForEntry(e); if (set == null) return null; float barspace = set.getBarSpace(); float y = e.getVal(); float x = e.getXIndex(); float spaceHalf = barspace / 2f; float top = x - 0.5f + spaceHalf; float bottom = x + 0.5f - spaceHalf; float left = y >= 0 ? y : 0; float right = y <= 0 ? y : 0; RectF bounds = new RectF(left, top, right, bottom); getTransformer(set.getAxisDependency()).rectValueToPixel(bounds); return bounds; }
Example 7
Source File: BarChartRenderer.java From iMoney with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { int setCount = mChart.getBarData().getDataSetCount(); for (int i = 0; i < indices.length; i++) { Highlight h = indices[i]; int index = h.getXIndex(); int dataSetIndex = h.getDataSetIndex(); BarDataSet set = mChart.getBarData().getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; float barspaceHalf = set.getBarSpace() / 2f; Transformer trans = mChart.getTransformer(set.getAxisDependency()); mHighlightPaint.setColor(set.getHighLightColor()); mHighlightPaint.setAlpha(set.getHighLightAlpha()); // check outofbounds if (index >= 0 && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) { BarEntry e = set.getEntryForXIndex(index); if (e == null || e.getXIndex() != index) continue; float groupspace = mChart.getBarData().getGroupSpace(); boolean isStack = h.getStackIndex() < 0 ? false : true; // calculate the correct x-position float x = index * setCount + dataSetIndex + groupspace / 2f + groupspace * index; final float y1; final float y2; if (isStack) { y1 = h.getRange().from; y2 = h.getRange().to; } else { y1 = e.getVal(); y2 = 0.f; } prepareBarHighlight(x, y1, y2, barspaceHalf, trans); c.drawRect(mBarRect, mHighlightPaint); if (mChart.isDrawHighlightArrowEnabled()) { mHighlightPaint.setAlpha(255); // distance between highlight arrow and bar float offsetY = mAnimator.getPhaseY() * 0.07f; float[] values = new float[9]; trans.getPixelToValueMatrix().getValues(values); final float xToYRel = Math.abs(values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]); final float arrowWidth = set.getBarSpace() / 2.f; final float arrowHeight = arrowWidth * xToYRel; final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY(); Path arrow = new Path(); arrow.moveTo(x + 0.4f, yArrow + offsetY); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight); trans.pathValueToPixel(arrow); c.drawPath(arrow, mHighlightPaint); } } } }
Example 8
Source File: HorizontalBarChart.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public RectF getBarBounds(BarEntry e) { IBarDataSet set = mData.getDataSetForEntry(e); if (set == null) return null; float barspace = set.getBarSpace(); float y = e.getVal(); float x = e.getXIndex(); float spaceHalf = barspace / 2f; float top = x - 0.5f + spaceHalf; float bottom = x + 0.5f - spaceHalf; float left = y >= 0 ? y : 0; float right = y <= 0 ? y : 0; RectF bounds = new RectF(left, top, right, bottom); getTransformer(set.getAxisDependency()).rectValueToPixel(bounds); return bounds; }
Example 9
Source File: RealmBarDataSet.java From Stayfit with Apache License 2.0 | 4 votes |
@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 10
Source File: BarChartRenderer.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { int setCount = mChart.getBarData().getDataSetCount(); for (int i = 0; i < indices.length; i++) { Highlight h = indices[i]; int index = h.getXIndex(); int dataSetIndex = h.getDataSetIndex(); IBarDataSet set = mChart.getBarData().getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; float barspaceHalf = set.getBarSpace() / 2f; Transformer trans = mChart.getTransformer(set.getAxisDependency()); mHighlightPaint.setColor(set.getHighLightColor()); mHighlightPaint.setAlpha(set.getHighLightAlpha()); // check outofbounds if (index >= 0 && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) { BarEntry e = set.getEntryForXIndex(index); if (e == null || e.getXIndex() != index) continue; float groupspace = mChart.getBarData().getGroupSpace(); boolean isStack = h.getStackIndex() < 0 ? false : true; // calculate the correct x-position float x = index * setCount + dataSetIndex + groupspace / 2f + groupspace * index; final float y1; final float y2; if (isStack) { y1 = h.getRange().from; y2 = h.getRange().to; } else { y1 = e.getVal(); y2 = 0.f; } prepareBarHighlight(x, y1, y2, barspaceHalf, trans); c.drawRect(mBarRect, mHighlightPaint); if (mChart.isDrawHighlightArrowEnabled()) { mHighlightPaint.setAlpha(255); // distance between highlight arrow and bar float offsetY = mAnimator.getPhaseY() * 0.07f; float[] values = new float[9]; trans.getPixelToValueMatrix().getValues(values); final float xToYRel = Math.abs(values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]); final float arrowWidth = set.getBarSpace() / 2.f; final float arrowHeight = arrowWidth * xToYRel; final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY(); Path arrow = new Path(); arrow.moveTo(x + 0.4f, yArrow + offsetY); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight); trans.pathValueToPixel(arrow); c.drawPath(arrow, mHighlightPaint); } } } }
Example 11
Source File: HorizontalBarChart.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public RectF getBarBounds(BarEntry e) { IBarDataSet set = mData.getDataSetForEntry(e); if (set == null) return null; float barspace = set.getBarSpace(); float y = e.getVal(); float x = e.getXIndex(); float spaceHalf = barspace / 2f; float top = x - 0.5f + spaceHalf; float bottom = x + 0.5f - spaceHalf; float left = y >= 0 ? y : 0; float right = y <= 0 ? y : 0; RectF bounds = new RectF(left, top, right, bottom); getTransformer(set.getAxisDependency()).rectValueToPixel(bounds); return bounds; }
Example 12
Source File: RealmBarDataSet.java From NetKnight with Apache License 2.0 | 4 votes |
@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: BarChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { BarData barData = mChart.getBarData(); int setCount = barData.getDataSetCount(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? barData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { IBarDataSet set = barData.getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; float barspaceHalf = set.getBarSpace() / 2f; Transformer trans = mChart.getTransformer(set.getAxisDependency()); mHighlightPaint.setColor(set.getHighLightColor()); mHighlightPaint.setAlpha(set.getHighLightAlpha()); int index = high.getXIndex(); // check outofbounds if (index >= 0 && index < (mChart.getXChartMax() * mAnimator.getPhaseX()) / setCount) { BarEntry e = set.getEntryForXIndex(index); if (e == null || e.getXIndex() != index) continue; float groupspace = barData.getGroupSpace(); boolean isStack = high.getStackIndex() < 0 ? false : true; // calculate the correct x-position float x = index * setCount + dataSetIndex + groupspace / 2f + groupspace * index; final float y1; final float y2; if (isStack) { y1 = high.getRange().from; y2 = high.getRange().to; } else { y1 = e.getVal(); y2 = 0.f; } prepareBarHighlight(x, y1, y2, barspaceHalf, trans); c.drawRect(mBarRect, mHighlightPaint); if (mChart.isDrawHighlightArrowEnabled()) { mHighlightPaint.setAlpha(255); // distance between highlight arrow and bar float offsetY = mAnimator.getPhaseY() * 0.07f; float[] values = new float[9]; trans.getPixelToValueMatrix().getValues(values); final float xToYRel = Math.abs( values[Matrix.MSCALE_Y] / values[Matrix.MSCALE_X]); final float arrowWidth = set.getBarSpace() / 2.f; final float arrowHeight = arrowWidth * xToYRel; final float yArrow = (y1 > -y2 ? y1 : y1) * mAnimator.getPhaseY(); Path arrow = new Path(); arrow.moveTo(x + 0.4f, yArrow + offsetY); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY - arrowHeight); arrow.lineTo(x + 0.4f + arrowWidth, yArrow + offsetY + arrowHeight); trans.pathValueToPixel(arrow); c.drawPath(arrow, mHighlightPaint); } } } } }
Example 14
Source File: BarChart.java From Notification-Analyser with MIT License | 4 votes |
@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)); } } } } } } }