com.jrefinery.chart
Class NumberAxis

java.lang.Object
  |
  +--com.jrefinery.chart.Axis
        |
        +--com.jrefinery.chart.ValueAxis
              |
              +--com.jrefinery.chart.NumberAxis
All Implemented Interfaces:
AxisConstants
Direct Known Subclasses:
HorizontalNumberAxis, VerticalNumberAxis

public abstract class NumberAxis
extends ValueAxis

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:
DG
See Also:
HorizontalNumberAxis, VerticalNumberAxis

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 com.jrefinery.chart.ValueAxis
DEFAULT_AUTO_RANGE, DEFAULT_AUTO_RANGE_MINIMUM_SIZE, DEFAULT_CROSSHAIR_PAINT, DEFAULT_CROSSHAIR_STROKE, DEFAULT_CROSSHAIR_VISIBLE, DEFAULT_GRID_LINE_PAINT, DEFAULT_GRID_LINE_STROKE, DEFAULT_LOWER_BOUND, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_BOUND, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT
 
Fields inherited from class com.jrefinery.chart.Axis
fixedDimension, label, labelFont, labelInsets, labelPaint, plot, tickLabelFont, tickLabelInsets, tickLabelPaint, tickLabelsVisible, tickMarkPaint, tickMarkStroke, tickMarksVisible, ticks, visible
 
Fields inherited from interface com.jrefinery.chart.AxisConstants
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
protected NumberAxis(java.lang.String label)
          Constructs a number axis, using default values where necessary.
protected NumberAxis(java.lang.String label, java.awt.Font labelFont, java.awt.Paint labelPaint, java.awt.Insets labelInsets, boolean tickLabelsVisible, java.awt.Font tickLabelFont, java.awt.Paint tickLabelPaint, java.awt.Insets tickLabelInsets, boolean tickMarksVisible, java.awt.Stroke tickMarkStroke, java.awt.Paint tickMarkPaint, boolean autoRange, java.lang.Number autoRangeMinimumSize, boolean autoRangeIncludesZero, boolean autoRangeStickyZero, double lowerBound, double upperBound, boolean inverted, boolean autoTickUnitSelection, NumberTickUnit tickUnit, boolean gridLinesVisible, java.awt.Stroke gridStroke, java.awt.Paint gridPaint, double anchorValue, boolean crosshairVisible, double crosshairValue, java.awt.Stroke crosshairStroke, java.awt.Paint crosshairPaint)
          Constructs a number axis.
 
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 the standard tick units, and uses a given Locale to create the DecimalFormats
 NumberTickUnit getTickUnit()
          Returns the tick unit for the axis.
 boolean isInverted()
          Returns a flag that controls the direction of values on the axis.
 void setAutoRangeIncludesZero(boolean flag)
          Sets the flag that indicates whether or not the automatic axis range 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 setInverted(boolean flag)
          Sets a flag that controls the direction of values on the axis, and notifies registered listeners that the axis has changed.
 void setTickUnit(NumberTickUnit unit)
          Sets a fixed tick unit for the axis, and notifies registered listeners that the axis has been changed.
protected  void setTickUnitAttribute(NumberTickUnit unit)
          Sets the tick unit attribute without any other side effects.
 
Methods inherited from class com.jrefinery.chart.ValueAxis
autoAdjustRange, centerRange, getAnchorValue, getAutoRangeMinimumSize, getAutoTickIndex, getCrosshairPaint, getCrosshairStroke, getCrosshairValue, getFixedAutoRange, getGridPaint, getGridStroke, getLowerMargin, getMaximumAxisValue, getMinimumAxisValue, getRange, getStandardTickUnits, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isCrosshairLockedOnData, isCrosshairVisible, isGridLinesVisible, resizeRange, resizeRange, setAnchoredRange, setAnchorValue, setAnchorValueAttribute, setAutoRange, setAutoRangeAttribute, setAutoRangeMinimumSize, setAutoRangeMinimumSizeAttribute, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelectionAttribute, setCrosshairLockedOnData, setCrosshairPaint, setCrosshairStroke, setCrosshairValue, setCrosshairValue, setCrosshairValueAttribute, setCrosshairVisible, setFixedAutoRange, setGridLinesVisible, setGridPaint, setGridStroke, setLowerMargin, setMaximumAxisValue, setMinimumAxisValue, setRange, setRange, setRangeAboutValue, setRangeAttribute, setStandardTickUnits, setUpperMargin, translateJava2DtoValue, translateValueToJava2D
 
