当前位置: 首页>>代码示例>>Java>>正文


Java Utils.getClosestDataSetIndex方法代码示例

本文整理汇总了Java中com.github.mikephil.charting.utils.Utils.getClosestDataSetIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.getClosestDataSetIndex方法的具体用法?Java Utils.getClosestDataSetIndex怎么用?Java Utils.getClosestDataSetIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.mikephil.charting.utils.Utils的用法示例。


在下文中一共展示了Utils.getClosestDataSetIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSingleTapUp

import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
@Override
public boolean onSingleTapUp(MotionEvent e) {

    mLastGesture = ChartGesture.SINGLE_TAP;

    OnChartGestureListener l = mChart.getOnChartGestureListener();

    if (l != null) {
        l.onChartSingleTapped(e);
    }

    if(!mChart.isHighlightPerTapEnabled()) {
        return false;
    }

    float distance = mChart.distanceToCenter(e.getX(), e.getY());

    // check if a slice was touched
    if (distance > mChart.getRadius()) {

        // if no slice was touched, highlight nothing

        if (mLastHighlighted == null)
            mChart.highlightValues(null); // no listener callback
        else
            mChart.highlightTouch(null); // listener callback

        mLastHighlighted = null;

    } else {

        float angle = mChart.getAngleForPoint(e.getX(), e.getY());

        if (mChart instanceof PieChart) {
            angle /= mChart.getAnimator().getPhaseY();
        }

        int index = mChart.getIndexForAngle(angle);

        // check if the index could be found
        if (index < 0) {

            mChart.highlightValues(null);
            mLastHighlighted = null;

        } else {

            List<SelectionDetail> valsAtIndex = mChart.getSelectionDetailsAtIndex(index);

            int dataSetIndex = 0;

            // get the dataset that is closest to the selection (PieChart
            // only
            // has one DataSet)
            if (mChart instanceof RadarChart) {

                dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, distance
                        / ((RadarChart) mChart).getFactor(), null);
            }

            if (dataSetIndex < 0) {
                mChart.highlightValues(null);
                mLastHighlighted = null;
            } else {
                Highlight h = new Highlight(index, dataSetIndex);
                performHighlight(h, e);
            }
        }
    }

    return true;
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:73,代码来源:PieRadarChartTouchListener.java

示例2: onSingleTapUp

import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
@Override
public boolean onSingleTapUp(MotionEvent e) {

    OnChartGestureListener l = mChart.getOnChartGestureListener();

    if (l != null) {
        l.onChartSingleTapped(e);
    }

    float distance = mChart.distanceToCenter(e.getX(), e.getY());

    // check if a slice was touched
    if (distance > mChart.getRadius()) {

        // if no slice was touched, highlight nothing
        mChart.highlightValues(null);
        mLastHighlighted = null;

    } else {

        float angle = mChart.getAngleForPoint(e.getX(), e.getY());

        if (mChart instanceof PieChart) {
            angle /= mChart.getAnimator().getPhaseY();
        }

        int index = mChart.getIndexForAngle(angle);

        // check if the index could be found
        if (index < 0) {

            mChart.highlightValues(null);
            mLastHighlighted = null;

        } else {

            List<SelectionDetail> valsAtIndex = mChart.getSelectionDetailsAtIndex(index);

            int dataSetIndex = 0;

            // get the dataset that is closest to the selection (PieChart
            // only
            // has one DataSet)
            if (mChart instanceof RadarChart) {

                dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, distance
                        / ((RadarChart) mChart).getFactor(), null);
            }

            if (dataSetIndex < 0) {
                mChart.highlightValues(null);
                mLastHighlighted = null;
            } else {
                Highlight h = new Highlight(index, dataSetIndex);

                if (h.equalTo(mLastHighlighted)) {

                    mChart.highlightTouch(null);
                    mLastHighlighted = null;
                } else {

                    mChart.highlightTouch(h);
                    mLastHighlighted = h;
                }
            }
        }
    }

    return true;
}
 
开发者ID:xinpengfei520,项目名称:P2P,代码行数:71,代码来源:PieRadarChartTouchListener.java

示例3: getDataSetIndex

import com.github.mikephil.charting.utils.Utils; //导入方法依赖的package包/类
/**
 * Returns the corresponding dataset-index for a given xIndex and xy-touch position in pixels.
 * 
 * @param xIndex
 * @param x
 * @param y
 * @return
 */
protected int getDataSetIndex(int xIndex, float x, float y) {

	List<SelectionDetail> valsAtIndex = getSelectionDetailsAtIndex(xIndex);

	float leftdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.LEFT);
	float rightdist = Utils.getMinimumDistance(valsAtIndex, y, YAxis.AxisDependency.RIGHT);

	YAxis.AxisDependency axis = leftdist < rightdist ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT;

	int dataSetIndex = Utils.getClosestDataSetIndex(valsAtIndex, y, axis);

	return dataSetIndex;
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:22,代码来源:ChartHighlighter.java


注:本文中的com.github.mikephil.charting.utils.Utils.getClosestDataSetIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。