Class NumberAxis
- java.lang.Object
-
- org.jfree.chart.axis.Axis
-
- org.jfree.chart.axis.ValueAxis
-
- org.jfree.chart.axis.NumberAxis
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,PublicCloneable
- Direct Known Subclasses:
CyclicNumberAxis
,LogarithmicAxis
,ModuloAxis
,SymbolAxis
public class NumberAxis extends ValueAxis implements java.lang.Cloneable, java.io.Serializable
An axis for displaying numerical data.If the axis is set up to automatically determine its range to fit the data, you can ensure that the range includes zero (statisticians usually prefer this) by setting the
autoRangeIncludesZero
flag totrue
.The
NumberAxis
class has a mechanism for automatically selecting a tick unit that is appropriate for the current axis range.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
autoRangeIncludesZero
A flag that affects the axis range when the range is determined automatically.private boolean
autoRangeStickyZero
A flag that affects the size of the margins added to the axis range when the range is determined automatically.static boolean
DEFAULT_AUTO_RANGE_INCLUDES_ZERO
The default value for the autoRangeIncludesZero flag.static boolean
DEFAULT_AUTO_RANGE_STICKY_ZERO
The default value for the autoRangeStickyZero flag.static NumberTickUnit
DEFAULT_TICK_UNIT
The default tick unit.static boolean
DEFAULT_VERTICAL_TICK_LABELS
The default setting for the vertical tick labels flag.private MarkerAxisBand
markerBand
An optional band for marking regions on the axis.private java.text.NumberFormat
numberFormatOverride
The override number format.private RangeType
rangeType
The range type (can be used to force the axis to display only positive values or only negative values).private static long
serialVersionUID
For serialization.private NumberTickUnit
tickUnit
The tick unit for the axis.-
Fields inherited from class org.jfree.chart.axis.ValueAxis
DEFAULT_AUTO_RANGE, DEFAULT_AUTO_RANGE_MINIMUM_SIZE, DEFAULT_AUTO_TICK_UNIT_SELECTION, DEFAULT_INVERTED, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT
-
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 NumberAxis()
Default constructor.NumberAxis(java.lang.String label)
Constructs a number axis, using default values where necessary.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
autoAdjustRange()
Rescales the axis to ensure that all data is visible.protected double
calculateHighestVisibleTickValue()
Calculates the value of the highest visible tick on the axis.protected double
calculateLowestVisibleTickValue()
Calculates the value of the lowest visible tick on the axis.protected int
calculateVisibleTickCount()
Calculates the number of visible ticks.java.lang.Object
clone()
Returns a clone of the axis.void
configure()
Configures the axis to work with the specified plot.static TickUnitSource
createIntegerTickUnits()
Returns a collection of tick units for integer values.static TickUnitSource
createIntegerTickUnits(java.util.Locale locale)
Returns a collection of tick units for integer values.static TickUnitSource
createStandardTickUnits()
Creates the standard tick units.static TickUnitSource
createStandardTickUnits(java.util.Locale locale)
Creates a collection of standard tick units.AxisState
draw(java.awt.Graphics2D g2, double cursor, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).boolean
equals(java.lang.Object obj)
Tests the axis for equality with an arbitrary object.protected double
estimateMaximumTickLabelHeight(java.awt.Graphics2D g2)
Estimates the maximum tick label height.protected double
estimateMaximumTickLabelWidth(java.awt.Graphics2D g2, TickUnit unit)
Estimates the maximum width of the tick labels, assuming the specified tick unit is used.boolean
getAutoRangeIncludesZero()
Returns the flag that indicates whether or not the automatic axis range (if indeed it is determined automatically) is forced to include zero.boolean
getAutoRangeStickyZero()
Returns a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.MarkerAxisBand
getMarkerBand()
Returns the (optional) marker band for the axis.java.text.NumberFormat
getNumberFormatOverride()
Returns the number format override.RangeType
getRangeType()
Returns the axis range type.NumberTickUnit
getTickUnit()
Returns the tick unit for the axis.int
hashCode()
Returns a hash code for this object.double
java2DToValue(double java2DValue, java.awt.geom.Rectangle2D area, RectangleEdge edge)
Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.java.util.List
refreshTicks(java.awt.Graphics2D g2, AxisState state, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).protected java.util.List
refreshTicksHorizontal(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).protected java.util.List
refreshTicksVertical(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).protected void
selectAutoTickUnit(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Selects an appropriate tick value for the axis.protected void
selectHorizontalAutoTickUnit(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Selects an appropriate tick value for the axis.protected void
selectVerticalAutoTickUnit(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Selects an appropriate tick value for the axis.void
setAutoRangeIncludesZero(boolean flag)
Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.void
setAutoRangeStickyZero(boolean flag)
Sets a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.void
setMarkerBand(MarkerAxisBand band)
Sets the marker band for the axis.void
setNumberFormatOverride(java.text.NumberFormat formatter)
Sets the number format override.void
setRangeType(RangeType rangeType)
Sets the axis range type.void
setTickUnit(NumberTickUnit unit)
Sets the tick unit for the axis and sends anAxisChangeEvent
to all registered listeners.void
setTickUnit(NumberTickUnit unit, boolean notify, boolean turnOffAutoSelect)
Sets the tick unit for the axis and, if requested, sends anAxisChangeEvent
to all registered listeners.double
valueToJava2D(double value, java.awt.geom.Rectangle2D area, RectangleEdge edge)
Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.-
Methods inherited from class org.jfree.chart.axis.ValueAxis
calculateAnchorPoint, centerRange, drawAxisLine, drawTickMarksAndLabels, findMaximumTickLabelHeight, findMaximumTickLabelWidth, getAutoRangeMinimumSize, getAutoTickIndex, getDefaultAutoRange, getDownArrow, getFixedAutoRange, getLeftArrow, getLowerBound, getLowerMargin, getMinorTickCount, getRange, getRightArrow, getStandardTickUnits, getUpArrow, getUpperBound, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isInverted, isNegativeArrowVisible, isPositiveArrowVisible, isVerticalTickLabels, lengthToJava2D, pan, reserveSpace, resizeRange, resizeRange, resizeRange2, setAutoRange, setAutoRange, setAutoRangeMinimumSize, setAutoRangeMinimumSize, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelection, setDefaultAutoRange, setDownArrow, setFixedAutoRange, setInverted, setLeftArrow, setLowerBound, setLowerMargin, setMinorTickCount, setNegativeArrowVisible, setPositiveArrowVisible, setRange, setRange, setRange, setRangeAboutValue, setRangeWithMargins, setRangeWithMargins, setRangeWithMargins, setRightArrow, setStandardTickUnits, setUpArrow, setUpperBound, setUpperMargin, setVerticalTickLabels, zoomRange
-
Methods inherited from class org.jfree.chart.axis.Axis
addChangeListener, createAndAddEntity, createAttributedLabel, drawAttributedLabel, drawLabel, fireChangeEvent, getAttributedLabel, getAxisLinePaint, getAxisLineStroke, getFixedDimension, getLabel, getLabelAngle, getLabelEnclosure, getLabelFont, getLabelInsets, getLabelLocation, getLabelPaint, getMinorTickMarkInsideLength, getMinorTickMarkOutsideLength, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, hasListener, isAxisLineVisible, isMinorTickMarksVisible, isTickLabelsVisible, isTickMarksVisible, isVisible, labelAnchorH, labelAnchorV, labelLocationX, labelLocationY, notifyListeners, removeChangeListener, setAttributedLabel, setAttributedLabel, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setFixedDimension, setLabel, setLabelAngle, setLabelFont, setLabelInsets, setLabelInsets, setLabelLocation, setLabelPaint, setMinorTickMarkInsideLength, setMinorTickMarkOutsideLength, setMinorTickMarksVisible, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
For serialization.- See Also:
- Constant Field Values
-
DEFAULT_AUTO_RANGE_INCLUDES_ZERO
public static final boolean DEFAULT_AUTO_RANGE_INCLUDES_ZERO
The default value for the autoRangeIncludesZero flag.- See Also:
- Constant Field Values
-
DEFAULT_AUTO_RANGE_STICKY_ZERO
public static final boolean DEFAULT_AUTO_RANGE_STICKY_ZERO
The default value for the autoRangeStickyZero flag.- See Also:
- Constant Field Values
-
DEFAULT_TICK_UNIT
public static final NumberTickUnit DEFAULT_TICK_UNIT
The default tick unit.
-
DEFAULT_VERTICAL_TICK_LABELS
public static final boolean DEFAULT_VERTICAL_TICK_LABELS
The default setting for the vertical tick labels flag.- See Also:
- Constant Field Values
-
rangeType
private RangeType rangeType
The range type (can be used to force the axis to display only positive values or only negative values).
-
autoRangeIncludesZero
private boolean autoRangeIncludesZero
A flag that affects the axis range when the range is determined automatically. If the auto range does NOT include zero and this flag is TRUE, then the range is changed to include zero.
-
autoRangeStickyZero
private boolean autoRangeStickyZero
A flag that affects the size of the margins added to the axis range when the range is determined automatically. If the value 0 falls within the margin and this flag is TRUE, then the margin is truncated at zero.
-
tickUnit
private NumberTickUnit tickUnit
The tick unit for the axis.
-
numberFormatOverride
private java.text.NumberFormat numberFormatOverride
The override number format.
-
markerBand
private MarkerAxisBand markerBand
An optional band for marking regions on the axis.
-
-
Method Detail
-
getRangeType
public RangeType getRangeType()
Returns the axis range type.- Returns:
- The axis range type (never
null
). - See Also:
setRangeType(RangeType)
-
setRangeType
public void setRangeType(RangeType rangeType)
Sets the axis range type.- Parameters:
rangeType
- the range type (null
not permitted).- See Also:
getRangeType()
-
getAutoRangeIncludesZero
public boolean getAutoRangeIncludesZero()
Returns the flag that indicates whether or not the automatic axis range (if indeed it is determined automatically) is forced to include zero.- Returns:
- The flag.
-
setAutoRangeIncludesZero
public void setAutoRangeIncludesZero(boolean flag)
Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.If the flag is changed to
true
, the axis range is recalculated.Any change to the flag will trigger an
AxisChangeEvent
.- Parameters:
flag
- the new value of the flag.- See Also:
getAutoRangeIncludesZero()
-
getAutoRangeStickyZero
public boolean getAutoRangeStickyZero()
Returns a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.- Returns:
- The flag.
- See Also:
setAutoRangeStickyZero(boolean)
-
setAutoRangeStickyZero
public void setAutoRangeStickyZero(boolean flag)
Sets a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.- Parameters:
flag
- the new flag.- See Also:
getAutoRangeStickyZero()
-
getTickUnit
public NumberTickUnit getTickUnit()
Returns the tick unit for the axis.Note: if the
autoTickUnitSelection
flag istrue
the tick unit may be changed while the axis is being drawn, so in that case the return value from this method may be irrelevant if the method is called before the axis has been drawn.- Returns:
- The tick unit for the axis.
- See Also:
setTickUnit(NumberTickUnit)
,ValueAxis.isAutoTickUnitSelection()
-
setTickUnit
public void setTickUnit(NumberTickUnit unit)
Sets the tick unit for the axis and sends anAxisChangeEvent
to all registered listeners. A side effect of calling this method is that the "auto-select" feature for tick units is switched off (you can restore it using theValueAxis.setAutoTickUnitSelection(boolean)
method).- Parameters:
unit
- the new tick unit (null
not permitted).- See Also:
getTickUnit()
,setTickUnit(NumberTickUnit, boolean, boolean)
-
setTickUnit
public void setTickUnit(NumberTickUnit unit, boolean notify, boolean turnOffAutoSelect)
Sets the tick unit for the axis and, if requested, sends anAxisChangeEvent
to all registered listeners. In addition, an option is provided to turn off the "auto-select" feature for tick units (you can restore it using theValueAxis.setAutoTickUnitSelection(boolean)
method).- Parameters:
unit
- the new tick unit (null
not permitted).notify
- notify listeners?turnOffAutoSelect
- turn off the auto-tick selection?
-
getNumberFormatOverride
public java.text.NumberFormat getNumberFormatOverride()
Returns the number format override. If this is non-null, then it will be used to format the numbers on the axis.- Returns:
- The number formatter (possibly
null
). - See Also:
setNumberFormatOverride(NumberFormat)
-
setNumberFormatOverride
public void setNumberFormatOverride(java.text.NumberFormat formatter)
Sets the number format override. If this is non-null, then it will be used to format the numbers on the axis.- Parameters:
formatter
- the number formatter (null
permitted).- See Also:
getNumberFormatOverride()
-
getMarkerBand
public MarkerAxisBand getMarkerBand()
Returns the (optional) marker band for the axis.- Returns:
- The marker band (possibly
null
). - See Also:
setMarkerBand(MarkerAxisBand)
-
setMarkerBand
public void setMarkerBand(MarkerAxisBand band)
Sets the marker band for the axis.The marker band is optional, leave it set to
null
if you don't require it.- Parameters:
band
- the new band (null
permitted).- See Also:
getMarkerBand()
-
configure
public void configure()
Configures the axis to work with the specified plot. If the axis has auto-scaling, then sets the maximum and minimum values.
-
autoAdjustRange
protected void autoAdjustRange()
Rescales the axis to ensure that all data is visible.- Specified by:
autoAdjustRange
in classValueAxis
-
valueToJava2D
public double valueToJava2D(double value, java.awt.geom.Rectangle2D area, RectangleEdge edge)
Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.Note that it is possible for the coordinate to fall outside the plotArea.
- Specified by:
valueToJava2D
in classValueAxis
- Parameters:
value
- the data value.area
- the area for plotting the data.edge
- the axis location.- Returns:
- The Java2D coordinate.
- See Also:
java2DToValue(double, Rectangle2D, RectangleEdge)
-
java2DToValue
public double java2DToValue(double java2DValue, java.awt.geom.Rectangle2D area, RectangleEdge edge)
Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.- Specified by:
java2DToValue
in classValueAxis
- Parameters:
java2DValue
- the coordinate in Java2D space.area
- the area in which the data is plotted.edge
- the location.- Returns:
- The data value.
- See Also:
valueToJava2D(double, Rectangle2D, RectangleEdge)
-
calculateLowestVisibleTickValue
protected double calculateLowestVisibleTickValue()
Calculates the value of the lowest visible tick on the axis.- Returns:
- The value of the lowest visible tick on the axis.
- See Also:
calculateHighestVisibleTickValue()
-
calculateHighestVisibleTickValue
protected double calculateHighestVisibleTickValue()
Calculates the value of the highest visible tick on the axis.- Returns:
- The value of the highest visible tick on the axis.
- See Also:
calculateLowestVisibleTickValue()
-
calculateVisibleTickCount
protected int calculateVisibleTickCount()
Calculates the number of visible ticks.- Returns:
- The number of visible ticks on the axis.
-
draw
public AxisState draw(java.awt.Graphics2D g2, double cursor, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).- Specified by:
draw
in classAxis
- Parameters:
g2
- the graphics device (null
not permitted).cursor
- the cursor location.plotArea
- the area within which the axes and data should be drawn (null
not permitted).dataArea
- the area within which the data should be drawn (null
not permitted).edge
- the location of the axis (null
not permitted).plotState
- collects information about the plot (null
permitted).- Returns:
- The axis state (never
null
).
-
createStandardTickUnits
public static TickUnitSource createStandardTickUnits()
Creates the standard tick units.If you don't like these defaults, create your own instance of TickUnits and then pass it to the setStandardTickUnits() method in the NumberAxis class.
- Returns:
- The standard tick units.
- See Also:
ValueAxis.setStandardTickUnits(TickUnitSource)
,createIntegerTickUnits()
-
createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits()
Returns a collection of tick units for integer values.- Returns:
- A collection of tick units for integer values.
- See Also:
ValueAxis.setStandardTickUnits(TickUnitSource)
,createStandardTickUnits()
-
createStandardTickUnits
public static TickUnitSource createStandardTickUnits(java.util.Locale locale)
Creates a collection of standard tick units. The supplied locale is used to create the number formatter (a localised instance ofNumberFormat
).If you don't like these defaults, create your own instance of
TickUnits
and then pass it to thesetStandardTickUnits()
method.- Parameters:
locale
- the locale.- Returns:
- A tick unit collection.
- See Also:
ValueAxis.setStandardTickUnits(TickUnitSource)
-
createIntegerTickUnits
public static TickUnitSource createIntegerTickUnits(java.util.Locale locale)
Returns a collection of tick units for integer values. Uses a given Locale to create the DecimalFormats.- Parameters:
locale
- the locale to use to represent Numbers.- Returns:
- A collection of tick units for integer values.
- See Also:
ValueAxis.setStandardTickUnits(TickUnitSource)
-
estimateMaximumTickLabelHeight
protected double estimateMaximumTickLabelHeight(java.awt.Graphics2D g2)
Estimates the maximum tick label height.- Parameters:
g2
- the graphics device.- Returns:
- The maximum height.
-
estimateMaximumTickLabelWidth
protected double estimateMaximumTickLabelWidth(java.awt.Graphics2D g2, TickUnit unit)
Estimates the maximum width of the tick labels, assuming the specified tick unit is used.Rather than computing the string bounds of every tick on the axis, we just look at two values: the lower bound and the upper bound for the axis. These two values will usually be representative.
- Parameters:
g2
- the graphics device.unit
- the tick unit to use for calculation.- Returns:
- The estimated maximum width of the tick labels.
-
selectAutoTickUnit
protected void selectAutoTickUnit(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Selects an appropriate tick value for the axis. The strategy is to display as many ticks as possible (selected from an array of 'standard' tick units) without the labels overlapping.- Parameters:
g2
- the graphics device.dataArea
- the area defined by the axes.edge
- the axis location.
-
selectHorizontalAutoTickUnit
protected void selectHorizontalAutoTickUnit(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Selects an appropriate tick value for the axis. The strategy is to display as many ticks as possible (selected from an array of 'standard' tick units) without the labels overlapping.- Parameters:
g2
- the graphics device.dataArea
- the area defined by the axes.edge
- the axis location.
-
selectVerticalAutoTickUnit
protected void selectVerticalAutoTickUnit(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Selects an appropriate tick value for the axis. The strategy is to display as many ticks as possible (selected from an array of 'standard' tick units) without the labels overlapping.- Parameters:
g2
- the graphics device.dataArea
- the area in which the plot should be drawn.edge
- the axis location.
-
refreshTicks
public java.util.List refreshTicks(java.awt.Graphics2D g2, AxisState state, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).- Specified by:
refreshTicks
in classAxis
- Parameters:
g2
- the graphics device.state
- the axis state.dataArea
- the area in which the plot should be drawn.edge
- the location of the axis.- Returns:
- A list of ticks.
-
refreshTicksHorizontal
protected java.util.List refreshTicksHorizontal(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).- Parameters:
g2
- the graphics device.dataArea
- the area in which the data should be drawn.edge
- the location of the axis.- Returns:
- A list of ticks.
-
refreshTicksVertical
protected java.util.List refreshTicksVertical(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).- Parameters:
g2
- the graphics device.dataArea
- the area in which the plot should be drawn.edge
- the location of the axis.- Returns:
- A list of ticks.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a clone of the axis.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classValueAxis
- Returns:
- A clone
- Throws:
java.lang.CloneNotSupportedException
- if some component of the axis does not support cloning.
-
equals
public boolean equals(java.lang.Object obj)
Tests the axis for equality with an arbitrary object.
-
-