org.jfree.chart.axis
Class DateAxis

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

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

The base class for axes that display dates.

You will find it easier to understand how this axis works if you bear in mind that it really displays/measures integer (or long) data, where the integers are milliseconds since midnight, 1-Jan-1970. When displaying tick labels, the millisecond values are converted back to dates using a DateFormat instance.

Author:
David Gilbert
See Also:
HorizontalDateAxis, Serialized Form

Field Summary
static java.util.Date DEFAULT_ANCHOR_DATE
          The default anchor date.
static double DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS
          The default minimum auto range size.
static DateRange DEFAULT_DATE_RANGE
          The default axis range.
static DateTickUnit DEFAULT_DATE_TICK_UNIT
          The default date 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 DateAxis(java.lang.String label)
          Creates a date axis.
 
Method Summary
 java.util.Date calculateHighestVisibleTickValue(DateTickUnit unit)
          Calculates the value of the highest visible tick on the axis.
 java.util.Date calculateLowestVisibleTickValue(DateTickUnit unit)
          Calculates the value of the lowest visible tick on the axis.
static TickUnits createStandardDateTickUnits()
          Returns a collection of standard date tick units.
 java.util.Date getAnchorDate()
          Returns the anchor date for the axis.
 java.text.DateFormat getDateFormatOverride()
          Returns the date format override.
 java.util.Date getMaximumDate()
          Returns the latest date visible on the axis.
 java.util.Date getMinimumDate()
          Returns the earliest date visible on the axis.
 DateTickUnit getTickUnit()
          Returns the tick unit for the axis.
 boolean isTickMarksAtStartOfUnit()
          Returns true if the tick marks are displayed at the start of each time unit, and false if they are displayed in the middle of each time unit.
protected  java.util.Date nextStandardDate(java.util.Date date, DateTickUnit unit)
          Returns the first "standard" date (based on the specified field and units).
protected  java.util.Date previousStandardDate(java.util.Date date, DateTickUnit unit)
          Returns the previous "standard" date, for a given date and tick unit.
 void setAnchorDate(java.util.Date anchorDate)
          Sets the anchor date for the axis.
 void setAnchorValue(double value)
          Sets the anchor value.
 void setAxisRange(double lower, double upper)
          Deprecated. use setRange(double, double) method.
 void setDateFormatOverride(java.text.DateFormat formatter)
          Sets the date format override.
 void setMaximumDate(java.util.Date maximumDate)
          Sets the maximum date visible on the axis.
 void setMinimumDate(java.util.Date minimumDate)
          Sets the minimum date visible on the axis.
 void setRange(java.util.Date lower, java.util.Date upper)
          Sets the axis range.
 void setRange(double lower, double upper)
          Sets the axis range.
 void setRange(Range range)
          Sets the upper and lower bounds for the axis.
 void setTickMarksAtStartOfUnit(boolean flag)
          Sets the flag that controls whether the tick marks are displayed at the start or the middle of each tick unit.
 void setTickUnit(DateTickUnit unit)
          Sets the tick unit for the axis.
 void setTickUnit(DateTickUnit unit, boolean notify, boolean turnOffAutoSelection)
          Sets the tick unit attribute without any other side effects.
 
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, setAnchorValueAttribute, setAutoRange, setAutoRange, setAutoRangeMinimumSize, setAutoRangeMinimumSize, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelection, setFixedAutoRange, setInverted, setLowerMargin, setMaximumAxisValue, setMinimumAxisValue, 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_DATE_RANGE

public static final DateRange DEFAULT_DATE_RANGE
The default axis range.


DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS

public static final double DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS
The default minimum auto range size.

See Also:
Constant Field Values

DEFAULT_DATE_TICK_UNIT

public static final DateTickUnit DEFAULT_DATE_TICK_UNIT
The default date tick unit.


DEFAULT_ANCHOR_DATE

public static final java.util.Date DEFAULT_ANCHOR_DATE
The default anchor date.

Constructor Detail

DateAxis

protected DateAxis(java.lang.String label)
Creates a date axis.

Parameters:
label - the axis label.
Method Detail

getTickUnit

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

Returns:
the tick unit for the axis.

setTickUnit

public void setTickUnit(DateTickUnit unit)
Sets the tick unit for the axis. The auto-tick-unit-selection flag is set to false, and registered listeners are notified that the axis has been changed.

Parameters:
unit - the new tick unit.

setTickUnit

public void setTickUnit(DateTickUnit unit,
                        boolean notify,
                        boolean turnOffAutoSelection)
