@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); } }
/** * Constructor for stacked bar entries. One data object for whole stack * * @param x * @param vals - the stack values, use at least 2 */ public BarEntry(float x, float[] vals) { super(x, calcSum(vals)); this.mYVals = vals; calcPosNegSum(); calcRanges(); }
/** * Set the array of values this BarEntry should represent. * * @param vals */ public void setVals(float[] vals) { setY(calcSum(vals)); mYVals = vals; calcPosNegSum(); calcRanges(); }
entries.add(new BarEntry(Float.parseFloat(split[1]), Float.parseFloat(split[0])));
@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); }
mHighlightPaint.setAlpha(set.getHighLightAlpha()); boolean isStack = (high.getStackIndex() >= 0 && e.isStacked()) ? true : false; y1 = e.getPositiveSum(); y2 = -e.getNegativeSum(); Range range = e.getRanges()[high.getStackIndex()]; y1 = e.getY(); y2 = 0.f; prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);
continue; float x = e.getX(); float y = e.getY(); float[] vals = e.getYVals(); float negY = -e.getNegativeSum(); float yStart = 0f;
values1.add(new BarEntry(i, 50)); values2.add(new BarEntry(i, 60)); assertEquals(27f, groupWidth, 0.01f); assertEquals(0f, values1.get(0).getX(), 0.01f); assertEquals(1f, values1.get(1).getX(), 0.01f); assertEquals(1008f, values1.get(0).getX(), 0.01f); assertEquals(1019f, values2.get(0).getX(), 0.01f); assertEquals(1035f, values1.get(1).getX(), 0.01f); assertEquals(1046f, values2.get(1).getX(), 0.01f); assertEquals(-992f, values1.get(0).getX(), 0.01f); assertEquals(-981f, values2.get(0).getX(), 0.01f); assertEquals(-965f, values1.get(1).getX(), 0.01f); assertEquals(-954f, values2.get(1).getX(), 0.01f); data.groupBars(-20, groupSpace, barSpace); assertEquals(-12f, values1.get(0).getX(), 0.01f); assertEquals(-1f, values2.get(0).getX(), 0.01f); assertEquals(15f, values1.get(1).getX(), 0.01f); assertEquals(26f, values2.get(1).getX(), 0.01f);
float val = entry.getY(); if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) { Drawable icon = entry.getIcon(); float[] vals = entry.getYVals(); float x = (buffer.buffer[bufferIndex] + buffer.buffer[bufferIndex + 2]) / 2f; (entry.getY() >= 0 ? posOffset : negOffset), color); if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) { Drawable icon = entry.getIcon(); (entry.getY() >= 0 ? posOffset : negOffset); float negY = -entry.getNegativeSum(); if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) { Drawable icon = entry.getIcon();
/** * calculates the maximum stacksize that occurs in the Entries array of this * DataSet */ private void calcStackSize(List<BarEntry> yVals) { for (int i = 0; i < yVals.size(); i++) { float[] vals = yVals.get(i).getYVals(); if (vals != null && vals.length > mStackSize) mStackSize = vals.length; } }
@Override public void onDataReady(List<UbidotsClient.Value> result) { Log.d("Chart", "======== On data Ready ==========="); List<BarEntry> entries = new ArrayList(); List<String> labels = new ArrayList<String>(); for (int i=0; i < result.size(); i++) { BarEntry be = new BarEntry(result.get(i).value, i); entries.add(be); Log.d("Chart", be.toString()); // Convert timestamp to date Date d = new Date(result.get(i).timestamp); // Create Labels labels.add(sdf.format(d)); } BarDataSet lse = new BarDataSet(entries, "Humidity"); lse.setDrawValues(false); lse.setColor(Color.BLUE); BarData bd = new BarData(labels, lse); humChart.setData(bd); Handler handler = new Handler(ChartFragment.this.getActivity().getMainLooper()); handler.post(new Runnable() { @Override public void run() { humChart.invalidate(); } }); } });
x = e.getX();
protected void calcRanges() { float[] values = getYVals(); if (values == null || values.length == 0) return; mRanges = new Range[values.length]; float negRemain = -getNegativeSum(); float posRemain = 0f; for (int i = 0; i < mRanges.length; i++) { float value = values[i]; if (value < 0) { mRanges[i] = new Range(negRemain, negRemain - value); negRemain -= value; } else { mRanges[i] = new Range(posRemain, posRemain + value); posRemain += value; } } } }
entry.setX(fromX);
/** * 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()); }
protected BarData generateBarData(int dataSets, float range, int count) { ArrayList<IBarDataSet> sets = new ArrayList<>(); for(int i = 0; i < dataSets; i++) { ArrayList<BarEntry> entries = new ArrayList<>(); for(int j = 0; j < count; j++) { entries.add(new BarEntry(j, (float) (Math.random() * range) + range / 4)); } BarDataSet ds = new BarDataSet(entries, getLabel(i)); ds.setColors(ColorTemplate.VORDIPLOM_COLORS); sets.add(ds); } BarData d = new BarData(sets); d.setValueTypeface(tf); return d; }
/** * 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); }