Class DateAxis
- All Implemented Interfaces:
Serializable
,Cloneable
,PublicCloneable
DateFormat
instance.
You can also create a Timeline
and supply in
the constructor to create an axis that only contains certain domain values.
For example, this allows you to create a date axis that only contains
working days.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A timeline that includes all milliseconds (as defined byjava.util.Date
) in the real time line. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DateFormat
The override date format.static final Date
The default anchor date.static final double
The default minimum auto range size.static final DateRange
The default axis range.private static final Timeline
A static default timeline shared by all standard DateAxisprivate Locale
The locale for the axis (null
is not permitted).private static final long
For serialization.private DateTickMarkPosition
Tick marks can be displayed at the start or the middle of the time period.private DateTickUnit
The current tick unit.private Timeline
Our underlying timeline.private TimeZone
The time zone 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Rescales the axis to ensure that all data is visible.private Date
calculateDateForPosition
(RegularTimePeriod period, DateTickMarkPosition position) Returns aDate
corresponding to the specified position within aRegularTimePeriod
.Calculates the value of the highest visible tick on the axis.Calculates the value of the lowest visible tick on the axis.clone()
Returns a clone of the object.void
Configures the axis to work with the specified plot.private Date
correctTickDateForPosition
(Date time, DateTickUnit unit, DateTickMarkPosition position) Corrects the given tick date for the position setting.static TickUnitSource
Returns a collection of standard date tick units that uses the default time zone.static TickUnitSource
createStandardDateTickUnits
(TimeZone zone, Locale locale) Returns a collection of standard date tick units.double
dateToJava2D
(Date date, Rectangle2D area, RectangleEdge edge) Translates a date to Java2D coordinates, based on the range displayed by this axis for the specified data area.draw
(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState) Draws the axis on a Java 2D graphics device (such as the screen or a printer).boolean
Tests this axis for equality with an arbitrary object.private double
Estimates the maximum width of the tick labels, assuming the specified tick unit is used.private double
Estimates the maximum width of the tick labels, assuming the specified tick unit is used.Returns the date format override.Returns the locale for this axis.Returns the latest date visible on the axis.Returns the earliest date visible on the axis.Returns the tick mark position (start, middle or end of the time period).Returns the tick unit for the axis.Returns the underlying timeline used by this axis.Returns the time zone for the axis.int
hashCode()
Returns a hash code for this object.boolean
isHiddenValue
(long millis) Returnstrue
if the axis hides this value, andfalse
otherwise.double
java2DToValue
(double java2DValue, Rectangle2D area, RectangleEdge edge) Translates a Java2D coordinate into the corresponding data value.protected Date
nextStandardDate
(Date date, DateTickUnit unit) Returns the first "standard" date (based on the specified field and units).protected Date
previousStandardDate
(Date date, DateTickUnit unit) Returns the previous "standard" date, for a given date and tick unit.refreshTicks
(Graphics2D g2, AxisState state, 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 List
refreshTicksHorizontal
(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) Recalculates the ticks for the date axis.protected List
refreshTicksVertical
(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) Recalculates the ticks for the date axis.protected void
selectAutoTickUnit
(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) Selects an appropriate tick value for the axis.protected void
selectHorizontalAutoTickUnit
(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) Selects an appropriate tick size for the axis.protected void
selectVerticalAutoTickUnit
(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) Selects an appropriate tick size for the axis.void
setDateFormatOverride
(DateFormat formatter) Sets the date format override and sends anAxisChangeEvent
to all registered listeners.void
Sets the locale for the axis and sends a change event to all registered listeners.void
setMaximumDate
(Date maximumDate) Sets the maximum date visible on the axis and sends anAxisChangeEvent
to all registered listeners.void
setMinimumDate
(Date date) Sets the minimum date visible on the axis and sends anAxisChangeEvent
to all registered listeners.void
setRange
(double lower, double upper) Sets the axis range and sends anAxisChangeEvent
to all registered listeners.void
Sets the axis range and sends anAxisChangeEvent
to all registered listeners.void
Sets the upper and lower bounds for the axis and sends anAxisChangeEvent
to all registered listeners.void
Sets the range for the axis, if requested, sends anAxisChangeEvent
to all registered listeners.void
setTickMarkPosition
(DateTickMarkPosition position) Sets the tick mark position (start, middle or end of the time period) and sends anAxisChangeEvent
to all registered listeners.void
setTickUnit
(DateTickUnit unit) Sets the tick unit for the axis.void
setTickUnit
(DateTickUnit unit, boolean notify, boolean turnOffAutoSelection) Sets the tick unit attribute and, if requested, sends anAxisChangeEvent
to all registered listeners.void
setTimeline
(Timeline timeline) Sets the underlying timeline to use for this axis.void
setTimeZone
(TimeZone zone) Sets the time zone for the axis and sends anAxisChangeEvent
to all registered listeners.double
valueToJava2D
(double value, Rectangle2D area, RectangleEdge edge) Translates the data value to the display coordinates (Java 2D User Space) of the chart.void
zoomRange
(double lowerPercent, double upperPercent) Zooms in on the current range (zoom-in stops once the axis length reaches the equivalent of one millisecond).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, setRangeAboutValue, setRangeWithMargins, setRangeWithMargins, setRangeWithMargins, setRightArrow, setStandardTickUnits, setUpArrow, setUpperBound, setUpperMargin, setVerticalTickLabels
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 Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization.- See Also:
-
DEFAULT_DATE_RANGE
The default axis range. -
DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS
public static final double DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDSThe default minimum auto range size.- See Also:
-
DEFAULT_ANCHOR_DATE
The default anchor date. -
tickUnit
The current tick unit. -
dateFormatOverride
The override date format. -
tickMarkPosition
Tick marks can be displayed at the start or the middle of the time period. -
DEFAULT_TIMELINE
A static default timeline shared by all standard DateAxis -
timeZone
The time zone for the axis. -
locale
The locale for the axis (null
is not permitted). -
timeline
Our underlying timeline.
-
-
Constructor Details
-
DateAxis
public DateAxis()Creates a date axis with no label. -
DateAxis
Creates a date axis with the specified label.- Parameters:
label
- the axis label (null
permitted).
-
DateAxis
Creates a date axis.- Parameters:
label
- the axis label (null
permitted).zone
- the time zone.locale
- the locale (null
not permitted).
-
-
Method Details
-
getTimeZone
Returns the time zone for the axis.- Returns:
- The time zone (never
null
). - See Also:
-
setTimeZone
Sets the time zone for the axis and sends anAxisChangeEvent
to all registered listeners.- Parameters:
zone
- the time zone (null
not permitted).- See Also:
-
getLocale
Returns the locale for this axis.- Returns:
- The locale (never
null
).
-
setLocale
Sets the locale for the axis and sends a change event to all registered listeners.- Parameters:
locale
- the new locale (null
not permitted).
-
getTimeline
Returns the underlying timeline used by this axis.- Returns:
- The timeline.
-
setTimeline
Sets the underlying timeline to use for this axis. If the timeline is changed, anAxisChangeEvent
is sent to all registered listeners.- Parameters:
timeline
- the timeline.
-
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 (possibly
null
). - See Also:
-
setTickUnit
Sets the tick unit for the axis. The auto-tick-unit-selection flag is set tofalse
, and registered listeners are notified that the axis has been changed.- Parameters:
unit
- the tick unit.- See Also:
-
setTickUnit
Sets the tick unit attribute and, if requested, sends anAxisChangeEvent
to all registered listeners.- Parameters:
unit
- the new tick unit.notify
- notify registered listeners?turnOffAutoSelection
- turn off auto selection?- See Also:
-
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 formatter (possibly
null
).
-
setDateFormatOverride
Sets the date format override and sends anAxisChangeEvent
to all registered listeners. If this is non-null, then it will be used to format the dates on the axis.- Parameters:
formatter
- the date formatter (null
permitted).
-
setRange
Sets the upper and lower bounds for the axis and sends anAxisChangeEvent
to all registered listeners. As a side-effect, the auto-range flag is set to false. -
setRange
Sets the range for the axis, if requested, sends anAxisChangeEvent
to all registered listeners. As a side-effect, the auto-range flag is set tofalse
(optional). -
setRange
Sets the axis range and sends anAxisChangeEvent
to all registered listeners.- 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 and sends anAxisChangeEvent
to all registered listeners. -
getMinimumDate
Returns the earliest date visible on the axis.- Returns:
- The date.
- See Also:
-
setMinimumDate
Sets the minimum date visible on the axis and sends anAxisChangeEvent
to all registered listeners. Ifdate
is on or after the current maximum date for the axis, the maximum date will be shifted to preserve the current length of the axis.- Parameters:
date
- the date (null
not permitted).- See Also:
-
getMaximumDate
Returns the latest date visible on the axis.- Returns:
- The date.
- See Also:
-
setMaximumDate
Sets the maximum date visible on the axis and sends anAxisChangeEvent
to all registered listeners. IfmaximumDate
is on or before the current minimum date for the axis, the minimum date will be shifted to preserve the current length of the axis.- Parameters:
maximumDate
- the date (null
not permitted).- See Also:
-
getTickMarkPosition
Returns the tick mark position (start, middle or end of the time period).- Returns:
- The position (never
null
).
-
setTickMarkPosition
Sets the tick mark position (start, middle or end of the time period) and sends anAxisChangeEvent
to all registered listeners.- Parameters:
position
- the position (null
not permitted).
-
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. -
isHiddenValue
public boolean isHiddenValue(long millis) Returnstrue
if the axis hides this value, andfalse
otherwise.- Parameters:
millis
- the data value.- Returns:
- A value.
-
valueToJava2D
Translates the data value to the display coordinates (Java 2D User Space) of the chart.- Specified by:
valueToJava2D
in classValueAxis
- Parameters:
value
- the date to be plotted.area
- the rectangle (in Java2D space) where the data is to be plotted.edge
- the axis location.- Returns:
- The coordinate corresponding to the supplied data value.
- See Also:
-
dateToJava2D
Translates a date to Java2D coordinates, based on the range displayed by this axis for the specified data area.- Parameters:
date
- the date.area
- the rectangle (in Java2D space) where the data is to be plotted.edge
- the axis location.- Returns:
- The coordinate corresponding to the supplied date.
-
java2DToValue
Translates a Java2D coordinate into the corresponding data value. To perform this translation, you need to know the area used for plotting data, and which edge the axis is located on.- Specified by:
java2DToValue
in classValueAxis
- Parameters:
java2DValue
- the coordinate in Java2D space.area
- the rectangle (in Java2D space) where the data is to be plotted.edge
- the axis location.- Returns:
- A data value.
- See Also:
-
calculateLowestVisibleTickValue
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
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
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.
-
calculateDateForPosition
Returns aDate
corresponding to the specified position within aRegularTimePeriod
.- Parameters:
period
- the period.position
- the position (null
not permitted).- Returns:
- A date.
-
nextStandardDate
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
Returns a collection of standard date tick units that uses the default time zone. This collection will be used by default, but you are free to create your own collection if you want to (see theValueAxis.setStandardTickUnits(TickUnitSource)
method inherited from theValueAxis
class).- Returns:
- A collection of standard date tick units.
-
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 theValueAxis.setStandardTickUnits(TickUnitSource)
method inherited from theValueAxis
class).- Parameters:
zone
- the time zone (null
not permitted).locale
- the locale (null
not permitted).- Returns:
- A collection of standard date tick units.
-
autoAdjustRange
protected void autoAdjustRange()Rescales the axis to ensure that all data is visible.- Specified by:
autoAdjustRange
in classValueAxis
-
selectAutoTickUnit
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(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) Selects an appropriate tick size for the axis. The strategy is to display as many ticks as possible (selected from a collection 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
Selects an appropriate tick size for the axis. The strategy is to display as many ticks as possible (selected from a collection 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.
-
estimateMaximumTickLabelWidth
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.
-
estimateMaximumTickLabelHeight
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.
-
refreshTicks
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.
-
correctTickDateForPosition
private Date correctTickDateForPosition(Date time, DateTickUnit unit, DateTickMarkPosition position) Corrects the given tick date for the position setting.- Parameters:
time
- the tick date/time.unit
- the tick unit.position
- the tick position.- Returns:
- The adjusted time.
-
refreshTicksHorizontal
Recalculates the ticks for the date axis.- Parameters:
g2
- the graphics device.dataArea
- the area in which the data is to be drawn.edge
- the location of the axis.- Returns:
- A list of ticks.
-
refreshTicksVertical
Recalculates the ticks for the date axis.- 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.
-
draw
public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, 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
).
-
zoomRange
public void zoomRange(double lowerPercent, double upperPercent) Zooms in on the current range (zoom-in stops once the axis length reaches the equivalent of one millisecond). -
equals
Tests this axis for equality with an arbitrary object. -
hashCode
public int hashCode()Returns a hash code for this object. -
clone
Returns a clone of the object.- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classValueAxis
- Returns:
- A clone.
- Throws:
CloneNotSupportedException
- if some component of the axis does not support cloning.
-