Package org.jfree.chart.axis
Class Axis
java.lang.Object
org.jfree.chart.axis.Axis
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
CategoryAxis,ValueAxis
The base class for all axes in JFreeChart. Subclasses are divided into
those that display values (
ValueAxis) and those that display
categories (CategoryAxis).- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FontThe default axis label font (Font("SansSerif", Font.PLAIN, 12)).static final RectangleInsetsThe default axis label insets (RectangleInsets(3.0, 3.0, 3.0, 3.0)).static final PaintThe default axis label paint (Color.BLACK).static final PaintThe default axis line paint (Color.GRAY).static final StrokeThe default axis line stroke (BasicStroke(0.5f)).static final booleanThe default axis visibility (true).static final FontThe default tick label font (Font("SansSerif", Font.PLAIN, 10)).static final RectangleInsetsThe default tick label insets (RectangleInsets(2.0, 4.0, 2.0, 4.0)).static final PaintThe default tick label paint (Color.BLACK).static final booleanThe default tick labels visibility (true).static final floatThe default tick mark inside length (0.0f).static final floatThe default tick mark outside length (2.0f).static final PaintThe default tick paint (Color.GRAY).static final StrokeThe default tick stroke (BasicStroke(0.5f)).static final booleanThe default tick marks visible (true). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeListener(AxisChangeListener listener) Registers an object for notification of changes to the axis.clone()Returns a clone of the axis.abstract voidConfigures the axis to work with the current plot.protected voidcreateAndAddEntity(double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) Creates an entity for the axis and adds it to the rendering info.createAttributedLabel(String label) Creates and returns anAttributedStringwith the specified text and the labelFont and labelPaint applied as attributes.abstract AxisStatedraw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) Draws the axis on a Java 2D graphics device (such as the screen or a printer).protected AxisStatedrawAttributedLabel(AttributedString label, Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state) Draws the axis label.protected voiddrawAxisLine(Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge) Draws an axis line at the current cursor position and edge.protected AxisStatedrawLabel(String label, Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state) Draws the axis label.booleanTests this axis for equality with another object.protected voidSends anAxisChangeEventto all registered listeners.Returns the attributed label (the returned value is a copy, so modifying it will not impact the state of the axis).Returns the paint used to draw the axis line.Returns the stroke used to draw the axis line.doubleReturns the fixed dimension for the axis.getLabel()Returns the label for the axis.doubleReturns the angle of the axis label.protected Rectangle2DgetLabelEnclosure(Graphics2D g2, RectangleEdge edge) Returns a rectangle that encloses the axis label.Returns the font for the axis label.Returns the insets for the label (that is, the amount of blank space that should be left around the label).Returns the location of the axis label.Returns the color/shade used to draw the axis label.floatReturns the inside length of the minor tick marks.floatReturns the outside length of the minor tick marks.getPlot()Returns the plot that the axis is assigned to.Returns the font used for the tick labels (if showing).Returns the insets for the tick labels.Returns the color/shade used for the tick labels.floatReturns the inside length of the tick marks.floatReturns the outside length of the tick marks.Returns the paint used to draw tick marks (if they are showing).Returns the stroke used to draw tick marks.inthashCode()Returns a hash code for this instance.booleanhasListener(EventListener listener) Returnstrueif the specified object is registered with the dataset as a listener.booleanA flag that controls whether or not the axis line is drawn.booleanReturns the flag that indicates whether or not the minor tick marks are showing.booleanReturns a flag indicating whether or not the tick labels are visible.booleanReturns the flag that indicates whether or not the tick marks are showing.booleanReturnstrueif the axis is visible, andfalseotherwise.protected TextAnchorlabelAnchorH(AxisLabelLocation location) Returns the appropriate horizontal text anchor for the specified axis location.protected TextAnchorlabelAnchorV(AxisLabelLocation location) Returns the appropriate vertical text anchor for the specified axis location.protected doublelabelLocationX(AxisLabelLocation location, Rectangle2D dataArea) Returns the x-coordinate for the point to which the axis label should be aligned.protected doublelabelLocationY(AxisLabelLocation location, Rectangle2D dataArea) Returns the y-coordinate for the point to which the axis label should be aligned.protected voidnotifyListeners(AxisChangeEvent event) Notifies all registered listeners that the axis has changed.abstract ListrefreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).voidremoveChangeListener(AxisChangeListener listener) Deregisters an object for notification of changes to the axis.abstract AxisSpacereserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) Estimates the space (height or width) required to draw the axis.voidsetAttributedLabel(String label) Sets the attributed label for the axis and sends anAxisChangeEventto all registered listeners.voidSets the attributed label for the axis and sends anAxisChangeEventto all registered listeners.voidsetAxisLinePaint(Paint paint) Sets the paint used to draw the axis line and sends anAxisChangeEventto all registered listeners.voidsetAxisLineStroke(Stroke stroke) Sets the stroke used to draw the axis line and sends anAxisChangeEventto all registered listeners.voidsetAxisLineVisible(boolean visible) Sets a flag that controls whether or not the axis line is visible and sends anAxisChangeEventto all registered listeners.voidsetFixedDimension(double dimension) Sets the fixed dimension for the axis.voidSets the label for the axis and sends anAxisChangeEventto all registered listeners.voidsetLabelAngle(double angle) Sets the angle for the label and sends anAxisChangeEventto all registered listeners.voidsetLabelFont(Font font) Sets the font for the axis label and sends anAxisChangeEventto all registered listeners.voidsetLabelInsets(RectangleInsets insets) Sets the insets for the axis label, and sends anAxisChangeEventto all registered listeners.voidsetLabelInsets(RectangleInsets insets, boolean notify) Sets the insets for the axis label, and sends anAxisChangeEventto all registered listeners.voidsetLabelLocation(AxisLabelLocation location) Sets the axis label location and sends anAxisChangeEventto all registered listeners.voidsetLabelPaint(Paint paint) Sets the paint used to draw the axis label and sends anAxisChangeEventto all registered listeners.voidsetMinorTickMarkInsideLength(float length) Sets the inside length of the minor tick marks and sends anAxisChangeEventto all registered listeners.voidsetMinorTickMarkOutsideLength(float length) Sets the outside length of the minor tick marks and sends anAxisChangeEventto all registered listeners.voidsetMinorTickMarksVisible(boolean flag) Sets the flag that indicates whether or not the minor tick marks are showing and sends anAxisChangeEventto all registered listeners.voidSets a reference to the plot that the axis is assigned to.voidsetTickLabelFont(Font font) Sets the font for the tick labels and sends anAxisChangeEventto all registered listeners.voidsetTickLabelInsets(RectangleInsets insets) Sets the insets for the tick labels and sends anAxisChangeEventto all registered listeners.voidsetTickLabelPaint(Paint paint) Sets the paint used to draw tick labels (if they are showing) and sends anAxisChangeEventto all registered listeners.voidsetTickLabelsVisible(boolean flag) Sets the flag that determines whether or not the tick labels are visible and sends anAxisChangeEventto all registered listeners.voidsetTickMarkInsideLength(float length) Sets the inside length of the tick marks and sends anAxisChangeEventto all registered listeners.voidsetTickMarkOutsideLength(float length) Sets the outside length of the tick marks and sends anAxisChangeEventto all registered listeners.voidsetTickMarkPaint(Paint paint) Sets the paint used to draw tick marks and sends anAxisChangeEventto all registered listeners.voidsetTickMarkStroke(Stroke stroke) Sets the stroke used to draw tick marks and sends anAxisChangeEventto all registered listeners.voidsetTickMarksVisible(boolean flag) Sets the flag that indicates whether or not the tick marks are showing and sends anAxisChangeEventto all registered listeners.voidsetVisible(boolean flag) Sets a flag that controls whether or not the axis is visible and sends anAxisChangeEventto all registered listeners.
-
Field Details
-
DEFAULT_AXIS_VISIBLE
The default axis visibility (true).- See Also:
-
DEFAULT_AXIS_LABEL_FONT
The default axis label font (Font("SansSerif", Font.PLAIN, 12)). -
DEFAULT_AXIS_LABEL_PAINT
The default axis label paint (Color.BLACK). -
DEFAULT_AXIS_LABEL_INSETS
The default axis label insets (RectangleInsets(3.0, 3.0, 3.0, 3.0)). -
DEFAULT_AXIS_LINE_PAINT
The default axis line paint (Color.GRAY). -
DEFAULT_AXIS_LINE_STROKE
The default axis line stroke (BasicStroke(0.5f)). -
DEFAULT_TICK_LABELS_VISIBLE
The default tick labels visibility (true).- See Also:
-
DEFAULT_TICK_LABEL_FONT
The default tick label font (Font("SansSerif", Font.PLAIN, 10)). -
DEFAULT_TICK_LABEL_PAINT
The default tick label paint (Color.BLACK). -
DEFAULT_TICK_LABEL_INSETS
The default tick label insets (RectangleInsets(2.0, 4.0, 2.0, 4.0)). -
DEFAULT_TICK_MARKS_VISIBLE
The default tick marks visible (true).- See Also:
-
DEFAULT_TICK_MARK_STROKE
The default tick stroke (BasicStroke(0.5f)). -
DEFAULT_TICK_MARK_PAINT
The default tick paint (Color.GRAY). -
DEFAULT_TICK_MARK_INSIDE_LENGTH
The default tick mark inside length (0.0f).- See Also:
-
DEFAULT_TICK_MARK_OUTSIDE_LENGTH
The default tick mark outside length (2.0f).- See Also:
-
-
Constructor Details
-
Axis
Constructs an axis with the specific label and default values for other attributes.- Parameters:
label- the axis label (nullpermitted).
-
-
Method Details
-
isVisible
Returnstrueif the axis is visible, andfalseotherwise.- Returns:
- A boolean.
- See Also:
-
setVisible
Sets a flag that controls whether or not the axis is visible and sends anAxisChangeEventto all registered listeners.- Parameters:
flag- the flag.- See Also:
-
getLabel
Returns the label for the axis.- Returns:
- The label for the axis (
nullpossible). - See Also:
-
setLabel
Sets the label for the axis and sends anAxisChangeEventto all registered listeners.- Parameters:
label- the new label (nullpermitted).- See Also:
-
getAttributedLabel
Returns the attributed label (the returned value is a copy, so modifying it will not impact the state of the axis). The default value isnull.- Returns:
- The attributed label (possibly
null).
-
setAttributedLabel
Sets the attributed label for the axis and sends anAxisChangeEventto all registered listeners. This is a convenience method that converts the string into anAttributedStringusing the current font attributes.- Parameters:
label- the label (nullpermitted).
-
setAttributedLabel
Sets the attributed label for the axis and sends anAxisChangeEventto all registered listeners.- Parameters:
label- the label (nullpermitted).
-
createAttributedLabel
Creates and returns anAttributedStringwith the specified text and the labelFont and labelPaint applied as attributes.- Parameters:
label- the label (nullpermitted).- Returns:
- An attributed string or
null.
-
getLabelFont
Returns the font for the axis label.- Returns:
- The font (never
null). - See Also:
-
setLabelFont
Sets the font for the axis label and sends anAxisChangeEventto all registered listeners.- Parameters:
font- the font (nullnot permitted).- See Also:
-
getLabelPaint
Returns the color/shade used to draw the axis label.- Returns:
- The paint (never
null). - See Also:
-
setLabelPaint
Sets the paint used to draw the axis label and sends anAxisChangeEventto all registered listeners.- Parameters:
paint- the paint (nullnot permitted).- See Also:
-
getLabelInsets
Returns the insets for the label (that is, the amount of blank space that should be left around the label).- Returns:
- The label insets (never
null). - See Also:
-
setLabelInsets
Sets the insets for the axis label, and sends anAxisChangeEventto all registered listeners.- Parameters:
insets- the insets (nullnot permitted).- See Also:
-
setLabelInsets
Sets the insets for the axis label, and sends anAxisChangeEventto all registered listeners.- Parameters:
insets- the insets (nullnot permitted).notify- notify listeners?
-
getLabelAngle
Returns the angle of the axis label.- Returns:
- The angle (in radians).
- See Also:
-
setLabelAngle
Sets the angle for the label and sends anAxisChangeEventto all registered listeners.- Parameters:
angle- the angle (in radians).- See Also:
-
getLabelLocation
Returns the location of the axis label. The default isAxisLabelLocation.MIDDLE.- Returns:
- The location of the axis label (never
null).
-
setLabelLocation
Sets the axis label location and sends anAxisChangeEventto all registered listeners.- Parameters:
location- the new location (nullnot permitted).
-
isAxisLineVisible
A flag that controls whether or not the axis line is drawn.- Returns:
- A boolean.
- See Also:
-
setAxisLineVisible
Sets a flag that controls whether or not the axis line is visible and sends anAxisChangeEventto all registered listeners.- Parameters:
visible- the flag.- See Also:
-
getAxisLinePaint
Returns the paint used to draw the axis line.- Returns:
- The paint (never
null). - See Also:
-
setAxisLinePaint
Sets the paint used to draw the axis line and sends anAxisChangeEventto all registered listeners.- Parameters:
paint- the paint (nullnot permitted).- See Also:
-
getAxisLineStroke
Returns the stroke used to draw the axis line.- Returns:
- The stroke (never
null). - See Also:
-
setAxisLineStroke
Sets the stroke used to draw the axis line and sends anAxisChangeEventto all registered listeners.- Parameters:
stroke- the stroke (nullnot permitted).- See Also:
-
isTickLabelsVisible
Returns a flag indicating whether or not the tick labels are visible.- Returns:
- The flag.
- See Also:
-
setTickLabelsVisible
Sets the flag that determines whether or not the tick labels are visible and sends anAxisChangeEventto all registered listeners.- Parameters:
flag- the flag.- See Also:
-
isMinorTickMarksVisible
Returns the flag that indicates whether or not the minor tick marks are showing.- Returns:
- The flag that indicates whether or not the minor tick marks are showing.
- See Also:
-
setMinorTickMarksVisible
Sets the flag that indicates whether or not the minor tick marks are showing and sends anAxisChangeEventto all registered listeners.- Parameters:
flag- the flag.- See Also:
-
getTickLabelFont
Returns the font used for the tick labels (if showing).- Returns:
- The font (never
null). - See Also:
-
setTickLabelFont
Sets the font for the tick labels and sends anAxisChangeEventto all registered listeners.- Parameters:
font- the font (nullnot allowed).- See Also:
-
getTickLabelPaint
Returns the color/shade used for the tick labels.- Returns:
- The paint used for the tick labels.
- See Also:
-
setTickLabelPaint
Sets the paint used to draw tick labels (if they are showing) and sends anAxisChangeEventto all registered listeners.- Parameters:
paint- the paint (nullnot permitted).- See Also:
-
getTickLabelInsets
Returns the insets for the tick labels.- Returns:
- The insets (never
null). - See Also:
-
setTickLabelInsets
Sets the insets for the tick labels and sends anAxisChangeEventto all registered listeners.- Parameters:
insets- the insets (nullnot permitted).- See Also:
-
isTickMarksVisible
Returns the flag that indicates whether or not the tick marks are showing.- Returns:
- The flag that indicates whether or not the tick marks are showing.
- See Also:
-
setTickMarksVisible
Sets the flag that indicates whether or not the tick marks are showing and sends anAxisChangeEventto all registered listeners.- Parameters:
flag- the flag.- See Also:
-
getTickMarkInsideLength
Returns the inside length of the tick marks.- Returns:
- The length.
- See Also:
-
setTickMarkInsideLength
Sets the inside length of the tick marks and sends anAxisChangeEventto all registered listeners.- Parameters:
length- the new length.- See Also:
-
getTickMarkOutsideLength
Returns the outside length of the tick marks.- Returns:
- The length.
- See Also:
-
setTickMarkOutsideLength
Sets the outside length of the tick marks and sends anAxisChangeEventto all registered listeners.- Parameters:
length- the new length.- See Also:
-
getTickMarkStroke
Returns the stroke used to draw tick marks.- Returns:
- The stroke (never
null). - See Also:
-
setTickMarkStroke
Sets the stroke used to draw tick marks and sends anAxisChangeEventto all registered listeners.- Parameters:
stroke- the stroke (nullnot permitted).- See Also:
-
getTickMarkPaint
Returns the paint used to draw tick marks (if they are showing).- Returns:
- The paint (never
null). - See Also:
-
setTickMarkPaint
Sets the paint used to draw tick marks and sends anAxisChangeEventto all registered listeners.- Parameters:
paint- the paint (nullnot permitted).- See Also:
-
getMinorTickMarkInsideLength
Returns the inside length of the minor tick marks.- Returns:
- The length.
- See Also:
-
setMinorTickMarkInsideLength
Sets the inside length of the minor tick marks and sends anAxisChangeEventto all registered listeners.- Parameters:
length- the new length.- See Also:
-
getMinorTickMarkOutsideLength
Returns the outside length of the minor tick marks.- Returns:
- The length.
- See Also:
-
setMinorTickMarkOutsideLength
Sets the outside length of the minor tick marks and sends anAxisChangeEventto all registered listeners.- Parameters:
length- the new length.- See Also:
-
getPlot
Returns the plot that the axis is assigned to. This method will returnnullif the axis is not currently assigned to a plot.- Returns:
- The plot that the axis is assigned to (possibly
null). - See Also:
-
setPlot
Sets a reference to the plot that the axis is assigned to.This method is used internally, you shouldn't need to call it yourself.
- Parameters:
plot- the plot.- See Also:
-
getFixedDimension
Returns the fixed dimension for the axis.- Returns:
- The fixed dimension.
- See Also:
-
setFixedDimension
Sets the fixed dimension for the axis.This is used when combining more than one plot on a chart. In this case, there may be several axes that need to have the same height or width so that they are aligned. This method is used to fix a dimension for the axis (the context determines whether the dimension is horizontal or vertical).
- Parameters:
dimension- the fixed dimension.- See Also:
-
configure
Configures the axis to work with the current plot. Override this method to perform any special processing (such as auto-rescaling). -
reserveSpace
public abstract AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) Estimates the space (height or width) required to draw the axis.- Parameters:
g2- the graphics device.plot- the plot that the axis belongs to.plotArea- the area within which the plot (including axes) should be drawn.edge- the axis location.space- space already reserved.- Returns:
- The space required to draw the axis (including pre-reserved space).
-
draw
public abstract AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) Draws the axis on a Java 2D graphics device (such as the screen or a printer).- Parameters:
g2- the graphics device (nullnot permitted).cursor- the cursor location (determines where to draw the axis).plotArea- the area within which the axes and plot should be drawn.dataArea- the area within which the data should be drawn.edge- the axis location (nullnot permitted).plotState- collects information about the plot (nullpermitted).- Returns:
- The axis state (never
null).
-
refreshTicks
public abstract List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).- Parameters:
g2- the graphics device.state- the axis state.dataArea- the area inside the axes.edge- the edge on which the axis is located.- Returns:
- The list of ticks.
-
createAndAddEntity
protected void createAndAddEntity(double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) Creates an entity for the axis and adds it to the rendering info. IfplotStateisnull, this means that rendering info is not being collected so this method simply returns without doing anything.- Parameters:
cursor- the initial cursor value.state- the axis state after completion of the drawing with a possibly updated cursor position.dataArea- the data area.edge- the edge (nullnot permitted).plotState- the PlotRenderingInfo from which a reference to the entity collection can be obtained (nullpermitted).
-
addChangeListener
Registers an object for notification of changes to the axis.- Parameters:
listener- the object that is being registered.- See Also:
-
removeChangeListener
Deregisters an object for notification of changes to the axis.- Parameters:
listener- the object to deregister.- See Also:
-
hasListener
Returnstrueif the specified object is registered with the dataset as a listener. Most applications won't need to call this method, it exists mainly for use by unit testing code.- Parameters:
listener- the listener.- Returns:
- A boolean.
-
notifyListeners
Notifies all registered listeners that the axis has changed. The AxisChangeEvent provides information about the change.- Parameters:
event- information about the change to the axis.
-
fireChangeEvent
Sends anAxisChangeEventto all registered listeners. -
getLabelEnclosure
Returns a rectangle that encloses the axis label. This is typically used for layout purposes (it gives the maximum dimensions of the label).- Parameters:
g2- the graphics device.edge- the edge of the plot area along which the axis is measuring.- Returns:
- The enclosing rectangle.
-
labelLocationX
Returns the x-coordinate for the point to which the axis label should be aligned.- Parameters:
location- the axis label location (nullnot permitted).dataArea- the display area in which the data will be rendered (nullnot permitted).- Returns:
- The x-coordinate.
-
labelLocationY
Returns the y-coordinate for the point to which the axis label should be aligned.- Parameters:
location- the location (nullnot permitted).dataArea- the data area (nullnot permitted).- Returns:
- The y-coordinate.
-
labelAnchorH
Returns the appropriate horizontal text anchor for the specified axis location.- Parameters:
location- the location (nullnot permitted).- Returns:
- The text anchor (never
null).
-
labelAnchorV
Returns the appropriate vertical text anchor for the specified axis location.- Parameters:
location- the location (nullnot permitted).- Returns:
- The text anchor (never
null).
-
drawLabel
protected AxisState drawLabel(String label, Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state) Draws the axis label.- Parameters:
label- the label text.g2- the graphics device.plotArea- the plot area.dataArea- the area inside the axes.edge- the location of the axis.state- the axis state (nullnot permitted).- Returns:
- Information about the axis.
-
drawAttributedLabel
protected AxisState drawAttributedLabel(AttributedString label, Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state) Draws the axis label.- Parameters:
label- the label text.g2- the graphics device.plotArea- the plot area.dataArea- the area inside the axes.edge- the location of the axis.state- the axis state (nullnot permitted).- Returns:
- Information about the axis.
-
drawAxisLine
Draws an axis line at the current cursor position and edge.- Parameters:
g2- the graphics device.cursor- the cursor position.dataArea- the data area.edge- the edge.
-
clone
Returns a clone of the axis.- Overrides:
clonein classObject- Returns:
- A clone.
- Throws:
CloneNotSupportedException- if some component of the axis does not support cloning.
-
equals
Tests this axis for equality with another object. -
hashCode
Returns a hash code for this instance.
-