Java Code Examples for com.github.mikephil.charting.interfaces.datasets.IDataSet#getEntryForXValue()

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.IDataSet#getEntryForXValue() . 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: ChartHighlighter.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex.
 *
 * @param set
 * @param dataSetIndex
 * @param xVal
 * @param rounding
 * @return
 */
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

    ArrayList<Highlight> highlights = new ArrayList<>();

    //noinspection unchecked
    List<Entry> entries = set.getEntriesForXValue(xVal);
    if (entries.size() == 0) {
        // Try to find closest x-value and take all entries for that x-value
        final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
        if (closest != null) {
            //noinspection unchecked
            entries = set.getEntriesForXValue(closest.getX());
        }
    }

    if (entries.size() == 0) {
        return highlights;
    }

    for (Entry e : entries) {
        MPPointD pixels = mChart.getTransformer(
                set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());

        highlights.add(new Highlight(
                e.getX(), e.getY(),
                (float) pixels.x, (float) pixels.y,
                dataSetIndex, set.getAxisDependency()));
    }

    return highlights;
}
 
Example 2
Source File: HorizontalBarHighlighter.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

    ArrayList<Highlight> highlights = new ArrayList<>();

    //noinspection unchecked
    List<Entry> entries = set.getEntriesForXValue(xVal);
    if (entries.size() == 0) {
        // Try to find closest x-value and take all entries for that x-value
        final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
        if (closest != null) {
            //noinspection unchecked
            entries = set.getEntriesForXValue(closest.getX());
        }
    }

    if (entries.size() == 0) {
        return highlights;
    }

    for (Entry e : entries) {
        MPPointD pixels = mChart.getTransformer(
                set.getAxisDependency()).getPixelForValues(e.getY(), e.getX());

        highlights.add(new Highlight(
                e.getX(), e.getY(),
                (float) pixels.x, (float) pixels.y,
                dataSetIndex, set.getAxisDependency()));
    }

    return highlights;
}
 
Example 3
Source File: ChartData.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Removes the Entry object closest to the given DataSet at the
 * specified index. Returns true if an Entry was removed, false if no Entry
 * was found that meets the specified requirements.
 *
 * @param xValue
 * @param dataSetIndex
 * @return
 */
public boolean removeEntry(float xValue, int dataSetIndex) {

    if (dataSetIndex >= mDataSets.size())
        return false;

    IDataSet dataSet = mDataSets.get(dataSetIndex);
    Entry e = dataSet.getEntryForXValue(xValue, Float.NaN);

    if (e == null)
        return false;

    return removeEntry(e, dataSetIndex);
}
 
Example 4
Source File: ChartHighlighter.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex.
 *
 * @param set
 * @param dataSetIndex
 * @param xVal
 * @param rounding
 * @return
 */
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

    ArrayList<Highlight> highlights = new ArrayList<>();

    //noinspection unchecked
    List<Entry> entries = set.getEntriesForXValue(xVal);
    if (entries.size() == 0) {
        // Try to find closest x-value and take all entries for that x-value
        final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
        if (closest != null)
        {
            //noinspection unchecked
            entries = set.getEntriesForXValue(closest.getX());
        }
    }

    if (entries.size() == 0)
        return highlights;

    for (Entry e : entries) {
        MPPointD pixels = mChart.getTransformer(
                set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());

        highlights.add(new Highlight(
                e.getX(), e.getY(),
                (float) pixels.x, (float) pixels.y,
                dataSetIndex, set.getAxisDependency()));
    }

    return highlights;
}
 
Example 5
Source File: HorizontalBarHighlighter.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

	ArrayList<Highlight> highlights = new ArrayList<>();

	//noinspection unchecked
	List<Entry> entries = set.getEntriesForXValue(xVal);
	if (entries.size() == 0) {
		// Try to find closest x-value and take all entries for that x-value
		final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
		if (closest != null)
		{
			//noinspection unchecked
			entries = set.getEntriesForXValue(closest.getX());
		}
	}

	if (entries.size() == 0)
		return highlights;

	for (Entry e : entries) {
		MPPointD pixels = mChart.getTransformer(
				set.getAxisDependency()).getPixelForValues(e.getY(), e.getX());

		highlights.add(new Highlight(
				e.getX(), e.getY(),
				(float) pixels.x, (float) pixels.y,
				dataSetIndex, set.getAxisDependency()));
	}

	return highlights;
}
 
Example 6
Source File: ChartData.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the Entry object closest to the given DataSet at the
 * specified index. Returns true if an Entry was removed, false if no Entry
 * was found that meets the specified requirements.
 *
 * @param xValue
 * @param dataSetIndex
 * @return
 */
public boolean removeEntry(float xValue, int dataSetIndex) {

    if (dataSetIndex >= mDataSets.size())
        return false;

    IDataSet dataSet = mDataSets.get(dataSetIndex);
    Entry e = dataSet.getEntryForXValue(xValue, Float.NaN);

    if (e == null)
        return false;

    return removeEntry(e, dataSetIndex);
}
 
Example 7
Source File: ChartHighlighter.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex.
 *
 * @param set
 * @param dataSetIndex
 * @param xVal
 * @param rounding
 * @return
 */
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

    ArrayList<Highlight> highlights = new ArrayList<>();

    //noinspection unchecked
    List<Entry> entries = set.getEntriesForXValue(xVal);
    if (entries.size() == 0) {
        // Try to find closest x-value and take all entries for that x-value
        final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
        if (closest != null)
        {
            //noinspection unchecked
            entries = set.getEntriesForXValue(closest.getX());
        }
    }

    if (entries.size() == 0)
        return highlights;

    for (Entry e : entries) {
        MPPointD pixels = mChart.getTransformer(
                set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());

        highlights.add(new Highlight(
                e.getX(), e.getY(),
                (float) pixels.x, (float) pixels.y,
                dataSetIndex, set.getAxisDependency()));
    }

    return highlights;
}
 
Example 8
Source File: HorizontalBarHighlighter.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

	ArrayList<Highlight> highlights = new ArrayList<>();

	//noinspection unchecked
	List<Entry> entries = set.getEntriesForXValue(xVal);
	if (entries.size() == 0) {
		// Try to find closest x-value and take all entries for that x-value
		final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
		if (closest != null)
		{
			//noinspection unchecked
			entries = set.getEntriesForXValue(closest.getX());
		}
	}

	if (entries.size() == 0)
		return highlights;

	for (Entry e : entries) {
		MPPointD pixels = mChart.getTransformer(
				set.getAxisDependency()).getPixelForValues(e.getY(), e.getX());

		highlights.add(new Highlight(
				e.getX(), e.getY(),
				(float) pixels.x, (float) pixels.y,
				dataSetIndex, set.getAxisDependency()));
	}

	return highlights;
}
 
Example 9
Source File: ChartData.java    From StockChart-MPAndroidChart with MIT License 3 votes vote down vote up
/**
 * Removes the Entry object closest to the given DataSet at the
 * specified index. Returns true if an Entry was removed, false if no Entry
 * was found that meets the specified requirements.
 *
 * @param xValue
 * @param dataSetIndex
 * @return
 */
public boolean removeEntry(float xValue, int dataSetIndex) {

    if (dataSetIndex >= mDataSets.size()) {
        return false;
    }

    IDataSet dataSet = mDataSets.get(dataSetIndex);
    Entry e = dataSet.getEntryForXValue(xValue, Float.NaN);

    return e != null && removeEntry(e, dataSetIndex);

}