Java Code Examples for com.github.mikephil.charting.highlight.Highlight#getDataIndex()

The following examples show how to use com.github.mikephil.charting.highlight.Highlight#getDataIndex() . 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 vote down vote up
/**
 * 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: CombinedChartCurrentDay.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 3
Source File: CombinedData.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * 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 4
Source File: CombinedData.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 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 5
Source File: CombinedData.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * 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 6
Source File: CombinedChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    Chart chart = mChart.get();
    if (chart == null) {
        return;
    }

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer) {
            data = ((BarChartRenderer) renderer).mChart.getBarData();
        } else if (renderer instanceof LineChartRenderer) {
            data = ((LineChartRenderer) renderer).mChart.getLineData();
        } else if (renderer instanceof CandleStickChartRenderer) {
            data = ((CandleStickChartRenderer) renderer).mChart.getCandleData();
        } else if (renderer instanceof ScatterChartRenderer) {
            data = ((ScatterChartRenderer) renderer).mChart.getScatterData();
        } else if (renderer instanceof BubbleChartRenderer) {
            data = ((BubbleChartRenderer) renderer).mChart.getBubbleData();
        }

        int dataIndex = data == null ? -1
                : ((CombinedData) chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) {
                mHighlightBuffer.add(h);
            }
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
Example 7
Source File: CombinedData.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * 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 8
Source File: CombinedChartRenderer.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof LineChartRenderer)
            data = ((LineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                mHighlightBuffer.add(h);
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
Example 9
Source File: CombinedData.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Get the Entry for a corresponding highlight object
 *
 * @param highlight
 * @return the entry that is highlighted
 */
@Override
public Entry getEntryForHighlight(Highlight highlight) {

    List<BarLineScatterCandleBubbleData> 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<Entry> entries = data.getDataSetByIndex(highlight.getDataSetIndex())
                .getEntriesForXValue(highlight.getX());
        for (Entry entry : entries) {

            boolean b1 = entry.getY() == highlight.getY();
            boolean b2 = Float.isNaN(highlight.getY());

            if (b1 ||
                    b2)
                return entry;
        }

        return null;
    }
}
 
Example 10
Source File: CombinedChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof LineChartRenderer)
            data = ((LineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                mHighlightBuffer.add(h);
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
Example 11
Source File: AppCombinedChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof AppLineChartRenderer)
            data = ((AppLineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                mHighlightBuffer.add(h);
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
Example 12
Source File: CombinedData.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
/**
 * 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 13
Source File: CombinedChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof LineChartRenderer)
            data = ((LineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null
                ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        ArrayList<Highlight> dataIndices = new ArrayList<>();
        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                dataIndices.add(h);
        }

        renderer.drawHighlighted(c, dataIndices.toArray(new Highlight[dataIndices.size()]));

    }
}