aChartEngine: getting coordinates of any point on the graph area

风流意气都作罢 提交于 2019-12-14 02:42:51

问题


I am using achartengine to display line graphs.And i am stuck at trying to get the coordinates of a point on touch (not the coordinates on the line graph but anywhere in the graph area). so i think getSeriesAndPointForScreenCoordinate(...) wont help in this case.

Any suggestions?


回答1:


try using this code :

myXYPlot.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

            switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                displaycoordinates(event);
                break;

            case MotionEvent.ACTION_DOWN:
                displaycoordinates(event); 
                break;                  
            default:
                break;
            }
            return true;
        }           
    });              
}

where displaycoordinates() is defined below:

public void displaycoordinates(MotionEvent event) {
    // TODO Auto-generated method stub

    float x = event.getX();
    float y = event.getY();

    PointF point = new PointF(x,y);

    NumberFormat nf = new DecimalFormat("#0.00");

    Double j = getXval(x);
    String xval = nf.format(j);

    Double k = getYval(y);
    String yval = nf.format(x);

    if(j>=condition1 && k>=condition2 && j<=condition3 && k<=condition4)
    {
        toast = Toast.makeText(getApplicationContext(), xval+"xval"+yval+" yval", 0);
        toast.show();
    }

}



回答2:


If you have the screen coordinates point then you can just call chartView.toRealPoint() in order to get the real data coordinate values.



来源:https://stackoverflow.com/questions/16566962/achartengine-getting-coordinates-of-any-point-on-the-graph-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!