@Override public void onValueSelected(Entry e, Highlight h) { BarEntry entry = (BarEntry) e; if (entry.getYVals() != null) Log.i("VAL SELECTED", "Value: " + entry.getYVals()[h.getStackIndex()]); else Log.i("VAL SELECTED", "Value: " + entry.getY()); }
/** * Used to draw bar labels, calls {@link #getFormattedValue(float)} by default. * * @param barEntry bar being labeled * @return formatted string label */ public String getBarLabel(BarEntry barEntry) { return getFormattedValue(barEntry.getY()); }
@Override public String getBarStackedLabel(float value, BarEntry entry) { if (!mDrawWholeStack) { float[] vals = entry.getYVals(); 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(entry.getY()) + mSuffix; } else { return ""; // return empty } } } // return the "proposed" value return mFormat.format(value) + mSuffix; } }
/** * Returns an exact copy of the BarEntry. */ public BarEntry copy() { BarEntry copied = new BarEntry(getX(), getY(), getData()); copied.setVals(mYVals); return copied; }
@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); } }
@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); }
@Override public void refreshContent(Entry e, Highlight highlight) { if (e instanceof BarEntry) { BarEntry be = (BarEntry) e; if(be.getYVals() != null) { // draw the stack value tvContent.setText(Utils.formatNumber(be.getYVals()[highlight.getStackIndex()], 0, true)); } else { tvContent.setText(Utils.formatNumber(be.getY(), 0, true)); } } else { tvContent.setText(Utils.formatNumber(e.getY(), 0, true)); } super.refreshContent(e, highlight); }
/** * 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); }
float y = e.getY(); float[] vals = e.getYVals();
y1 = e.getY(); y2 = 0.f;
float y = e.getY(); float[] vals = e.getYVals();
/** * Returns an exact copy of the BarEntry. */ public BarEntry copy() { BarEntry copied = new BarEntry(getX(), getY(), getData()); copied.setVals(mYVals); return copied; }
entry.getY(), (float) pixels.x, (float) pixels.y,
/** * Returns an exact copy of the BarEntry. */ public BarEntry copy() { BarEntry copied = new BarEntry(getX(), getY(), getData()); copied.setVals(mYVals); return copied; }
/** * Returns an exact copy of the BarEntry. */ public BarEntry copy() { BarEntry copied = new BarEntry(getX(), getY(), getData()); copied.setVals(mYVals); return copied; }
float val = entry.getY(); String formattedValue = formatter.getBarLabel(entry); drawValue(c, formattedValue, buffer.buffer[bufferIndex + 2] + (entry.getY() >= 0 ? posOffset : negOffset), buffer.buffer[bufferIndex + 1] + halfTextHeight, color); + (entry.getY() >= 0 ? posOffset : negOffset); float py = buffer.buffer[bufferIndex + 1];
@Test public void testBinHeights() { final IBarDataSet barDataSet = barData.getDataSetByIndex(0); assertEquals(3, barDataSet.getEntryCount()); assertEquals(2d, barDataSet.getEntryForIndex(0).getY(), 0.000001); assertEquals(1d, barDataSet.getEntryForIndex(1).getY(), 0.000001); assertEquals(1d, barDataSet.getEntryForIndex(2).getY(), 0.000001); }
@Override public void onValueSelected(Entry e, Highlight h) { BarEntry entry = (BarEntry) e; if (entry.getYVals() != null) Log.i("VAL SELECTED", "Value: " + entry.getYVals()[h.getStackIndex()]); else Log.i("VAL SELECTED", "Value: " + entry.getY()); }
/** * Returns an exact copy of the BarEntry. */ @Override public BarEntry copy() { BarEntry copied = new BarEntry(getXIndex(), getX(), getY(), getData()); copied.setVals(mYVals); return copied; }