Sets the tick unit attribute without any other side effects.

Parameters:
unit - the new tick unit.
notify - notify registered listeners?
turnOffAutoSelection - turn off auto selection?

getDateFormatOverride

public java.text.DateFormat getDateFormatOverride()
Returns the date format override. If this is non-null, then it will be used to format the dates on the axis.

Returns:
the date format override.

setDateFormatOverride

public void setDateFormatOverride(java.text.DateFormat formatter)
Sets the date format override. If this is non-null, then it will be used to format the dates on the axis.

Parameters:
formatter - the date formatter (null permitted).

getAnchorDate

public java.util.Date getAnchorDate()
Returns the anchor date for the axis.

Returns:
the anchor date for the axis (possibly null).

setAnchorDate

public void setAnchorDate(java.util.Date anchorDate)
Sets the anchor date for the axis.

Parameters:
anchorDate - the new anchor date (null permitted).

setAnchorValue

public void setAnchorValue(double value)
Sets the anchor value.

This method keeps the anchorDate and anchorValue in synch.

Overrides:
setAnchorValue in class ValueAxis
Parameters:
value - the new value.

setRange

public void setRange(Range range)
Sets the upper and lower bounds for the axis. Registered listeners are notified of the change.

As a side-effect, the auto-range flag is set to false.

Overrides:
setRange in class ValueAxis
Parameters:
range - the new range.

setRange

public void setRange(java.util.Date lower,
                     java.util.Date upper)
Sets the axis range.

Parameters:
lower - the lower bound for the axis.
upper - the upper bound for the axis.

setRange

public void setRange(double lower,
                     double upper)
Sets the axis range.

Overrides:
setRange in class ValueAxis
Parameters:
lower - the lower bound for the axis.
upper - the upper bound for the axis.

getMinimumDate

public java.util.Date getMinimumDate()
Returns the earliest date visible on the axis.

Returns:
the earliest date visible on the axis.

setMinimumDate

public void setMinimumDate(java.util.Date minimumDate)
Sets the minimum date visible on the axis.

Parameters:
minimumDate - the new minimum date.

getMaximumDate

public java.util.Date getMaximumDate()
Returns the latest date visible on the axis.

Returns:
the latest date visible on the axis.

isTickMarksAtStartOfUnit

public boolean isTickMarksAtStartOfUnit()
Returns true if the tick marks are displayed at the start of each time unit, and false if they are displayed in the middle of each time unit.

Returns:
A boolean.

setTickMarksAtStartOfUnit

public void setTickMarksAtStartOfUnit(boolean flag)
Sets the flag that controls whether the tick marks are displayed at the start or the middle of each tick unit.

Parameters:
flag - a boolean.

setMaximumDate

public void setMaximumDate(java.util.Date maximumDate)
Sets the maximum date visible on the axis.

Parameters:
maximumDate - the new maximum date.

calculateLowestVisibleTickValue

public java.util.Date calculateLowestVisibleTickValue(DateTickUnit unit)
Calculates the value of the lowest visible tick on the axis.

Parameters:
unit - date unit to use.
Returns:
The value of the lowest visible tick on the axis.

calculateHighestVisibleTickValue

public java.util.Date calculateHighestVisibleTickValue(DateTickUnit unit)
Calculates the value of the highest visible tick on the axis.

Parameters:
unit - date unit to use.
Returns:
the value of the highest visible tick on the axis.

previousStandardDate

protected java.util.Date previousStandardDate(java.util.Date date,
                                              DateTickUnit unit)
Returns the previous "standard" date, for a given date and tick unit.

Parameters:
date - the reference date.
unit - the tick unit.
Returns:
the previous "standard" date.

nextStandardDate

protected java.util.Date nextStandardDate(java.util.Date date,
                                          DateTickUnit unit)
Returns the first "standard" date (based on the specified field and units).

Parameters:
date - the reference date.
unit - the date tick unit.
Returns:
the next "standard" date.

createStandardDateTickUnits

public static TickUnits createStandardDateTickUnits()
Returns a collection of standard date tick units. This collection will be used by default, but you are free to create your own collection if you want to (see the setStandardTickUnits(...) method inherited from the ValueAxis class).

Returns:
a collection of standard date tick units.

setAxisRange

public void setAxisRange(double lower,
                         double upper)
Deprecated. use setRange(double, double) method.

Sets the axis range.

Parameters:
lower - the lower bound for the axis.
upper - the upper bound for the axis.