目前,下面的代码显示附加的条形图,其中包含小数位数,从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开始以整数递增所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)