Package org.jfree.chart.axis
Class CategoryAxis
java.lang.Object
org.jfree.chart.axis.Axis
org.jfree.chart.axis.CategoryAxis
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
CategoryAxis3D,ExtendedCategoryAxis,SubCategoryAxis
public class CategoryAxis extends Axis implements Cloneable, Serializable
An axis that displays categories.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static doubleDEFAULT_AXIS_MARGINThe default margin for the axis (used for both lower and upper margins).static doubleDEFAULT_CATEGORY_MARGINThe default margin between categories (a percentage of the overall axis length).Fields inherited from class org.jfree.chart.axis.Axis
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_LINE_PAINT, DEFAULT_AXIS_LINE_STROKE, 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 -
Constructor Summary
Constructors Constructor Description CategoryAxis()Creates a new category axis with no label.CategoryAxis(String label)Constructs a category axis, using default values where necessary. -
Method Summary
Modifier and Type Method Description voidaddCategoryLabelToolTip(Comparable category, String tooltip)Adds a tooltip to the specified category and sends anAxisChangeEventto all registered listeners.voidclearCategoryLabelToolTips()Clears the category label tooltips and sends anAxisChangeEventto all registered listeners.Objectclone()Creates a clone of the axis.voidconfigure()Configures the axis against the current plot.AxisStatedraw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge, PlotRenderingInfo plotState)Draws the axis on a Java 2D graphics device (such as the screen or a printer).booleanequals(Object obj)Tests this axis for equality with an arbitrary object.CategoryLabelPositiongetBottomCategoryLabelPosition()Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.BOTTOM).doublegetCategoryEnd(int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the end coordinate for the specified category.doublegetCategoryJava2DCoordinate(CategoryAnchor anchor, int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the Java 2D coordinate for a category.intgetCategoryLabelPositionOffset()Returns the offset between the axis and the category labels (before label positioning is taken into account).CategoryLabelPositionsgetCategoryLabelPositions()Returns the category label position specification (this contains label positioning info for all four possible axis locations).doublegetCategoryMargin()Returns the category margin.doublegetCategoryMiddle(int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the middle coordinate for the specified category.doublegetCategoryStart(int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the starting coordinate for the specified category.CategoryLabelPositiongetLeftCategoryLabelPosition()Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.LEFT).doublegetLowerMargin()Returns the lower margin for the axis.floatgetMaxCategoryLabelWidthRatio()Returns the category label width ratio.CategoryLabelPositiongetRightCategoryLabelPosition()Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.RIGHT).booleangetSkipCategoryLabelsToFit()Deprecated.No longer supported.CategoryLabelPositiongetTopCategoryLabelPosition()Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.TOP).doublegetUpperMargin()Returns the upper margin for the axis.booleanisVerticalCategoryLabels()Deprecated.Use the get/setXXXCategoryLabelPosition methods.ListrefreshTicks(Graphics2D g2, AxisState state, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)Creates a temporary list of ticks that can be used when drawing the axis.voidremoveCategoryLabelToolTip(Comparable category)Removes the tooltip for the specified category and sends anAxisChangeEventto all registered listeners.AxisSpacereserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, org.jfree.ui.RectangleEdge edge, AxisSpace space, boolean isOpositeAxisVisible)Estimates the space required for the axis, given a specific drawing area.voidsetBottomCategoryLabelPosition(CategoryLabelPosition position)Deprecated.Use setCategoryLabelPositions(...).voidsetCategoryLabelPositionOffset(int offset)Sets the offset between the axis and the category labels (before label positioning is taken into account).voidsetCategoryLabelPositions(CategoryLabelPositions positions)Sets the category label position specification for the axis and sends anAxisChangeEventto all registered listeners.voidsetCategoryMargin(double margin)Sets the category margin and sends anAxisChangeEventto all registered listeners.voidsetLeftCategoryLabelPosition(CategoryLabelPosition position)Deprecated.Use setCategoryLabelPositions(...).voidsetLowerMargin(double margin)Sets the lower margin for the axis and sends anAxisChangeEventto all registered listeners.voidsetMaxCategoryLabelWidthRatio(float ratio)Sets the maximum category label width ratio and sends anAxisChangeEventto all registered listeners.voidsetRightCategoryLabelPosition(CategoryLabelPosition position)Deprecated.Use setLabelPositions(...).voidsetSkipCategoryLabelsToFit(boolean flag)Deprecated.No longer supported.voidsetSkipLabels(int skipValue)voidsetTopCategoryLabelPosition(CategoryLabelPosition position)Deprecated.Use setCategoryLabelPositions(...).voidsetUpperMargin(double margin)Sets the upper margin for the axis and sends anAxisChangeEventto all registered listeners.voidsetVerticalCategoryLabels(boolean flag)Deprecated.Use the get/setXXXCategoryLabelPosition methods.Methods inherited from class org.jfree.chart.axis.Axis
addChangeListener, getAxisLinePaint, getAxisLineStroke, getFixedDimension, getLabel, getLabelAngle, getLabelFont, getLabelInsets, getLabelPaint, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, isAxisLineVisible, isTickLabelsVisible, isTickMarksVisible, isVisible, removeChangeListener, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setFixedDimension, setLabel, setLabelAngle, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
-
Field Details
-
DEFAULT_AXIS_MARGIN
public static final double DEFAULT_AXIS_MARGINThe default margin for the axis (used for both lower and upper margins).- See Also:
- Constant Field Values
-
DEFAULT_CATEGORY_MARGIN
public static final double DEFAULT_CATEGORY_MARGINThe default margin between categories (a percentage of the overall axis length).- See Also:
- Constant Field Values
-
-
Constructor Details
-
CategoryAxis
public CategoryAxis()Creates a new category axis with no label. -
CategoryAxis
Constructs a category axis, using default values where necessary.- Parameters:
label- the axis label (nullpermitted).
-
-
Method Details
-
getLowerMargin
public double getLowerMargin()Returns the lower margin for the axis.- Returns:
- the margin.
-
setLowerMargin
public void setLowerMargin(double margin)Sets the lower margin for the axis and sends anAxisChangeEventto all registered listeners.- Parameters:
margin- the margin as a percentage of the axis length (for example, 0.05 is five percent).
-
getUpperMargin
public double getUpperMargin()Returns the upper margin for the axis.- Returns:
- the margin.
-
setUpperMargin
public void setUpperMargin(double margin)Sets the upper margin for the axis and sends anAxisChangeEventto all registered listeners.- Parameters:
margin- the margin as a percentage of the axis length (for example, 0.05 is five percent).
-
getCategoryMargin
public double getCategoryMargin()Returns the category margin.- Returns:
- the margin.
-
setCategoryMargin
public void setCategoryMargin(double margin)Sets the category margin and sends anAxisChangeEventto all registered listeners.The overall category margin is distributed over N-1 gaps, where N is the number of categories on the axis.
- Parameters:
margin- the margin as a percentage of the axis length (for example, 0.05 is five percent).
-
getMaxCategoryLabelWidthRatio
public float getMaxCategoryLabelWidthRatio()Returns the category label width ratio.- Returns:
- the ratio.
-
setMaxCategoryLabelWidthRatio
public void setMaxCategoryLabelWidthRatio(float ratio)Sets the maximum category label width ratio and sends anAxisChangeEventto all registered listeners.- Parameters:
ratio- the ratio.
-
getCategoryLabelPositionOffset
public int getCategoryLabelPositionOffset()Returns the offset between the axis and the category labels (before label positioning is taken into account).- Returns:
- the offset (in Java2D units).
-
setCategoryLabelPositionOffset
public void setCategoryLabelPositionOffset(int offset)Sets the offset between the axis and the category labels (before label positioning is taken into account).- Parameters:
offset- the offset (in Java2D units).
-
getCategoryLabelPositions
Returns the category label position specification (this contains label positioning info for all four possible axis locations).- Returns:
- the positions (never
null).
-
setCategoryLabelPositions
Sets the category label position specification for the axis and sends anAxisChangeEventto all registered listeners.- Parameters:
positions- the positions (nullnot permitted).
-
addCategoryLabelToolTip
Adds a tooltip to the specified category and sends anAxisChangeEventto all registered listeners.- Parameters:
category- the category (nullnot permitted). @param tooltip the tooltip text (nullpermitted).
-
removeCategoryLabelToolTip
Removes the tooltip for the specified category and sends anAxisChangeEventto all registered listeners.- Parameters:
category- the category (nullnot permitted).
-
clearCategoryLabelToolTips
public void clearCategoryLabelToolTips()Clears the category label tooltips and sends anAxisChangeEventto all registered listeners. -
getCategoryJava2DCoordinate
public double getCategoryJava2DCoordinate(CategoryAnchor anchor, int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the Java 2D coordinate for a category.- Parameters:
anchor- the anchor point.category- the category index.categoryCount- the category count.area- the data area.edge- the location of the axis.- Returns:
- the coordinate.
-
getCategoryStart
public double getCategoryStart(int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the starting coordinate for the specified category.- Parameters:
category- the category.categoryCount- the number of categories.area- the data area.edge- the axis location.- Returns:
- the coordinate.
-
getCategoryMiddle
public double getCategoryMiddle(int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the middle coordinate for the specified category.- Parameters:
category- the category.categoryCount- the number of categories.area- the data area.edge- the axis location.- Returns:
- the coordinate.
-
getCategoryEnd
public double getCategoryEnd(int category, int categoryCount, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Returns the end coordinate for the specified category.- Parameters:
category- the category.categoryCount- the number of categories.area- the data area.edge- the axis location.- Returns:
- the coordinate.
-
reserveSpace
public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, org.jfree.ui.RectangleEdge edge, AxisSpace space, boolean isOpositeAxisVisible)Estimates the space required for the axis, given a specific drawing area.- Specified by:
reserveSpacein classAxis- Parameters:
g2- the graphics device (used to obtain font information).plot- the plot that the axis belongs to.plotArea- the area within which the axis should be drawn.edge- the axis location (top or bottom).space- the space already reserved.- Returns:
- The space required to draw the axis.
-
configure
public void configure()Configures the axis against the current plot. -
draw
public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge, PlotRenderingInfo plotState)Draws the axis on a Java 2D graphics device (such as the screen or a printer).- Specified by:
drawin classAxis- Parameters:
g2- the graphics device (nullnot permitted).cursor- the cursor location.plotArea- the area within which the axis should be drawn (nullnot permitted).dataArea- the area within which the plot is being drawn (nullnot permitted).edge- the location of the axis (nullnot permitted).plotState- collects information about the plot (nullpermitted).- Returns:
- the axis state (never
null).
-
setSkipLabels
public void setSkipLabels(int skipValue) -
refreshTicks
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)Creates a temporary list of ticks that can be used when drawing the axis.- Specified by:
refreshTicksin classAxis- Parameters:
g2- the graphics device (used to get font measurements).state- the axis state.plotArea- the area where the plot and axes will be drawn.dataArea- the area inside the axes.edge- the location of the axis.- Returns:
- A list of ticks.
-
clone
Creates a clone of the axis.- Overrides:
clonein classAxis- Returns:
- a clone.
- Throws:
CloneNotSupportedException- if some component of the axis does not support cloning.
-
equals
Tests this axis for equality with an arbitrary object. -
isVerticalCategoryLabels
public boolean isVerticalCategoryLabels()Deprecated.Use the get/setXXXCategoryLabelPosition methods.Returns a flag indicating whether the category labels are rotated to vertical.- Returns:
- The flag.
-
setVerticalCategoryLabels
public void setVerticalCategoryLabels(boolean flag)Deprecated.Use the get/setXXXCategoryLabelPosition methods.Sets the flag that determines whether the category labels are rotated to vertical.- Parameters:
flag- the flag.
-
getSkipCategoryLabelsToFit
public boolean getSkipCategoryLabelsToFit()Deprecated.No longer supported.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)Deprecated.No longer supported.Sets the flag that determines whether the category labels are to be skipped to avoid overlapping.- Parameters:
flag- the new value of the flag.
-
getTopCategoryLabelPosition
Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.TOP).Returns the category label positioning info that applies when the axis is displayed at the top of the plot area.- Returns:
- the position info.
-
setTopCategoryLabelPosition
Deprecated.Use setCategoryLabelPositions(...).Sets the position info that applies when the axis is displayed at the top of the plot area.- Parameters:
position- the position info.
-
getBottomCategoryLabelPosition
Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.BOTTOM).Returns the category label positioning info that applies when the axis is displayed at the bottom of the plot area.- Returns:
- the position info.
-
setBottomCategoryLabelPosition
Deprecated.Use setCategoryLabelPositions(...).Sets the position info that applies when the axis is displayed at the bottom of the plot area.- Parameters:
position- the position info.
-
getLeftCategoryLabelPosition
Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.LEFT).Returns the category label positioning info that applies when the axis is displayed at the left of the plot area.- Returns:
- the position info.
-
setLeftCategoryLabelPosition
Deprecated.Use setCategoryLabelPositions(...).Sets the position info that applies when the axis is displayed at the left of the plot area.- Parameters:
position- the position info.
-
getRightCategoryLabelPosition
Deprecated.Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.RIGHT).Returns the category label positioning info that applies when the axis is displayed at the right of the plot area.- Returns:
- the position info.
-
setRightCategoryLabelPosition
Deprecated.Use setLabelPositions(...).Sets the position info that applies when the axis is displayed at the right of the plot area.- Parameters:
position- the position info.
-