org.jfree.chart.axis
Class HorizontalCategoryAxis

java.lang.Object
  |
  +--org.jfree.chart.axis.Axis
        |
        +--org.jfree.chart.axis.CategoryAxis
              |
              +--org.jfree.chart.axis.HorizontalCategoryAxis
All Implemented Interfaces:
AxisConstants, HorizontalAxis, java.io.Serializable
Direct Known Subclasses:
HorizontalCategoryAxis3D

public class HorizontalCategoryAxis
extends CategoryAxis
implements HorizontalAxis, java.io.Serializable

A horizontal axis that displays categories. Used for bar charts and line charts.

Note: the axis needs to rely on the plot for assistance with the placement of category labels, since the plot controls how the categories are distributed.

Author:
David Gilbert
See Also:
Serialized Form

Field Summary
static boolean DEFAULT_VERTICAL_CATEGORY_LABELS
          The default setting for vertical category labels.
 
Fields inherited from class org.jfree.chart.axis.CategoryAxis
DEFAULT_AXIS_MARGIN, DEFAULT_CATEGORY_MARGIN
 
Fields inherited from interface org.jfree.chart.axis.AxisConstants
BOTTOM, DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE, DEFAULT_TICK_MARKS_VISIBLE, LEFT, RIGHT, TOP
 
Constructor Summary
HorizontalCategoryAxis(java.lang.String label)
          Creates a new axis using default attribute values.
 
Method Summary
 void configure()
          Configures the axis against the current plot.
 void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, int location)
          Draws the axis on a Java 2D graphics device (such as the screen or a printer).
 boolean equals(java.lang.Object obj)
          Tests this axis for equality with another object.
 double getCategoryEnd(int category, int categoryCount, java.awt.geom.Rectangle2D area)
          Returns the end coordinate for the specified category.
 double getCategoryMiddle(int category, int categoryCount, java.awt.geom.Rectangle2D area)
          Returns the middle coordinate for the specified category.
 double getCategoryStart(int category, int categoryCount, java.awt.geom.Rectangle2D area)
          Returns the starting coordinate for the specified category.
protected  double getMaxTickLabelWidth(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea)
          Returns the maximum width of the ticks in the working list (that is set up by refreshTicks()).
 boolean getSkipCategoryLabelsToFit()
          Returns the flag that determines whether the category labels are to be skipped to avoid overlapping.
 boolean getVerticalCategoryLabels()
          Returns a flag indicating whether the category labels are drawn 'vertically'.
protected  boolean isCompatiblePlot(Plot plot)
          Returns true if the specified plot is compatible with the axis.
 void refreshTicks(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, int location)
          Creates a temporary list of ticks that can be used when drawing the axis.
 double reserveHeight(java.awt.Graphics2D g2, Plot plot, java.awt.geom.Rectangle2D drawArea, int location)
          Estimates the height required for the axis, given a specific drawing area, without any information about the width of the vertical axis.
 double reserveHeight(java.awt.Graphics2D g2, Plot plot, java.awt.geom.Rectangle2D drawArea, int location, double reservedWidth, int verticalAxisLocation)
          Returns the area required to draw the axis in the specified draw area.
 void setSkipCategoryLabelsToFit(boolean flag)
          Sets the flag that determines whether the category labels are to be skipped to avoid overlapping.
 void setVerticalCategoryLabels(boolean flag)
          Sets the flag that determines whether the category labels are drawn 'vertically'.
 void setVerticalTickLabels(boolean flag)
          Sets the flag that determines whether the category labels are drawn 'vertically'.
 
Methods inherited from class org.jfree.chart.axis.CategoryAxis
getCategoryMargin, getLowerMargin, getUpperMargin, setCategoryMargin, setLowerMargin, setUpperMargin
 
Methods inherited from class org.jfree.chart.axis.Axis
addChangeListener, drawHorizontalLabel, drawVerticalLabel, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, getTicks, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, removeChangeListener, setFixedDimension, setLabel, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_VERTICAL_CATEGORY_LABELS

public static final boolean DEFAULT_VERTICAL_CATEGORY_LABELS
The default setting for vertical category labels.

See Also:
Constant Field Values
Constructor Detail

HorizontalCategoryAxis

public HorizontalCategoryAxis(java.lang.String label)
Creates a new axis using default attribute values.

Parameters:
label - the axis label (null permitted).
Method Detail

getVerticalCategoryLabels

public boolean getVerticalCategoryLabels()
Returns a flag indicating whether the category labels are drawn 'vertically'.

Returns:
the flag.

setVerticalCategoryLabels

public void setVerticalCategoryLabels(boolean flag)
Sets the flag that determines whether the category labels are drawn 'vertically'.

Parameters:
flag - the new value of the flag.

setVerticalTickLabels

public void setVerticalTickLabels(boolean flag)
Sets the flag that determines whether the category labels are drawn 'vertically'.

