问题
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