java – GraphView垂直标签从0开始以整数递增
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – GraphView垂直标签从0开始以整数递增,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2218字,纯文字阅读大概需要4分钟。
内容图文
![java – GraphView垂直标签从0开始以整数递增](/upload/InfoBanner/zyjiaocheng/756/a6c7fb7f19c843219df838f8e738afef.jpg)
目前,下面的代码显示附加的条形图,其中包含小数位数,从2开始.
我的问题是:有没有办法从0开始y轴标签,并将整数增加到数据的最大值?例如,在这,0,1,2,3,4,5?
barData = this.getIntent().getExtras().getString("GraphData");
GraphViewSeries barGraphSeries = new GraphViewSeries(
new GraphViewData[] {
new GraphViewData(0, Integer.parseInt(barData
.substring(0, barData.indexOf(",")))),
new GraphViewData(1, Integer.parseInt(barData
.substring(barData.indexOf(",") + 1,
barData.length()))) });
GraphView statGraphView = new BarGraphView(this,
"Current Stat Graph");
statGraphView.getGraphViewStyle().setGridColor(Color.BLACK);
statGraphView.getGraphViewStyle().setHorizontalLabelsColor(
Color.BLACK);
statGraphView.getGraphViewStyle().setVerticalLabelsColor(
Color.BLACK);
String[] horLabels = { "Correct", "Incorrect" };
statGraphView.setHorizontalLabels(horLabels);
statGraphView.getGraphViewStyle().setNumHorizontalLabels(2);
statGraphView.getGraphViewStyle().setNumVerticalLabels(10);
statGraphView.addSeries(barGraphSeries);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(statGraphView);
解决方法:
首先要知道的是,如果让GraphView管理Y标度,它将显示10个间隔,即11个值.
因此,如果您具有0到10或0到20之间的值,则显示的值将为整数.
您可以使用GraphView.setManualYAxisBounds手动设置垂直边界(double max,double min)
在这种情况下,您可能希望使用setManualYAxisBounds(5,0),但不会显示整数.
所以你必须使用getGraphViewStyle().setNumVerticalLabels(6)
这是我用来动态调整比例的代码,从0到200的值,最大比例值尽可能接近我的数据的最大值(我希望我可以理解,哈哈)
int maxValue = ... // here, you find your max value
// search the interval between 2 vertical labels
int interval;
if (maxValue <= 55) {
interval = 5; // increment of 5 between each label
} else if (maxValue <= 110) {
interval = 10; // increment of 10 between each label
} else {
interval = 20; // increment of 20 between each label
}
// search the top value of your graph, it must be a multiplier of your interval
int maxLabel = maxValue;
while (maxLabel % interval != 0) {
maxLabel++;
}
// set manual bounds
setManualYAxisBounds(maxLabel, 0);
// indicate number of vertical labels
getGraphViewStyle().setNumVerticalLabels(maxLabel / interval + 1);
// now, it's ok, you should have a graph with integer labels
内容总结
以上是互联网集市为您收集整理的java – GraphView垂直标签从0开始以整数递增全部内容,希望文章能够帮你解决java – GraphView垂直标签从0开始以整数递增所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。