Methods inherited from class com.jrefinery.chart.Axis
addChangeListener, configure, draw, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getMaxTickLabelWidth, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkPaint, getTickMarkStroke, isCompatiblePlot, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, refreshTicks, removeChangeListener, setFixedDimension, setLabel, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, 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.

DEFAULT_AUTO_RANGE_STICKY_ZERO

public static final boolean DEFAULT_AUTO_RANGE_STICKY_ZERO
The default value for the autoRangeStickyZero flag.

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.

NumberAxis

protected NumberAxis(java.lang.String label,
                     java.awt.Font labelFont,
                     java.awt.Paint labelPaint,
                     java.awt.Insets labelInsets,
                     boolean tickLabelsVisible,
                     java.awt.Font tickLabelFont,
                     java.awt.Paint tickLabelPaint,
                     java.awt.Insets tickLabelInsets,
                     boolean tickMarksVisible,
                     java.awt.Stroke tickMarkStroke,
                     java.awt.Paint tickMarkPaint,
                     boolean autoRange,
                     java.lang.Number autoRangeMinimumSize,
                     boolean autoRangeIncludesZero,
                     boolean autoRangeStickyZero,
                     double lowerBound,
                     double upperBound,
                     boolean inverted,
                     boolean autoTickUnitSelection,
                     NumberTickUnit tickUnit,
                     boolean gridLinesVisible,
                     java.awt.Stroke gridStroke,
                     java.awt.Paint gridPaint,
                     double anchorValue,
                     boolean crosshairVisible,
                     double crosshairValue,
                     java.awt.Stroke crosshairStroke,
                     java.awt.Paint crosshairPaint)
Constructs a number axis.
Parameters:
label - the axis label.
labelFont - the font for displaying the axis label.
labelPaint - the paint used to display the axis label.
labelInsets - the amount of blank space around the axis label.
tickLabelsVisible - flag indicating whether or not the tick labels are visible.
tickLabelFont - the font used to display the tick labels.
tickLabelPaint - the paint used to draw the tick labels.
tickLabelInsets - the amount of blank space around the tick labels.
tickMarksVisible - flag indicating whether or not tick marks are visible.
tickMarkStroke - the stroke used to draw the tick marks (if visible).
tickMarkPaint - the paint used to draw the tick marks (if visible).
autoRange - flag indicating whether or not the axis range is automatically determined.
autoRangeMinimumSize - the smallest range allowed when the axis range is calculated to fit the data.
autoRangeIncludesZero - a flag indicating whether the auto range must include zero.
autoRangeStickyZero - a flag controlling the axis margins around zero.
lowerBound - the lowest value shown on the axis.
upperBound - the highest value shown on the axis.
inverted - a flag indicating whether the axis is normal or inverted (inverted means running from positive to negative).
autoTickUnitSelection - a flag indicating whether or not the tick value is automatically selected.
tickUnit - the tick unit for the axis.
gridLinesVisible - flag indicating whether or not grid lines are visible.
gridStroke - the pen/brush used to display grid lines (if visible).
gridPaint - the color used to display grid lines (if visible).
anchorValue - the anchor value.
crosshairVisible - whether to show a crosshair.
crosshairValue - the value at which to draw the crosshair line (null permitted).
crosshairStroke - the pen/brush used to draw the data line.
crosshairPaint - the color used to draw the data line.
Method Detail

isInverted

public boolean isInverted()
Returns a flag that controls the direction of values on the axis.

For a regular axis, values increase from left to right (for a horizontal axis) and bottom to top (for a vertical axis). When the axis is 'inverted', the values increase in the opposite direction.

Returns:
the flag.

setInverted

public void setInverted(boolean flag)
Sets a flag that controls the direction of values on the axis, and notifies registered listeners that the axis has changed.
Parameters:
flag - the flag.

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 automatic axis range is forced to include zero.
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 a fixed tick unit for the axis, and notifies registered listeners that the axis has been changed.

This method also sets the autoTickUnitSelection flag to false.

Parameters:
unit - The new tick unit.

setTickUnitAttribute

protected void setTickUnitAttribute(NumberTickUnit unit)
Sets the tick unit attribute without any other side effects.
Parameters:
unit - the new tick unit.

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 the standard tick units, and uses a given Locale to create the DecimalFormats

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.

Parameters:
locale - the locale to use to represent Numbers.
Returns:
the standard tick units.

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.