Java Code Examples for com.github.mikephil.charting.highlight.Highlight#getDataSetIndex()
The following examples show how to use
com.github.mikephil.charting.highlight.Highlight#getDataSetIndex() .
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: CombinedChartKline.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { List<BarLineScatterCandleBubbleData> dataObjects = mData.getAllData(); if (highlight.getDataIndex() >= dataObjects.size()) return null; ChartData data = dataObjects.get(highlight.getDataIndex()); if (highlight.getDataSetIndex() >= data.getDataSetCount()) return null; else { // The value of the highlighted entry could be NaN - // if we are not interested in highlighting a specific value. List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex()) .getEntriesForXValue(highlight.getX()); return entries.get(0); } }
Example 2
Source File: ChartData.java From NetKnight with Apache License 2.0 | 6 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { if (highlight.getDataSetIndex() >= mDataSets.size()) return null; else { // The value of the highlighted entry could be NaN - // if we are not interested in highlighting a specific value. List<?> entries = mDataSets.get(highlight.getDataSetIndex()) .getEntriesForXIndex(highlight.getXIndex()); for (Object entry : entries) if (((Entry)entry).getVal() == highlight.getValue() || Float.isNaN(highlight.getValue())) return (Entry)entry; return null; } }
Example 3
Source File: CombinedChart.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch * point * inside the CombinedChart. * * @param x * @param y * @return */ @Override public Highlight getHighlightByTouchPoint(float x, float y) { if (mData == null) { Log.e(LOG_TAG, "Can't select by touch. No data set."); return null; } else { Highlight h = getHighlighter().getHighlight(x, y); if (h == null || !isHighlightFullBarEnabled()) { return h; } // For isHighlightFullBarEnabled, remove stackIndex return new Highlight(h.getX(), h.getY(), h.getXPx(), h.getYPx(), h.getDataSetIndex(), -1, h.getAxis()); } }
Example 4
Source File: BarChart.java From Ticket-Analysis with MIT License | 6 votes |
/** * Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch * point * inside the BarChart. * * @param x * @param y * @return */ @Override public Highlight getHighlightByTouchPoint(float x, float y) { if (mData == null) { Log.e(LOG_TAG, "Can't select by touch. No data set."); return null; } else { Highlight h = getHighlighter().getHighlight(x, y); if (h == null || !isHighlightFullBarEnabled()) return h; // For isHighlightFullBarEnabled, remove stackIndex return new Highlight(h.getX(), h.getY(), h.getXPx(), h.getYPx(), h.getDataSetIndex(), -1, h.getAxis()); } }
Example 5
Source File: CombinedChart.java From Ticket-Analysis with MIT License | 6 votes |
/** * Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch * point * inside the CombinedChart. * * @param x * @param y * @return */ @Override public Highlight getHighlightByTouchPoint(float x, float y) { if (mData == null) { Log.e(LOG_TAG, "Can't select by touch. No data set."); return null; } else { Highlight h = getHighlighter().getHighlight(x, y); if (h == null || !isHighlightFullBarEnabled()) return h; // For isHighlightFullBarEnabled, remove stackIndex return new Highlight(h.getX(), h.getY(), h.getXPx(), h.getYPx(), h.getDataSetIndex(), -1, h.getAxis()); } }
Example 6
Source File: CombinedData.java From Ticket-Analysis with MIT License | 6 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ @Override public Entry getEntryForHighlight(Highlight highlight) { if (highlight.getDataIndex() >= getAllData().size()) return null; ChartData data = getDataByIndex(highlight.getDataIndex()); if (highlight.getDataSetIndex() >= data.getDataSetCount()) return null; // The value of the highlighted entry could be NaN - // if we are not interested in highlighting a specific value. List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex()) .getEntriesForXValue(highlight.getX()); for (Entry entry : entries) if (entry.getY() == highlight.getY() || Float.isNaN(highlight.getY())) return entry; return null; }
Example 7
Source File: ChartData.java From Stayfit with Apache License 2.0 | 5 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { if (highlight.getDataSetIndex() >= mDataSets.size()) return null; else return mDataSets.get(highlight.getDataSetIndex()).getEntryForXIndex( highlight.getXIndex()); }
Example 8
Source File: CombinedData.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ @Override public Entry getEntryForHighlight(Highlight highlight) { List<ChartData> dataObjects = getAllData(); if (highlight.getDataIndex() >= dataObjects.size()) return null; ChartData data = dataObjects.get(highlight.getDataIndex()); if (highlight.getDataSetIndex() >= data.getDataSetCount()) return null; else { // The value of the highlighted entry could be NaN - // if we are not interested in highlighting a specific value. List<?> entries = data.getDataSetByIndex(highlight.getDataSetIndex()) .getEntriesForXIndex(highlight.getXIndex()); for (Object entry : entries) if (((Entry)entry).getVal() == highlight.getValue() || Float.isNaN(highlight.getValue())) return (Entry)entry; return null; } }
Example 9
Source File: ChartData.java From iMoney with Apache License 2.0 | 5 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { if (highlight.getDataSetIndex() >= mDataSets.size()) return null; else return mDataSets.get(highlight.getDataSetIndex()).getEntryForXIndex( highlight.getXIndex()); }
Example 10
Source File: ChartData.java From android-kline with Apache License 2.0 | 5 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { if (highlight.getDataSetIndex() >= mDataSets.size()) return null; else { return mDataSets.get(highlight.getDataSetIndex()).getEntryForXValue(highlight.getX(), highlight.getY()); } }
Example 11
Source File: CombinedData.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * Get dataset for highlight * * @param highlight current highlight * @return dataset related to highlight */ public IBarLineScatterCandleBubbleDataSet<? extends Entry> getDataSetByHighlight(Highlight highlight) { if (highlight.getDataIndex() >= getAllData().size()) { return null; } BarLineScatterCandleBubbleData data = getDataByIndex(highlight.getDataIndex()); if (highlight.getDataSetIndex() >= data.getDataSetCount()) { return null; } return (IBarLineScatterCandleBubbleDataSet<? extends Entry>) data.getDataSets().get(highlight.getDataSetIndex()); }
Example 12
Source File: CombinedData.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ @Override public Entry getEntryForHighlight(Highlight highlight) { if (highlight.getDataIndex() >= getAllData().size()) { return null; } ChartData data = getDataByIndex(highlight.getDataIndex()); if (highlight.getDataSetIndex() >= data.getDataSetCount()) { return null; } // The value of the highlighted entry could be NaN - // if we are not interested in highlighting a specific value. List<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex()) .getEntriesForXValue(highlight.getX()); for (Entry entry : entries) { if (entry.getY() == highlight.getY() || Float.isNaN(highlight.getY())) { return entry; } } return null; }
Example 13
Source File: ChartData.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * Get the Entry for a corresponding highlight object * * @param highlight * @return the entry that is highlighted */ public Entry getEntryForHighlight(Highlight highlight) { if (highlight.getDataSetIndex() >= mDataSets.size()) { return null; } else { return mDataSets.get(highlight.getDataSetIndex()).getEntryForXValue(highlight.getX(), highlight.getY()); } }
Example 14
Source File: LineChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { LineData lineData = mChart.getLineData(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? lineData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { ILineDataSet set = lineData.getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; int xIndex = high.getXIndex(); // get the // x-position if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX()) continue; final float yVal = set.getYValForXIndex(xIndex); if (Float.isNaN(yVal)) continue; float y = yVal * mAnimator.getPhaseY(); // get // the // y-position float[] pts = new float[]{ xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } } }
Example 15
Source File: CandleStickChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { CandleData candleData = mChart.getCandleData(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? candleData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { int xIndex = high.getXIndex(); // get the // x-position ICandleDataSet set = mChart.getCandleData().getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; CandleEntry e = set.getEntryForXIndex(xIndex); if (e == null || e.getXIndex() != xIndex) continue; float lowValue = e.getLow() * mAnimator.getPhaseY(); float highValue = e.getHigh() * mAnimator.getPhaseY(); float y = (lowValue + highValue) / 2f; float[] pts = new float[]{ xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } } }
Example 16
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 17
Source File: BubbleChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { BubbleData bubbleData = mChart.getBubbleData(); float phaseX = Math.max(0.f, Math.min(1.f, mAnimator.getPhaseX())); float phaseY = mAnimator.getPhaseY(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? bubbleData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { IBubbleDataSet dataSet = bubbleData.getDataSetByIndex(dataSetIndex); if (dataSet == null || !dataSet.isHighlightEnabled()) continue; final BubbleEntry entry = (BubbleEntry) bubbleData.getEntryForHighlight(high); if (entry == null || entry.getXIndex() != high.getXIndex()) continue; BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX); BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX); int minx = dataSet.getEntryIndex(entryFrom); int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount()); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); sizeBuffer[0] = 0f; sizeBuffer[2] = 1f; trans.pointValuesToPixel(sizeBuffer); boolean normalizeSize = dataSet.isNormalizeSizeEnabled(); // calcualte the full width of 1 step on the x-axis final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]); final float maxBubbleHeight = Math.abs( mViewPortHandler.contentBottom() - mViewPortHandler.contentTop()); final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth); pointBuffer[0] = (float) (entry.getXIndex() - minx) * phaseX + (float) minx; pointBuffer[1] = (float) (entry.getVal()) * phaseY; trans.pointValuesToPixel(pointBuffer); float shapeHalf = getShapeSize(entry.getSize(), dataSet.getMaxSize(), referenceSize, normalizeSize) / 2f; if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf) || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf)) continue; if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf)) continue; if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf)) break; if (high.getXIndex() < minx || high.getXIndex() >= maxx) continue; final int originalColor = dataSet.getColor(entry.getXIndex()); Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor), Color.blue(originalColor), _hsvBuffer); _hsvBuffer[2] *= 0.5f; final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer); mHighlightPaint.setColor(color); mHighlightPaint.setStrokeWidth(dataSet.getHighlightCircleWidth()); c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint); } } }
Example 18
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 19
Source File: Chart.java From iMoney with Apache License 2.0 | 4 votes |
/** * draws all MarkerViews on the highlighted positions */ protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHightlight.length; i++) { Highlight highlight = mIndicesToHightlight[i]; int xIndex = highlight.getXIndex(); int dataSetIndex = highlight.getDataSetIndex(); if (xIndex <= mDeltaX && xIndex <= mDeltaX * mAnimator.getPhaseX()) { Entry e = mData.getEntryForHighlight(mIndicesToHightlight[i]); // make sure entry not null if (e == null || e.getXIndex() != mIndicesToHightlight[i].getXIndex()) continue; float[] pos = getMarkerPosition(e, highlight); // check bounds if (!mViewPortHandler.isInBounds(pos[0], pos[1])) continue; // callbacks to update the content mMarkerView.refreshContent(e, highlight); // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, // MeasureSpec.UNSPECIFIED), // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), // mMarkerView.getMeasuredHeight()); // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]); mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), mMarkerView.getMeasuredHeight()); if (pos[1] - mMarkerView.getHeight() <= 0) { float y = mMarkerView.getHeight() - pos[1]; mMarkerView.draw(canvas, pos[0], pos[1] + y); } else { mMarkerView.draw(canvas, pos[0], pos[1]); } } } }
Example 20
Source File: Chart.java From NetKnight with Apache License 2.0 | 4 votes |
/** * draws all MarkerViews on the highlighted positions */ protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled if (mMarkerView == null || !mDrawMarkerViews || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHighlight.length; i++) { Highlight highlight = mIndicesToHighlight[i]; int xIndex = highlight.getXIndex(); int dataSetIndex = highlight.getDataSetIndex(); float deltaX = mXAxis != null ? mXAxis.mAxisRange : ((mData == null ? 0.f : mData.getXValCount()) - 1.f); if (xIndex <= deltaX && xIndex <= deltaX * mAnimator.getPhaseX()) { Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]); // make sure entry not null if (e == null || e.getXIndex() != mIndicesToHighlight[i].getXIndex()) continue; float[] pos = getMarkerPosition(e, highlight); // check bounds if (!mViewPortHandler.isInBounds(pos[0], pos[1])) continue; // callbacks to update the content mMarkerView.refreshContent(e, highlight); // mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, // MeasureSpec.UNSPECIFIED), // MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); // mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), // mMarkerView.getMeasuredHeight()); // mMarkerView.draw(mDrawCanvas, pos[0], pos[1]); mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(), mMarkerView.getMeasuredHeight()); if (pos[1] - mMarkerView.getHeight() <= 0) { float y = mMarkerView.getHeight() - pos[1]; mMarkerView.draw(canvas, pos[0], pos[1] + y); } else { mMarkerView.draw(canvas, pos[0], pos[1]); } } } }