Setting the legend box position

Multiple legend boxes can be displayed, positioned at different locations and showing the titles of distinct groups of series. For example, a chart displaying two vertical scales can have one legend box to the left and another one to the right, showing the titles of series whose data points are plotted against the left and vertical scales, respectively.
There is no limit on the number of legend boxes that can be added to the chart context. By default, only one legend box is displayed, showing the titles of all series added to the chart context. The default legend box, referred to as the primary legend box, is automatically created. Any additional legend box, referred to as a secondary legend box, has to be explicitly created and added.

The only applets that support multiple legend boxes are GraphApplet and ScatterApplet. PieApplet doesn't support.

Each legend box is assigned an index. The primary one has index 0 and secondary legend boxes are sequentially assigned indexes in the order they are added to the chart context, starting with number 1. These indexes are used to get references to respective legend boxes.

To create secondary legend boxes and add them to the chart context, use the parameter nroflegends to specify the number of legend boxes to be created, as follow:

<param name="nroflegends" value="3">
Three secondary legend boxes are created, with indexes 1, 2 and 3.

To display the title of a series inside a secondary legend box, do as follow:

<param name="serie1_legendindex" value="2">
The title of a series with index 1 will be displayed inside a secondary legend box with index 2.

By default, the orientation of a legend box is automatic. If it is placed at the bottom side, series titles are displayed side by side(horizontal orientation), and if it is placed at the left or right sides, series titles are stacked one above the other(vertical orientation).

To disable auto orientation and set orientation manually, use the parameters legendx_autoorientationon and legendx_orientation. Set the former to no and pass one of the values below to the latter:

The legend box is, by default, automatically centered at the bottom of the chart area. Six values can be used to specify the position of the legend box, using the parameter legendx_position:

Additionally, it is possible to dynamically change the position of any legend box position using the mouse.

To dynamically change the legend box position, double click it to toggle chart into a 'moving legend' state. While in this mode, a red thick line surrounds the legend box and the chart does not answer to mouse events, like dragging or resizing, until the legend box is dropped onto the desired position. After toggling chart state, move mouse cursor to the position where the legend box will be moved to and do the following:

To resume from a 'moving legend' state without changing legend position, just double-click the legend box again.

A list of all legend parameters applicable to GraphApplet and ScatterApplet can be found here.
A list of all legend parameters applicable to PieApplet can be found here.

The following example creates two secondary legend boxes to display the titles of the green and yellow stacked bar series. The title of the remaining series is displayed in the primary legend box, placed at the bottom.



<applet code="GraphApplet.class" codebase="../../../demo/applets/classes" archive="GraphChart.jar" width=550 height=300>

<param name="nroflegends" value="2"> <!-- Creates two secondary legend boxes. -->

<param name="legend1_position" value="0"> <!-- One secondary legend box is placed at the left side -->
<param name="legend2_position" value="2"> <!-- The other secondary legend box is placed at the right side -->

<param name="3d" value="yes">
<param name="horizontal" value="yes">

<param name="labels" value="label1,label2,label3,label4,label5,label6,label7">
<param name="title" value="The JetChart Library,Setting the legend box position">

<param name="graphset0_gridon" value="yes">
<param name="graphset0_crossedgridon" value="yes">

<param name="serie1" value="stackbar,Stacked Bar 1,ff0000">
<param name="serie1_values" value="100,80,-90,40,75,60,85">

<param name="serie2" value="stackbar,Stacked Bar 2,00ff00">
<param name="serie2_values" value="50,60,45,30,-65,53,73">

<param name="serie2_legendindex" value="1"><!-- Sets the index of the secondary legend box to display the green line series' title.-->

<param name="serie3" value="stackbar,Stacked Bar 3,ffff00">
<param name="serie3_values" value="40,-30,50,60,-80,90">

<param name="serie3_legendindex" value="2"><!-- Sets the index of the secondary legend box to display the yellow line series' title.-->

</applet>