org.jfree.chart.axis
Class NumberAxis

java.lang.Object
  |
  +--org.jfree.chart.axis.Axis
        |
        +--org.jfree.chart.axis.ValueAxis
              |
              +--org.jfree.chart.axis.NumberAxis
All Implemented Interfaces:
AxisConstants, java.io.Serializable
Direct Known Subclasses:
HorizontalNumberAxis, VerticalNumberAxis

public abstract class NumberAxis
extends ValueAxis
implements java.io.Serializable

The base class for axes that display 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 to true.

The NumberAxis class has a mechanism for automatically selecting a tick unit that is appropriate for the current axis range. This mechanism is an adaptation of code suggested by Laurence Vanhelsuwe.

Author:
David Gilbert
See Also:
Serialized Form

Field Summary
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.
 
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_BOUND, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_BOUND, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT
 
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
protected NumberAxis(java.lang.String label)
          Constructs a number axis, using default values where necessary.
 
Method Summary
 boolean autoRangeIncludesZero()
          Returns the flag that indicates whether or not the automatic axis range (if indeed it is determined automatically) is forced to include zero.
 boolean autoRangeStickyZero()
          Returns a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.
 double calculateHighestVisibleTickValue()
          Calculates the value of the highest visible tick on the axis.
 double calculateLowestVisibleTickValue()
          Calculates the value of the lowest visible tick on the axis.
 int calculateVisibleTickCount()
          Calculates the number of visible ticks.
static TickUnits createIntegerTickUnits()
          Returns a collection of tick units for integer values.
static TickUnits createIntegerTickUnits(java.util.Locale locale)
          Returns a collection of tick units for integer values.
static TickUnits createStandardTickUnits()
          Creates the standard tick units.
static TickUnits createStandardTickUnits(java.util.Locale locale)
          Creates a collection of standard tick units.
 java.text.NumberFormat getNumberFormatOverride()
          Returns the number format override.
 NumberTickUnit getTickUnit()
          Returns the tick unit 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 setNumberFormatOverride(java.text.NumberFormat formatter)
          Sets the number format override.
 void setTickUnit(NumberTickUnit unit)
          Sets the tick unit for the axis.
 void setTickUnit(NumberTickUnit unit, boolean notify, boolean turnOffAutoSelect)
          Sets the tick unit for the axis.
 
Methods inherited from class org.jfree.chart.axis.ValueAxis
autoAdjustRange, centerRange, getAnchorValue, getAutoRangeMinimumSize, getAutoTickIndex, getFixedAutoRange, getLowerMargin, getMaximumAxisValue, getMinimumAxisValue, getRange, getStandardTickUnits, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isInverted, resizeRange, resizeRange, setAnchoredRange, setAnchorValue, setAnchorValueAttribute, setAutoRange, setAutoRange, setAutoRangeMinimumSize, setAutoRangeMinimumSize, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelection, setFixedAutoRange, setInverted, setLowerMargin, setMaximumAxisValue, setMinimumAxisValue, setRange, setRange, setRangeAboutValue, setRangeAttribute, setStandardTickUnits, setUpperMargin, translateJava2DtoValue, translateValueToJava2D
 
Methods inherited from class org.jfree.chart.axis.Axis
addChangeListener, configure, draw, drawHorizontalLabel, drawVerticalLabel, equals, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getMaxTickLabelWidth, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, getTicks, isCompatiblePlot, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, refreshTicks, 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_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.

Constructor Detail

NumberAxis

protected NumberAxis(java.lang.String label)
Constructs a number axis, using default values where necessary.

Parameters:
label - the axis label.
Method Detail

autoRangeIncludesZero

public boolean autoRangeIncludesZero()
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.

autoRangeStickyZero

public boolean autoRangeStickyZero()
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.

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.

getTickUnit

public NumberTickUnit getTickUnit()
Returns the tick unit for the axis.

Returns:
the tick unit for the axis.

setTickUnit

public void setTickUnit(NumberTickUnit unit)
Sets the tick unit for the axis. This will turn off the auto tick unit selection mechanism (if it is on) and send an AxisChangeEvent to all registered listeners.

Parameters:
unit - the new tick unit.

setTickUnit

public void setTickUnit(NumberTickUnit unit,
                        boolean notify,
                        boolean turnOffAutoSelect)
Sets the tick unit for the axis. This will turn off the auto tick unit selection mechanism (if it is on) and, if requested, send an AxisChangeEvent to all registered listeners.

Parameters:
unit - the new tick unit.
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 format override.

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).

calculateLowestVisibleTickValue

public double calculateLowestVisibleTickValue()
Calculates the value of the lowest visible tick on the axis.

Returns:
the value of the lowest visible tick on the axis.

calculateHighestVisibleTickValue

public double calculateHighestVisibleTickValue()
Calculates the value of the highest visible tick on the axis.

Returns:
the value of the highest visible tick on the axis.

calculateVisibleTickCount

public int calculateVisibleTickCount()
Calculates the number of visible ticks.

Returns:
the number of visible ticks on the axis.

createStandardTickUnits

public static TickUnits 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.

createIntegerTickUnits

public static TickUnits createIntegerTickUnits()
Returns a collection of tick units for integer values.

Returns:
a collection of tick units for integer values.

createStandardTickUnits

public static TickUnits 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 of NumberFormat).

If you don't like these defaults, create your own instance of TickUnits and then pass it to the setStandardTickUnits(...) method.

Parameters:
locale - the locale.
Returns:
a tick unit collection.

createIntegerTickUnits

public static TickUnits 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.