如何在graphview中获取坐标值?

时间:2014-09-16 07:26:51

标签: android android-graphview

我正在使用

GraphViewSeries g1 = new GraphViewSeries("",
    new GraphViewSeriesStyle(Color.WHITE, 1/3),new GraphViewData[] {
            new GraphViewData(-5,0d),
            new GraphViewData(5,0d),

    });

GraphViewSeries g2 = new GraphViewSeries("",
    new GraphViewSeriesStyle(Color.WHITE, 1/3),new GraphViewData[] {
            new GraphViewData(0,-5d),
            new GraphViewData(0,5d),

    });

GraphViewSeries g3 = new GraphViewSeries("",
    new GraphViewSeriesStyle(Color.WHITE, 1/3),new GraphViewData[] {
            new GraphViewData(-5,-5d),
            new GraphViewData(5,-5d),

    });

    graphView.getGraphViewStyle().setNumVerticalLabels(11);
    graphView.getGraphViewStyle().setNumHorizontalLabels(11);
    graphView.setManualYAxisBounds(5, -5);
    graphView.setViewPort(-5,10); 



    int screenX = (int)event.getX();
    int screenY =(int) event.getY();

我为horizontal and vertical设置了标签11 ..使用此getX()GetY()方法,我得到的值为414,403等等。它显示了超出i&#39的值; m提到的值我怎么能得到x,y值,如1,0和-1,3等..这意味着我给了GraphViewData ..

1 个答案:

答案 0 :(得分:0)

如需设置y轴,可以

graphView.setManualYAxisBounds(5, -5); // min=-5, max=5
graphView.getGraphViewStyle().setNumVerticalLabels(11); // will have 11 y axis lables

上面的代码将使y轴的值为-5,-4,-3,......,4,5。(它们将始终保持这样)。

和x轴使用

setViewPort(-5, 1); // start position=-5, size=1

以上代码启动将使x轴从-5开始,大小为1。