Customizing Graph Legends

By default, the graph automatically calculates the best layout for the legend, based on the data that the graph displays. When automatic layout is disabled, you can set a number of properties on the legend components to customize the appearance of the legend.

The following properties of the LegendArea component control the display of the legend.

LegendArea Property

Description

BorderColor

The color of the border around the legend area. Automatic layout respects this property value.

BorderTransparent

Whether the border around the legend area is transparent (that is, does not show). Automatic layout respects this property value.

FillColor

The background color of the legend area. Automatic layout respects this property value.

FillTransparent

Whether the legend area background is transparent. Automatic layout respects this property value.

SFX

The special effects object that defines any special effects, such as a texture or an image, for the legend area background. Automatic layout respects this property value.

Position

The position of the legend area in the graph (top, bottom, right, or left). Automatic layout respects this property value.

AutomaticPlacement

Whether the legend position is determined by automatic layout or by the Position property. Automatic layout respects this property. The doAutoLayout method sets this property to BaseGraphComponent.AP_NEVER.

AlongGraphEdge Whether the legend extends along the entire edge of the graph or not. The edge is determined by the Position property. Automatic layout respects this property value. When this property is true, you should use automatic layout.

Rect

The size and location of the legend area, using the java.awt.Rectangle class. Automatic layout ignores this property; doAutoLayout sets it. Setting AlongGraphEdge to true also sets this property. This property is normally ignored if AutomaticPlacement is true.

MarkersPerRowAutomatic

Whether the graph automatically determines the number of rows of legend markers that appear in the legend, based on the number of series and the size of the legend area, or whether you set the number of rows explicitly. Automatic layout ignores this property.

LegendMarkersPerRow

The number of legend markers in a row in the legend area. MarkersPerRowAutomatic must be false for this property to take effect. Automatic layout ignores this property; doAutoLayout sets it, based on the data.

LegendOrientation

The orientation of the legend area, either vertical or horizontal. Automatic layout ignores this property; doAutoLayout sets it, based on the Position.

LegendTextPosition

The location of the legend text with regard to the legend markers, to the left of the marker, to the right of the marker, above, or below the marker. Automatic layout ignores this setting; doAutoLayout sets it to place the text to the right of the marker.

Visible

Whether the legend appears in the graph at all. Automatic layout honors this property.

The following properties of the graph control whether users can scroll through the legend to see markers.

Graph Property

Description

LegendScrollbarPresence

Whether a scrollbar appears in the legend. Automatic layout ignores this property; doAutoLayout sets it to SP_NEVER.

LegendSeriesCount

The number of markers that appear in a legend at a time. Automatic layout ignores this property; doAutoLayout sets it to the number of series that appears in the legend.

LegendSeriesStart

The first series for which to display a marker in the legend. Automatic layout ignores this property; doAutoLayout sets it to 0.

You can also limit the size of a legend marker by setting the MaxSize property of the LegendMarker. Automatic layout ignores the MaxSize property; doAutoLayout sets it to 11 pixels.

Making the Graph Legend Scrollable
Managing Automatic Graph Layout
Setting Rows of Legend Markers
Setting the Location of Legend Text
Setting the Position of a Legend