You should use the setVerticalCategoryLabels method - this method just passed over to it anyway.

Parameters:
flag - the new value of the flag.

getSkipCategoryLabelsToFit

public boolean getSkipCategoryLabelsToFit()
Returns the flag that determines whether the category labels are to be skipped to avoid overlapping.

Returns:
The flag.

setSkipCategoryLabelsToFit

public void setSkipCategoryLabelsToFit(boolean flag)
Sets the flag that determines whether the category labels are to be skipped to avoid overlapping.

Parameters:
flag - the new value of the flag.

getCategoryStart

public double getCategoryStart(int category,
                               int categoryCount,
                               java.awt.geom.Rectangle2D area)
Returns the starting coordinate for the specified category.

Specified by:
getCategoryStart in class CategoryAxis
Parameters:
category - the category.
categoryCount - the number of categories.
area - the data area.
Returns:
the coordinate.

getCategoryMiddle

public double getCategoryMiddle(int category,
                                int categoryCount,
                                java.awt.geom.Rectangle2D area)
Returns the middle coordinate for the specified category.

Specified by:
getCategoryMiddle in class CategoryAxis
Parameters:
category - the category.
categoryCount - the number of categories.
area - the data area.
Returns:
the coordinate.

getCategoryEnd

public double getCategoryEnd(int category,
                             int categoryCount,
                             java.awt.geom.Rectangle2D area)
Returns the end coordinate for the specified category.

Specified by:
getCategoryEnd in class CategoryAxis
Parameters:
category - the category.
categoryCount - the number of categories.
area - the data area.
Returns:
the coordinate.

draw

public void draw(java.awt.Graphics2D g2,
                 java.awt.geom.Rectangle2D plotArea,
                 java.awt.geom.Rectangle2D dataArea,
                 int location)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).

Specified by:
draw in class Axis
Parameters:
g2 - the graphics device.
plotArea - the area within which the axis should be drawn.
dataArea - the area within which the plot is being drawn.
location - the location of the axis (TOP or BOTTOM).

refreshTicks

public void refreshTicks(java.awt.Graphics2D g2,
                         java.awt.geom.Rectangle2D plotArea,
                         java.awt.geom.Rectangle2D dataArea,
                         int location)
Creates a temporary list of ticks that can be used when drawing the axis.

Specified by:
refreshTicks in class Axis
Parameters:
g2 - the graphics device (used to get font measurements).
plotArea - the area where the plot and axes will be drawn.
dataArea - the area inside the axes.
location - the location of the axis.

reserveHeight

public double reserveHeight(java.awt.Graphics2D g2,
                            Plot plot,
                            java.awt.geom.Rectangle2D drawArea,
                            int location)
Estimates the height required for the axis, given a specific drawing area, without any information about the width of the vertical axis.

Supports the HorizontalAxis interface.

Specified by:
reserveHeight in interface HorizontalAxis
Parameters:
g2 - the graphics device (used to obtain font information).
plot - the plot that the axis belongs to.
drawArea - the area within which the axis should be drawn.
location - the axis location (top or bottom).
Returns:
the estimated height required for the axis.

reserveHeight

public double reserveHeight(java.awt.Graphics2D g2,
                            Plot plot,
                            java.awt.geom.Rectangle2D drawArea,
                            int location,
                            double reservedWidth,
                            int verticalAxisLocation)
Returns the area required to draw the axis in the specified draw area.

Specified by:
reserveHeight in interface HorizontalAxis
Parameters:
g2 - the graphics device.
plot - the plot that the axis belongs to.
drawArea - the area within which the plot should be drawn.
location - the location of the axis.
reservedWidth - the width reserved by the vertical axis.
verticalAxisLocation - the location of the vertical axis.
Returns:
the area required to draw the axis in the specified draw area.

getMaxTickLabelWidth

protected double getMaxTickLabelWidth(java.awt.Graphics2D g2,
                                      java.awt.geom.Rectangle2D plotArea)
Returns the maximum width of the ticks in the working list (that is set up by refreshTicks()).

Overrides:
getMaxTickLabelWidth in class Axis
Parameters:
g2 - the graphics device.
plotArea - the area within which the plot is to be drawn.
Returns:
the maximum width of the ticks in the working list.

isCompatiblePlot

protected boolean isCompatiblePlot(Plot plot)
Returns true if the specified plot is compatible with the axis.

Specified by:
isCompatiblePlot in class Axis
Parameters:
plot - The plot.
Returns:
true if the specified plot is compatible with the axis.

configure

public void configure()
Configures the axis against the current plot. Nothing required in this class.

Specified by:
configure in class Axis

equals

public boolean equals(java.lang.Object obj)
Tests this axis for equality with another object.

Overrides:
equals in class CategoryAxis
Parameters:
obj - the object.
Returns:
true or false.