Setting Rows of Legend Markers

By default, the graph automatically calculates the best arrangement for legend markers, based on the number of series that are displayed in the graph and on the length of the series labels. Before you can set rows of legend markers, you must disable the automatic layout of the graph.

When automatic graph layout is disabled, the following properties of the LegendArea interact to determine the rows of legend markers:

When MarkersPerRowAutomatic is true, then the number of markers in a row is determined by the size of the legend area.

When MarkersPerRowAutomatic is false, then the LegendMarkersPerRow property specifies the number of markers that appear in a row.

You can set LegendMarkersPerRow to zero and MarkersPerRowAutomatic to have always one row or one column of markers, depending on the orientation of the legend area.

Automatic graph layout treats MarkersPerRowAutomatic as false, no matter how the property is set. The doAutoLayout method sets MarkersPerRowAutomatic to false, and it sets LegendMarkersPerRow to the number that it calculates.

Example: Displaying multiple rows of legend markers

The following code shows how to display legend markers in three rows. The code first disables automatic layout. Then it sets the legend orientation to horizontal, to ensure that the legend appears horizontal, without regard to the size of the legend area. Then this code specifies the number of markers per row.


// first, turn off automatic layout graph.setAutoLayout(Graph.AL_NEVER); // get the LegendArea of the graph LegendArea legend = graph.getLegendArea(); // set the orientation so that it is always horizontal legend.setLegendOrientation(LO_HORIZONTAL); // false is the default for MarkersPerRowAutomatic // this code is here in case it has been set to true legend.setMarkersPerRowAutomatic(false); // set the number of rows legend.setLegendMarkersPerRow(3);

Customizing Graph Legends
Managing Automatic Graph Layout