Java Code Examples for com.github.mikephil.charting.data.DataSet#Rounding

The following examples show how to use com.github.mikephil.charting.data.DataSet#Rounding . 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: RealmBaseDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 5 votes vote down vote up
@Override
public S getEntryForXValue(float xValue, float closestToY, DataSet.Rounding rounding) {

    int index = getEntryIndex(xValue, closestToY, rounding);
    if (index > -1)
        return mValues.get(index);
    return null;
}
 
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: RealmBaseDataSet.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public S getEntryForXIndex(int xIndex, DataSet.Rounding rounding) {
    int index = getEntryIndex(xIndex, rounding);
    if (index > -1)
        return mValues.get(index);
    return null;
}
 
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: RealmBaseDataSet.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public S getEntryForXIndex(int xIndex, DataSet.Rounding rounding) {
    int index = getEntryIndex(xIndex, rounding);
    if (index > -1)
        return mValues.get(index);
    return null;
}
 
Example 10
Source File: RealmBaseDataSet.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public int getEntryIndex(int x, DataSet.Rounding rounding) {

    int low = 0;
    int high = mValues.size() - 1;
    int closest = -1;

    while (low <= high) {
        int m = (high + low) / 2;

        if (x == mValues.get(m).getXIndex()) {
            while (m > 0 && mValues.get(m - 1).getXIndex() == x)
                m--;

            return m;
        }

        if (x > mValues.get(m).getXIndex())
            low = m + 1;
        else
            high = m - 1;

        closest = m;
    }

    if (closest != -1) {
        int closestXIndex = mValues.get(closest).getXIndex();
        if (rounding == DataSet.Rounding.UP) {
            if (closestXIndex < x && closest < mValues.size() - 1) {
                ++closest;
            }
        } else if (rounding == DataSet.Rounding.DOWN) {
            if (closestXIndex > x && closest > 0) {
                --closest;
            }
        }
    }

    return closest;
}
 
Example 11
Source File: IDataSet.java    From NetKnight with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the first Entry index found at the given xIndex with binary
 * search. If the no Entry at the specified x-index is found, this method
 * returns the index at the closest x-index. Returns -1 if no Entry object
 * at that index. INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xIndex
 * @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index
 * @return
 */
int getEntryIndex(int xIndex, DataSet.Rounding rounding);
 
Example 12
Source File: IDataSet.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
/**
 * Returns the first Entry object found at the given x-value with binary
 * search.
 * If the no Entry at the specified x-value is found, this method
 * returns the Entry at the closest x-value according to the rounding.
 * INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xValue     the x-value
 * @param closestToY If there are multiple y-values for the specified x-value,
 * @param rounding   determine whether to round up/down/closest
 *                   if there is no Entry matching the provided x-value
 * @return
 */
T getEntryForXValue(float xValue, float closestToY, DataSet.Rounding rounding);
 
Example 13
Source File: IDataSet.java    From NetKnight with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the first Entry object found at the given xIndex with binary
 * search. If the no Entry at the specified x-index is found, this method
 * returns the index at the closest x-index. Returns null if no Entry object
 * at that index. INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xIndex
 * @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index
 * @return
 */
T getEntryForXIndex(int xIndex, DataSet.Rounding rounding);
 
Example 14
Source File: IDataSet.java    From Stayfit with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the first Entry index found at the given xIndex with binary
 * search. If the no Entry at the specified x-index is found, this method
 * returns the index at the closest x-index. Returns -1 if no Entry object
 * at that index. INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xIndex
 * @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index
 * @return
 */
int getEntryIndex(int xIndex, DataSet.Rounding rounding);
 
Example 15
Source File: IDataSet.java    From Stayfit with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the first Entry object found at the given xIndex with binary
 * search. If the no Entry at the specified x-index is found, this method
 * returns the index at the closest x-index. Returns null if no Entry object
 * at that index. INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xIndex
 * @param rounding determine to round up/down/closest if there is no Entry matching the provided x-index
 * @return
 */
T getEntryForXIndex(int xIndex, DataSet.Rounding rounding);
 
Example 16
Source File: IDataSet.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the first Entry index found at the given x-value with binary
 * search.
 * If the no Entry at the specified x-value is found, this method
 * returns the Entry at the closest x-value according to the rounding.
 * INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xValue the x-value
 * @param closestToY If there are multiple y-values for the specified x-value,
 * @param rounding determine whether to round up/down/closest
 *                 if there is no Entry matching the provided x-value
 * @return
 */
int getEntryIndex(float xValue, float closestToY, DataSet.Rounding rounding);
 
Example 17
Source File: IDataSet.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the first Entry object found at the given x-value with binary
 * search.
 * If the no Entry at the specified x-value is found, this method
 * returns the Entry at the closest x-value according to the rounding.
 * INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xValue the x-value
 * @param closestToY If there are multiple y-values for the specified x-value,
 * @param rounding determine whether to round up/down/closest
 *                 if there is no Entry matching the provided x-value
 * @return
 *
 *
 */
T getEntryForXValue(float xValue, float closestToY, DataSet.Rounding rounding);
 
Example 18
Source File: IDataSet.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Returns the first Entry index found at the given x-value with binary
 * search.
 * If the no Entry at the specified x-value is found, this method
 * returns the Entry at the closest x-value according to the rounding.
 * INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xValue the x-value
 * @param closestToY If there are multiple y-values for the specified x-value,
 * @param rounding determine whether to round up/down/closest
 *                 if there is no Entry matching the provided x-value
 * @return
 */
int getEntryIndex(float xValue, float closestToY, DataSet.Rounding rounding);
 
Example 19
Source File: IDataSet.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Returns the first Entry object found at the given x-value with binary
 * search.
 * If the no Entry at the specified x-value is found, this method
 * returns the Entry at the closest x-value according to the rounding.
 * INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xValue the x-value
 * @param closestToY If there are multiple y-values for the specified x-value,
 * @param rounding determine whether to round up/down/closest
 *                 if there is no Entry matching the provided x-value
 * @return
 *
 *
 */
T getEntryForXValue(float xValue, float closestToY, DataSet.Rounding rounding);
 
Example 20
Source File: IDataSet.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
/**
 * Returns the first Entry index found at the given x-value with binary
 * search.
 * If the no Entry at the specified x-value is found, this method
 * returns the Entry at the closest x-value according to the rounding.
 * INFORMATION: This method does calculations at runtime. Do
 * not over-use in performance critical situations.
 *
 * @param xValue     the x-value
 * @param closestToY If there are multiple y-values for the specified x-value,
 * @param rounding   determine whether to round up/down/closest
 *                   if there is no Entry matching the provided x-value
 * @return
 */
int getEntryIndex(float xValue, float closestToY, DataSet.Rounding rounding);