By default, the graph displays the legend to the right of the plot area or
below the plot area, depending on the size and location of the plot area, the
legend, and the legend components. You can specify a particular position for
the legend area, either in the Legend
Panel or by calling the setPosition
method of the LegendArea
component. Before you call setPosition
, you must set the AutomaticPlacement
property of the LegendArea
to BaseGraphComponent.AP_NEVER
.
You can also set the legend to appear along an entire edge of the graph, so that no white space appears between the legend and the edge of the graph.
During automatic layout of components, the graph respects the legend position properties.
The following code shows how to move the legend to the top edge of the graph.
// first, turn off automatic placement LegendArea legend = graph.getLegendArea(); legend.setAutomaticPlacement(BaseGraphComponent.AP_NEVER); // set the position to the top edge legend.setPosition(BaseGraphComponent.LAP_TOP); legend.setAlongGraphEdge(true);