By default, the graph automatically calculates the space that tick labels require, and it automatically lays out the graph to accommodate the space requirements. On an ordinal axis, you can specify some of the automatic layout behavior. You can specify the direction of tick labels if the automatic layout requires label rotation. You can also specify whether to skip tick labels. However, setting these properties limits the strategies that the graph can use to find an appropriate layout. For example, rotating the text is one of the last strategies that the automatic layout mechanism uses to display the tick labels appropriately. If you force rotation, then you eliminate several possibilities for a better display.
If you disable automatic
layout, then you can fully control the way tick labels appear along the
ordinal axis, by setting properties of the tick label components. The javadoc
for the O1TickLabel
describes all of its properties.
On a time axis, the graph automatically formats the time or date labels, based on the amount of data along the axis.
The following code shows how to specify the direction of rotation when the graph automatically lays out components. The graph only rotates tick labels if there is no other way to prevent overlapping or truncated labels.
// set rotation for automatic layout graph.getO1TickLabel().setAutomaticRotation(BaseGraphComponent.AR_HORIZ_ROTATE_90);
The following code shows how to display all of the tick labels and to rotate them so that they can all be read. This code rotates them so that they read up, toward the plot area. Note that rotating tick labels limits the strategies that automatic layout can use to display tick labels appropriately. You might be preventing a better display if you rotate labels.
// disable automatic layout graph.setAutoLayout(Graph.AL_NEVER); O1TickLabel tick_label = graph.getO1TickLabel(); tick_label.setTickLabelSkipMode(BaseGraphComponent.TLS_NOSKIP); tick_label.setTextRotation(BaseGraphComponent.TR_HORIZ_ROTATE_90);
The following code shows how to display tick labels for January, April, July, and October in a graph where the groups are different months. This example assumes that the first group in the graph is for January.
// disable automatic layout graph.setAutoLayout(Graph.AL_NEVER); // get the O1TickLabel O1TickLabel tick_label_months = graph.getO1TickLabel(); // set the skip mode to manual tick_label_months.setTickLabelSkipMode(BaseGraphComponent.TLS_MANUAL); // hide two months between those shown, such as February and March tick_label_months.setTickLabelSkipCount(2); // start with the label for the first group of data -- January tick_label_months.setTickLabelSkipFirst(0);
Note: The value of TickLabelSkipFirst
must not
be larger than the value of TickLabelSkipCount
. For example, if
you set TickLabelSkipCount
to 3 and TickLabelSkipFirst
to 4, then you are specifying that you want to skip three labels between displayed
labels, and that you want to start with the fifth label in the graph. But to
start with the fifth label, the graph must skip four labels instead of three.
The graph cannot accommodate both requests.
The following code shows how to display tick labels for all groups but to stagger them so that the text of the labels does not overlap.
// disable automatic layout graph.setAutoLayout(Graph.AL_NEVER); // show all tick labels O1TickLabel tick_label = graph.getO1TickLabel(); tick_label.setTickLabelSkipMode(BaseGraphComponent.TLS_NOSKIP); // stagger tick_label.setTickLabelStagger(true);