com.jinsight.jetchart
Class Legend

java.lang.Object
  |
  +--com.jinsight.jetchart.Legend

public class Legend
extends java.lang.Object

The Legend class implements the legend box to display series titles. JetChart supports an unlimited number of legend boxes, each of them associated with different sets of series titles.
By default, all series titles are displayed in the primary legend box, which always exists and is automatically created. A legend box manually created is a secondary legend box. To display a series title inside a secondary legend box, add the series using the method Legend.addSeries(AbstractSerie as), as below:

LineSerie ls=new LineSerie();
ls.setTitle("Line series");
Legend legend=new Legend();
legend.addSerie(ls);


Any series not added to secondary legend boxes are automatically added to the primary legend box.


Field Summary
static int ANYWHERE
          Constant used to place the legend box at any location on the chart area.
static int BOTTOM
          Constant used to place the legend box at the bottom and centered.
static int BOTTOM_LEFT
          Constant used to place the legend box at the bottom and left-aligned.
static int BOTTOM_RIGHT
          Contant used to place the legend box at the bottom and right-aligned.
static int HORIZONTAL
          Constant used to arrange series titles horizontally.
static int LEFT
          Constant used to place the legend box at the left side.
static int RIGHT
          Constant used to place the legend box at the right side.
static int VERTICAL
          Constant used to arrange series titles vertically.
 
Constructor Summary
Legend()
           
 
Method Summary
 void addSerie(AbstractSerie as)
          Adds a series to this legend box.
protected  void finalize()
           
 int getPosition()
          Returns the legend box position.
 void removeAllSeries()
          Removes all series from this legend box.
 void removeSerie(AbstractSerie as)
          Removes a series from this legend box.
 void setAutoOrientationEnabled(boolean isAutoOrientationEnabled)
          Enables/disables automatic orientation.
 void setBackground(java.awt.Color background)
          Sets the legend box background color.
 void setColumnGap(int columnGap)
          Sets the gap between columns of a legend box.
 void setColumnLayout(int nrOfColumns)
          Sets the number of columns in the legend box.
 void setEnabled(boolean isEnabled)
          Enables/disables this Legend object.
 void setFont(java.awt.Font font)
          Sets the legend box font.
 void setForeground(java.awt.Color foreground)
          Sets the legend box foreground color.
 void setHGap(int hGap)
          Sets horizontal gap.
 void setLocation(int x, int y)
          Sets the location of the legend box, in absolute coordinates.
 void setOpacityEnabled(boolean isOpaque)
          Enables/disables opacity.
 void setOrientation(int orientation)
          Sets the legend box orientation to horizontal or vertical.
 void setPosition(int position)
          Sets the legend box position to the left, right, bottom or any location within the chart area.
 void setRowGap(int rowGap)
          Sets the gap between rows in a legend box displaying multiple rows.
 void setVGap(int vGap)
          Sets vertical gap.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERTICAL

public static final int VERTICAL
Constant used to arrange series titles vertically.

HORIZONTAL

public static final int HORIZONTAL
Constant used to arrange series titles horizontally.

LEFT

public static final int LEFT
Constant used to place the legend box at the left side.

BOTTOM

public static final int BOTTOM
Constant used to place the legend box at the bottom and centered.

RIGHT

public static final int RIGHT
Constant used to place the legend box at the right side.

BOTTOM_LEFT

public static final int BOTTOM_LEFT
Constant used to place the legend box at the bottom and left-aligned.

BOTTOM_RIGHT

public static final int BOTTOM_RIGHT
Contant used to place the legend box at the bottom and right-aligned.

ANYWHERE

public static final int ANYWHERE
Constant used to place the legend box at any location on the chart area.
Constructor Detail

Legend

public Legend()
Method Detail

setEnabled

public void setEnabled(boolean isEnabled)
Enables/disables this Legend object.
Parameters:
isEnabled - A boolean value(true/false).

addSerie

public void addSerie(AbstractSerie as)
Adds a series to this legend box. This method must not be used with the primary legend box, which has always index 0 when using the method GenericGraph.getLegend(int index).
Parameters:
as - An AbstractSerie object.
See Also:
removeSerie(com.jinsight.jetchart.AbstractSerie), GenericGraph.addLegend(com.jinsight.jetchart.Legend), GenericGraph.removeLegend(com.jinsight.jetchart.Legend)

removeSerie

public void removeSerie(AbstractSerie as)
Removes a series from this legend box. This method must not be used with the primary legend box, which has always index 0 when using the method GenericGraph.getLegend(int index).
Parameters:
as - An AbstractSerie object.
See Also:
addSerie(com.jinsight.jetchart.AbstractSerie), GenericGraph.addLegend(com.jinsight.jetchart.Legend), GenericGraph.removeLegend(com.jinsight.jetchart.Legend)

