Graphview in Eclipse Can the X & Y Axis use different LabelFormats?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 11:49:12

问题


I have a graph and I need the Y axis to display to 1dp. This works by doing the following code.

NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(1);
graph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter(nf, nf));

I need the X axis to display 2 strings, 1 at the beginning and 1 at the end. This works by doing the following code.

StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {firstStr,lastStr});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
graph.getGridLabelRenderer().setNumHorizontalLabels(2); 

My problem is I can't do both on the same graph!

Both work individually but not together, any ideas gratefully recieved

I am using version 4.0 of Graphview


回答1:


yes you can combine the static labels and dynamic labels.

Use the StaticLabelFormatter and set the dyamic label formatter. http://jjoe64.github.io/GraphView/javadoc/com/jjoe64/graphview/helper/StaticLabelsFormatter.html#setDynamicLabelFormatter-com.jjoe64.graphview.LabelFormatter-

Something like this should work:

NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(1);

StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {firstStr,lastStr});
staticLabelsFormatter.setDynamicLabelFormatter(new DefaultLabelFormatter(nf, nf));
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
graph.getGridLabelRenderer().setNumHorizontalLabels(2); 

Documentation http://www.android-graphview.org/documentation/label-formatter



来源:https://stackoverflow.com/questions/27861893/graphview-in-eclipse-can-the-x-y-axis-use-different-labelformats

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