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

The following examples show how to use com.github.mikephil.charting.interfaces.datasets.IDataSet#getYValForXIndex() . 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: BarHighlighter.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
@Override
protected SelectionDetail getSelectionDetail(int xIndex, float y, int dataSetIndex) {

	dataSetIndex = Math.max(dataSetIndex, 0);

	BarData barData = mChart.getBarData();
	IDataSet dataSet = barData.getDataSetCount() > dataSetIndex
			? barData.getDataSetByIndex(dataSetIndex)
			: null;
	if (dataSet == null)
		return null;

	final float yValue = dataSet.getYValForXIndex(xIndex);

	if (yValue == Double.NaN) return null;

	return new SelectionDetail(
			yValue,
			dataSetIndex,
			dataSet);
}
 
Example 2
Source File: PieRadarChartBase.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail
 * objects give information about the value at the selected index and the
 * DataSet it belongs to. INFORMATION: This method does calculations at
 * runtime. Do not over-use in performance critical situations.
 *
 * @return
 */
public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) {

    List<SelectionDetail> vals = new ArrayList<SelectionDetail>();

    for (int i = 0; i < mData.getDataSetCount(); i++) {

        IDataSet<?> dataSet = mData.getDataSetByIndex(i);

        // extract all y-values from all DataSets at the given x-index
        final float yVal = dataSet.getYValForXIndex(xIndex);
        if (yVal == Float.NaN)
            continue;

        vals.add(new SelectionDetail(yVal, i, dataSet));
    }

    return vals;
}
 
Example 3
Source File: PieRadarChartBase.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an array of SelectionDetail objects for the given x-index. The SelectionDetail
 * objects give information about the value at the selected index and the
 * DataSet it belongs to. INFORMATION: This method does calculations at
 * runtime. Do not over-use in performance critical situations.
 *
 * @return
 */
public List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) {

    List<SelectionDetail> vals = new ArrayList<SelectionDetail>();

    for (int i = 0; i < mData.getDataSetCount(); i++) {

        IDataSet<?> dataSet = mData.getDataSetByIndex(i);

        // extract all y-values from all DataSets at the given x-index
        final float yVal = dataSet.getYValForXIndex(xIndex);
        if (Float.isNaN(yVal))
            continue;

        vals.add(new SelectionDetail(yVal, i, dataSet));
    }

    return vals;
}
 
Example 4
Source File: CombinedHighlighter.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a list of SelectionDetail object corresponding to the given xIndex.
 *
 * @param xIndex
 * @return
 */
@Override
protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) {

    CombinedData data = (CombinedData) mChart.getData();

    // get all chartdata objects
    List<ChartData> dataObjects = data.getAllData();

    List<SelectionDetail> vals = new ArrayList<SelectionDetail>();

    float[] pts = new float[2];

    for (int i = 0; i < dataObjects.size(); i++) {

        for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) {

            IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j);

            // dont include datasets that cannot be highlighted
            if (!dataSet.isHighlightEnabled())
                continue;

            // extract all y-values from all DataSets at the given x-index
            final float yVal = dataSet.getYValForXIndex(xIndex);
            if (yVal == Float.NaN)
                continue;

            pts[1] = yVal;

            mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);

            if (!Float.isNaN(pts[1])) {
                vals.add(new SelectionDetail(pts[1], j, dataSet));
            }
        }
    }

    return vals;
}
 
Example 5
Source File: ChartHighlighter.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a list of SelectionDetail object corresponding to the given xIndex.
 * 
 * @param xIndex
 * @return
 */
protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex) {

	List<SelectionDetail> vals = new ArrayList<SelectionDetail>();

	float[] pts = new float[2];

	for (int i = 0; i < mChart.getData().getDataSetCount(); i++) {

		IDataSet dataSet = mChart.getData().getDataSetByIndex(i);

		// dont include datasets that cannot be highlighted
		if (!dataSet.isHighlightEnabled())
			continue;

		// extract all y-values from all DataSets at the given x-index
		final float yVal = dataSet.getYValForXIndex(xIndex);
		if (yVal == Float.NaN)
			continue;

		pts[1] = yVal;

		mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);

		if (!Float.isNaN(pts[1])) {
			vals.add(new SelectionDetail(pts[1], i, dataSet));
		}
	}

	return vals;
}