JIDE 3.5.15

com.jidesoft.chart.annotation
Class ChartLabel

java.lang.Object
  extended by com.jidesoft.chart.annotation.AbstractAnnotation
      extended by com.jidesoft.chart.annotation.AbstractLabel
          extended by com.jidesoft.chart.annotation.ChartLabel
All Implemented Interfaces:
Annotation, ChartAnnotation, Chartable, Comparable<Chartable>

public class ChartLabel
extends AbstractLabel
implements Chartable, ChartAnnotation, Comparable<Chartable>

A Chart Label is a simple label of textual information that can be used as an annotation on a point of a Chart. It can be used to point out particular features of a chart such as maxima or minima, to label regions of interest, or to give more details about the points that they annotate such as the precise x and y coordinates or other (unshown) attributes of the point object.

Note that when providing the coordinates to be used for displaying the label, they:

The following screenshot shows ChartLabels being used to give additional information on all the points in a model when the user moves his mouse over an item in the legend:

Example of the use of Chart Labels


Constructor Summary
ChartLabel(double x, double y)
          Create a ChartLabel at the given user coordinates, but with the text of the label set to null.
ChartLabel(double x, double y, String label)
          Create a chart label annotation to be placed at the given position.
ChartLabel(Positionable x, Positionable y)
          Create a ChartLabel at the given user coordinates, but with the text of the label set to null.
ChartLabel(Positionable x, Positionable y, String label)
          Create a ChartLabel at the given user coordinates, with the supplied text label.
ChartLabel(Positionable x, Positionable y, String label, Color color)
          Create ChartLabel at the given user coordinates, with the supplied text label and text color.
ChartLabel(Positionable x, Positionable y, String label, Color color, Font font)
          Create ChartLabel at the given user coordinates, with the supplied text label and text color.
 
Method Summary
 int compareTo(Chartable other)
          Compares with other Chartables based on their x coordinates
 void draw(Graphics2D g, Chart chart)
          Draws this Chart Label onto the supplied graphics context using properties of the supplied chart instance.
 boolean equals(Object obj)
           
 Color getBackground()
          Returns the current background color used for the label
 Border getBorder()
          Returns the current border on the ChartLabel (or null if none has been set)
 Point getPixelOffset()
          Returns the offset in pixel values that is applied to the position of the ChartLabel after the x,y user coordinates have been calculated
 Positionable getX()
          Gets the x coordinate of the Chartable object
 Positionable getY()
          Gets the y coordinate of the Chartable object
 int hashCode()
           
 void setBackground(Color background)
          Specify the background color to be used for the label.
 void setBorder(Border border)
          Specify the border to use for the ChartLabel.
 void setPixelOffset(Point pixelOffset)
          Specify the offset in pixel values to be applied to the position of the ChartLabel after the x,y user coordinates have been calculated
 String toString()
           
 
Methods inherited from class com.jidesoft.chart.annotation.AbstractLabel
getColor, getFont, getLabel, getLabelComponent, getLabelStyle, getRotation, paint, paint, setColor, setFont, setLabel, setLabelStyle, setRotation, size
 
Methods inherited from class com.jidesoft.chart.annotation.AbstractAnnotation
getZOrder, setZOrder
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jidesoft.chart.annotation.ChartAnnotation
getZOrder
 

Constructor Detail

ChartLabel

public ChartLabel(double x,
                  double y,
                  String label)
Create a chart label annotation to be placed at the given position. The X,Y coordinates are near the centre of the label

Parameters:
x - the x coordinate in the user space
y - the y coordinate in the user space
label - the label to draw

ChartLabel

public ChartLabel(double x,
                  double y)
Create a ChartLabel at the given user coordinates, but with the text of the label set to null. To make the label useful, you will presumably be calling setLabel() with a string value at some later stage.

Parameters:
x - the x coordinate in the user space
y - the y coordinate in the user space

ChartLabel

public ChartLabel(Positionable x,
                  Positionable y)
Create a ChartLabel at the given user coordinates, but with the text of the label set to null. This constructor accepts Positionable objects to specify the user coordinates, so you may be using a ChartCategory or a RealPosition to define the location.

Parameters:
x - the x coordinate of the label
y - the y coordinate of the label

ChartLabel

public ChartLabel(Positionable x,
                  Positionable y,
                  String label)
Create a ChartLabel at the given user coordinates, with the supplied text label.

Parameters:
x - the x coordinate of the centre of the label
y - the y coordinate of the centre of the label
label - the text of the label. If the label starts with '' it will be interpreted as an HTML fragment.

ChartLabel

public ChartLabel(Positionable x,
                  Positionable y,
                  String label,
                  Color color)
Create ChartLabel at the given user coordinates, with the supplied text label and text color.

Parameters:
x - the x coordinate of the centre of the label
y - the y coordinate of the centre of the label
label - the text of the label. If the label starts with '' it will be interpreted as an HTML fragment.
color - the color of the text of the label

ChartLabel

public ChartLabel(Positionable x,
                  Positionable y,
                  String label,
                  Color color,
                  Font font)
Create ChartLabel at the given user coordinates, with the supplied text label and text color.

Parameters:
x - the x coordinate of the centre of the label
y - the y coordinate of the centre of the label
label - the text of the label. If the label starts with '' it will be interpreted as an HTML fragment.
color - the color of the text of the label
font - the font to be used for the label
Method Detail

getBackground

public Color getBackground()
Returns the current background color used for the label

Returns:
the background color used for the label (or null if none has been set)

setBackground

public void setBackground(Color background)
Specify the background color to be used for the label. Transparent colors are allowed.

Parameters:
background - the background color to be used on the label

getBorder

public Border getBorder()
Returns the current border on the ChartLabel (or null if none has been set)

Returns:
the current border on the ChartLabel

setBorder

public void setBorder(Border border)
Specify the border to use for the ChartLabel. Don't forget that as well as the more common Border types like LineBorder you can also use EmptyBorder and CompoundBorder to good effect here.

Parameters:
border - the border to use

getX

public Positionable getX()
Gets the x coordinate of the Chartable object

Specified by:
getX in interface Chartable
Returns:
the x coordinate

getY

public Positionable getY()
Gets the y coordinate of the Chartable object

Specified by:
getY in interface Chartable
Returns:
the y coordinate

getPixelOffset

public Point getPixelOffset()
Returns the offset in pixel values that is applied to the position of the ChartLabel after the x,y user coordinates have been calculated

Returns:
the current pixel offset for the position of the chart label

setPixelOffset

public void setPixelOffset(Point pixelOffset)
Specify the offset in pixel values to be applied to the position of the ChartLabel after the x,y user coordinates have been calculated

Parameters:
pixelOffset - the pixel offset to be applied to the position of the chart label

compareTo

public int compareTo(Chartable other)
Compares with other Chartables based on their x coordinates

Specified by:
compareTo in interface Comparable<Chartable>
Parameters:
other - the other Chartable with which this object is to be compared
Returns:
an int to indicate whether the x coordinate of this ChartLabel is less than, the same as, or greater than the x coordinate of the supplied Chartable.

draw

public void draw(Graphics2D g,
                 Chart chart)
Draws this Chart Label onto the supplied graphics context using properties of the supplied chart instance.

Specified by:
draw in interface ChartAnnotation
Parameters:
g - the Graphics context
chart - the chart from which property values may be taken and applied to the label

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractLabel

equals

public boolean equals(Object obj)
Overrides:
equals in class AbstractLabel

toString

public String toString()
Overrides:
toString in class AbstractLabel

JIDE 3.5.15