removeAllSeries

public void removeAllSeries()
Removes all series from this legend box. This method must not be used with the primary legend box, which always has index 0 when using the method GenericGraph.getLegend(int index).
See Also:
addSerie(com.jinsight.jetchart.AbstractSerie), removeSerie(com.jinsight.jetchart.AbstractSerie), GenericGraph.addLegend(com.jinsight.jetchart.Legend), GenericGraph.removeLegend(com.jinsight.jetchart.Legend)

setFont

public void setFont(java.awt.Font font)
Sets the legend box font.
Parameters:
font - A Font object.

setColumnLayout

public void setColumnLayout(int nrOfColumns)
Sets the number of columns in the legend box. Only has effect if orientation is set to HORIZONTAL.
Parameters:
nrOfColumns - An integer number.
See Also:
setOrientation(int)

setOrientation

public void setOrientation(int orientation)
Sets the legend box orientation to horizontal or vertical. It has no effect if auto orientation is enabled. Orientation is vertical by default.
Parameters:
orientation - An integer number indicating legend box orientation.
See Also:
HORIZONTAL, VERTICAL

setAutoOrientationEnabled

public void setAutoOrientationEnabled(boolean isAutoOrientationEnabled)
Enables/disables automatic orientation. If the legend box is placed at the left or right sides, orientation is set to vertical. If the legend box is placed at the bottom side, orientation is set to horizontal. Automatic orientation is enabled by default.
Parameters:
isAutoOrientationEnabled - A boolean value.

setPosition

public void setPosition(int position)
Sets the legend box position to the left, right, bottom or any location within the chart area. Default position is BOTTOM.
The ANYWHERE constant only has efffect if auto orientation is disabled. Passing ANYWHERE to this method when auto orientation is enabled automatically sets the legend box position to BOTTOM.
Parameters:
position - An integer number indicating the legend box position.
See Also:
LEFT, RIGHT, BOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT, ANYWHERE, setAutoOrientationEnabled(boolean)

setLocation

public void setLocation(int x,
                        int y)
Sets the location of the legend box, in absolute coordinates. This method only has effect if legend positions is set to ANYWHERE and auto orientation is disabled.
Parameters:
x - The x coordinate of the upper left corner of the legend box.
y - The y coordinate of the upper left corner of the legend box.
See Also:
ANYWHERE, setPosition(int), setAutoOrientationEnabled(boolean)

getPosition

public int getPosition()
Returns the legend box position.
Returns:
An integer number indicating the legend box position.
See Also:
LEFT, RIGHT, BOTTOM, BOTTOM_RIGHT, BOTTOM_LEFT, ANYWHERE

setBackground

public void setBackground(java.awt.Color background)
Sets the legend box background color.
Parameters:
background - A Color object.

setOpacityEnabled

public void setOpacityEnabled(boolean isOpaque)
Enables/disables opacity. If disabled, background color is not painted. The legend box is opaque by default.
Parameters:
isOpaque - A boolean value(true/false).

setForeground

public void setForeground(java.awt.Color foreground)
Sets the legend box foreground color. The foreground color is the color of the series titles.
Parameters:
foreground - A Color object.

setHGap

public void setHGap(int hGap)
Sets horizontal gap. The horizontal gap is the space between the legend box and the left or right titles. If the left or right titles are not displayed, it is the distance between the legend box and the labels of the left or right axis. This property only has effect if the legend box is placed at the right or left sides. Default value is 10 pixels.
Parameters:
hGap - An integer number indicating the horizontal gap, in pixels.

setVGap

public void setVGap(int vGap)
Sets vertical gap. The vertical gap is the space between the bottom title and the legend box. If the bottom title is not displayed, it is the distance between the labels of the horizontal axis and the top of the legend box. This property only has effect if the legend is placed at the bottom side. Default value is 10 pixels.
Parameters:
vGap - An integer number indicating the vertical gap, in pixels.

setColumnGap

public void setColumnGap(int columnGap)
Sets the gap between columns of a legend box. The gap is the distance in pixels from a title icon to the next one on the right. There is a margin of 5 pixels surrounding each icon that is not affected by the column gap. Only has effect if legend orientation is HORIZONTAL and column layout is set to a number greater than zero. If column gap is set to zero, the distance between icons is automatically set to the width of the longest title. Default value is zero.
Parameters:
columnGap - an integer number equal or greater than zero.
See Also:
setColumnLayout(int), setOrientation(int)

setRowGap

public void setRowGap(int rowGap)
Sets the gap between rows in a legend box displaying multiple rows. There is a margin of 5 pixels surrounding each icon that is not affected by the row gap. Default value is zero.
Parameters:
rowGap - An integer number.

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object