Java Code Examples for com.github.mikephil.charting.data.BarData#getDataSetByIndex()
The following examples show how to use
com.github.mikephil.charting.data.BarData#getDataSetByIndex() .
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: HistogramChart.java From walt with Apache License 2.0 | 6 votes |
void recalculateDataSet(final BarData barData) { minBin = Math.floor(min / binWidth) * binWidth; maxBin = Math.floor(max / binWidth) * binWidth; int[][] bins = new int[rawData.size()][getNumBins()]; for (int setNum = 0; setNum < rawData.size(); setNum++) { for (Double d : rawData.get(setNum)) { ++bins[setNum][(int) (Math.floor((d - minBin) / binWidth))]; } } for (int setNum = 0; setNum < barData.getDataSetCount(); setNum++) { final IBarDataSet dataSet = barData.getDataSetByIndex(setNum); dataSet.clear(); for (int i = 0; i < bins[setNum].length; i++) { dataSet.addEntry(new BarEntry(i, bins[setNum][i])); } } groupBars(barData); barData.notifyDataChanged(); }
Example 2
Source File: HorizontalBarHighlighter.java From Ticket-Analysis with MIT License | 6 votes |
@Override public Highlight getHighlight(float x, float y) { BarData barData = mChart.getBarData(); MPPointD pos = getValsForTouch(y, x); Highlight high = getHighlightForX((float) pos.y, y, x); if (high == null) return null; IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex()); if (set.isStacked()) { return getStackedHighlight(high, set, (float) pos.y, (float) pos.x); } MPPointD.recycleInstance(pos); return high; }
Example 3
Source File: BarHighlighter.java From Ticket-Analysis with MIT License | 6 votes |
@Override public Highlight getHighlight(float x, float y) { Highlight high = super.getHighlight(x, y); if(high == null) { return null; } MPPointD pos = getValsForTouch(x, y); BarData barData = mChart.getBarData(); IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex()); if (set.isStacked()) { return getStackedHighlight(high, set, (float) pos.x, (float) pos.y); } MPPointD.recycleInstance(pos); return high; }
Example 4
Source File: BarHighlighter.java From android-kline with Apache License 2.0 | 6 votes |
@Override public Highlight getHighlight(float x, float y) { Highlight high = super.getHighlight(x, y); if(high == null) { return null; } MPPointD pos = getValsForTouch(x, y); BarData barData = mChart.getBarData(); IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex()); if (set.isStacked()) { return getStackedHighlight(high, set, (float) pos.x, (float) pos.y); } MPPointD.recycleInstance(pos); return high; }
Example 5
Source File: FiveDayChart.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * 动态增加一个点数据 * @param timeDatamodel * @param length */ public void dynamicsAddOne(TimeDataModel timeDatamodel, int length) { int index = length - 1; LineData lineData = lineChart.getData(); ILineDataSet d1 = lineData.getDataSetByIndex(0); d1.addEntry(new Entry( index, (float) timeDatamodel.getNowPrice())); ILineDataSet d2 = lineData.getDataSetByIndex(1); d2.addEntry(new Entry( index, (float) timeDatamodel.getAveragePrice())); BarData barData = barChart.getData(); IBarDataSet barDataSet = barData.getDataSetByIndex(0); float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f; barDataSet.addEntry(new BarEntry( index, timeDatamodel.getVolume(),color)); lineData.notifyDataChanged(); lineChart.notifyDataSetChanged(); barData.notifyDataChanged(); barChart.notifyDataSetChanged(); lineChart.setVisibleXRange(maxCount, maxCount); barChart.setVisibleXRange(maxCount, maxCount); //动态添加或移除数据后, 调用invalidate()刷新图表之前 必须调用 notifyDataSetChanged() . lineChart.moveViewToX(index); barChart.moveViewToX(index); }
Example 6
Source File: HorizontalBarHighlighter.java From StockChart-MPAndroidChart with MIT License | 6 votes |
@Override public Highlight getHighlight(float x, float y) { BarData barData = mChart.getBarData(); MPPointD pos = getValsForTouch(y, x); Highlight high = getHighlightForX((float) pos.y, y, x); if (high == null) { return null; } IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex()); if (set.isStacked()) { return getStackedHighlight(high, set, (float) pos.y, (float) pos.x); } MPPointD.recycleInstance(pos); return high; }
Example 7
Source File: HorizontalBarHighlighter.java From android-kline with Apache License 2.0 | 6 votes |
@Override public Highlight getHighlight(float x, float y) { BarData barData = mChart.getBarData(); MPPointD pos = getValsForTouch(y, x); Highlight high = getHighlightForX((float) pos.y, y, x); if (high == null) return null; IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex()); if (set.isStacked()) { return getStackedHighlight(high, set, (float) pos.y, (float) pos.x); } MPPointD.recycleInstance(pos); return high; }
Example 8
Source File: BarChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void drawData(Canvas c) { BarData barData = mChart.getBarData(); for (int i = 0; i < barData.getDataSetCount(); i++) { IBarDataSet set = barData.getDataSetByIndex(i); if (set.isVisible()) { drawDataSet(c, set, i); } } }
Example 9
Source File: BarChartRenderer.java From Ticket-Analysis with MIT License | 5 votes |
@Override public void drawData(Canvas c) { BarData barData = mChart.getBarData(); for (int i = 0; i < barData.getDataSetCount(); i++) { IBarDataSet set = barData.getDataSetByIndex(i); if (set.isVisible()) { drawDataSet(c, set, i); } } }
Example 10
Source File: BarChartRenderer.java From Ticket-Analysis with MIT License | 5 votes |
@Override public void initBuffers() { BarData barData = mChart.getBarData(); mBarBuffers = new BarBuffer[barData.getDataSetCount()]; for (int i = 0; i < mBarBuffers.length; i++) { IBarDataSet set = barData.getDataSetByIndex(i); mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1), barData.getDataSetCount(), set.isStacked()); } }
Example 11
Source File: BarChartRenderer.java From Stayfit with Apache License 2.0 | 5 votes |
@Override public void initBuffers() { BarData barData = mChart.getBarData(); mBarBuffers = new BarBuffer[barData.getDataSetCount()]; for (int i = 0; i < mBarBuffers.length; i++) { IBarDataSet set = barData.getDataSetByIndex(i); mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1), barData.getGroupSpace(), barData.getDataSetCount(), set.isStacked()); } }
Example 12
Source File: OneDayChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 动态更新最后一点数据 * @param timeDatamodel * @param length */ public void dynamicsUpdateOne(TimeDataModel timeDatamodel, int length) { int index = length - 1; LineData lineData = lineChart.getData(); ILineDataSet d1 = lineData.getDataSetByIndex(0); Entry e = d1.getEntryForIndex(index); d1.removeEntry(e); d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice())); ILineDataSet d2 = lineData.getDataSetByIndex(1); Entry e2 = d2.getEntryForIndex(index); d2.removeEntry(e2); d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice())); BarData barData = barChart.getData(); IBarDataSet barDataSet = barData.getDataSetByIndex(0); barDataSet.removeEntry(index); float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f; barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color)); lineData.notifyDataChanged(); lineChart.notifyDataSetChanged(); lineChart.moveViewToX(index); barData.notifyDataChanged(); barChart.notifyDataSetChanged(); barChart.moveViewToX(index); }
Example 13
Source File: HorizontalBarChartRenderer.java From iMoney with Apache License 2.0 | 5 votes |
@Override public void initBuffers() { BarData barData = mChart.getBarData(); mBarBuffers = new HorizontalBarBuffer[barData.getDataSetCount()]; for (int i = 0; i < mBarBuffers.length; i++) { BarDataSet set = barData.getDataSetByIndex(i); mBarBuffers[i] = new HorizontalBarBuffer(set.getValueCount() * 4 * set.getStackSize(), barData.getGroupSpace(), barData.getDataSetCount(), set.isStacked()); } }
Example 14
Source File: HorizontalBarChartRenderer.java From Stayfit with Apache License 2.0 | 5 votes |
@Override public void initBuffers() { BarData barData = mChart.getBarData(); mBarBuffers = new HorizontalBarBuffer[barData.getDataSetCount()]; for (int i = 0; i < mBarBuffers.length; i++) { IBarDataSet set = barData.getDataSetByIndex(i); mBarBuffers[i] = new HorizontalBarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1), barData.getGroupSpace(), barData.getDataSetCount(), set.isStacked()); } }
Example 15
Source File: BarChartRenderer.java From NetKnight with Apache License 2.0 | 5 votes |
@Override public void initBuffers() { BarData barData = mChart.getBarData(); mBarBuffers = new BarBuffer[barData.getDataSetCount()]; for (int i = 0; i < mBarBuffers.length; i++) { IBarDataSet set = barData.getDataSetByIndex(i); mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1), barData.getGroupSpace(), barData.getDataSetCount(), set.isStacked()); } }
Example 16
Source File: BarHighlighter.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public Highlight getHighlight(float x, float y) { BarData barData = mChart.getBarData(); final int xIndex = getXIndex(x); final float baseNoSpace = getBase(x); final int setCount = barData.getDataSetCount(); int dataSetIndex = ((int)baseNoSpace) % setCount; if (dataSetIndex < 0) { dataSetIndex = 0; } else if (dataSetIndex >= setCount) { dataSetIndex = setCount - 1; } SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, dataSetIndex); if (selectionDetail == null) return null; IBarDataSet set = barData.getDataSetByIndex(dataSetIndex); if (set.isStacked()) { float[] pts = new float[2]; pts[1] = y; // take any transformer to determine the x-axis value mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts); return getStackedHighlight(selectionDetail, set, xIndex, pts[1]); } return new Highlight( xIndex, selectionDetail.value, selectionDetail.dataIndex, selectionDetail.dataSetIndex, -1); }
Example 17
Source File: HorizontalBarHighlighter.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public Highlight getHighlight(float x, float y) { BarData barData = mChart.getBarData(); final int xIndex = getXIndex(x); final float baseNoSpace = getBase(x); final int setCount = barData.getDataSetCount(); int dataSetIndex = ((int)baseNoSpace) % setCount; if (dataSetIndex < 0) { dataSetIndex = 0; } else if (dataSetIndex >= setCount) { dataSetIndex = setCount - 1; } SelectionDetail selectionDetail = getSelectionDetail(xIndex, y, dataSetIndex); if (selectionDetail == null) return null; IBarDataSet set = barData.getDataSetByIndex(dataSetIndex); if (set.isStacked()) { float[] pts = new float[2]; pts[0] = y; // take any transformer to determine the x-axis value mChart.getTransformer(set.getAxisDependency()).pixelsToValue(pts); return getStackedHighlight(selectionDetail, set, xIndex, pts[0]); } return new Highlight( xIndex, selectionDetail.value, selectionDetail.dataIndex, selectionDetail.dataSetIndex, -1); }
Example 18
Source File: TimeBarChartRenderer.java From StockChart-MPAndroidChart with MIT License | 2 votes |
@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 19
Source File: BarChartRenderer.java From android-kline with Apache License 2.0 | 2 votes |
@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); } }
Example 20
Source File: BarChartRenderer.java From android-kline with Apache License 2.0 | 2 votes |
@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); } }