简体   繁体   English

GraphView更改x和y轴范围

[英]GraphView change x and y axis ranges

I have a line graph that I add data to each time the user enters a number. 我有一个线图,我每次用户输入数字时都会添加数据。 The user enters a number 50 times, so I want the x axis to range from 1 to 50 in increments of 1. On the y axis, I want it to range from 2 - 15 (user enters a number between 2 and 15) in increments of 1. I'm really not sure how to do this, this is what I have: 用户输入一个数字50次,所以我希望x轴的范围从1到50,增量为1.在y轴上,我希望它的范围是2 - 15(用户输入2到15之间的数字)增量为1.我真的不确定如何做到这一点,这就是我所拥有的:

    graph = (GraphView) findViewById(R.id.session_graph);
    series = new LineGraphSeries<DataPoint>(new DataPoint[] {});
    graph.addSeries(series);

    graph.getViewport().setMinX(1);
    graph.getViewport().setMaxX(50);
    graph.getViewport().setMinY(2.0);
    graph.getViewport().setMaxY(15.0);

However, when I fire up my app, the x and y axis range from 0 - 2 in intervals of 0.5 但是,当我启动我的应用程序时,x和y轴的范围为0 - 2,间隔为0.5

GraphView sets the axis range by default. GraphView默认设置轴范围。 What you wish to do is set the limits manually. 您要做的是手动设置限制。 After setting the ranges, you must tell the graphView to set the range as per your directive. 设置范围后,您必须告诉graphView根据您的指令设置范围。 This is how: 这是如何:

graph = (GraphView) findViewById(R.id.session_graph);
series = new LineGraphSeries<DataPoint>(new DataPoint[] {});
graph.addSeries(series);

graph.getViewport().setMinX(1);
graph.getViewport().setMaxX(50);
graph.getViewport().setMinY(2.0);
graph.getViewport().setMaxY(15.0);

graph.getViewport().setYAxisBoundsManual(true);
graph.getViewport().setXAxisBoundsManual(true);

Hope this helps and the answer is not too late :) 希望这会有所帮助,答案也不会太晚:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM