Package 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:
Serializable,Cloneable,org.jfree.util.PublicCloneable
public class DateAxis extends ValueAxis implements Cloneable, 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.
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:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static DateDEFAULT_ANCHOR_DATEThe default anchor date.static doubleDEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDSThe default minimum auto range size.static DateRangeDEFAULT_DATE_RANGEThe default axis range.static DateTickUnitDEFAULT_DATE_TICK_UNITThe 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_COUNTFields 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
-
Method Summary
Modifier and Type Method Description DatecalculateHighestVisibleTickValue(DateTickUnit unit)Calculates the value of the highest visible tick on the axis.DatecalculateLowestVisibleTickValue(DateTickUnit unit)Calculates the value of the lowest visible tick on the axis.Objectclone()Returns a clone of the object.voidconfigure()Configures the axis to work with the specified plot.static TickUnitSourcecreateStandardDateTickUnits()Returns a collection of standard date tick units that uses the default time zone.static TickUnitSourcecreateStandardDateTickUnits(TimeZone zone)Returns a collection of standard date tick units.doubledateToJava2D(Date date, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Translates a date to Java2D coordinates, based on the range displayed by this axis for the specified data area.AxisStatedraw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge, PlotRenderingInfo plotState)Draws the axis on a Java 2D graphics device (such as the screen or a printer).booleanequals(Object object)Tests an object for equality with this instance.DateFormatgetDateFormatOverride()Returns the date format override.DategetMaximumDate()Returns the latest date visible on the axis.DategetMinimumDate()Returns the earliest date visible on the axis.DateTickMarkPositiongetTickMarkPosition()Returns the tick mark position (start, middle or end of the time period).DateTickUnitgetTickUnit()Returns the tick unit for the axis.TimelinegetTimeline()Returns the underlying timeline used by this axis.booleanisHiddenValue(long millis)Returnstrueif the axis hides this value, andfalseotherwise.doublejava2DToValue(double java2DValue, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Translates a Java2D coordinate into the corresponding data value.ListrefreshTicks(Graphics2D g2, AxisState state, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).ListrefreshTicksHorizontal(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)Recalculates the ticks for the date axis.ListrefreshTicksVertical(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)Recalculates the ticks for the date axis.voidsetDateFormatOverride(DateFormat formatter)Sets the date format override.voidsetMaximumDate(Date maximumDate)Sets the maximum date visible on the axis.voidsetMinimumDate(Date minimumDate)Sets the minimum date visible on the axis.voidsetRange(double lower, double upper)Sets the axis range.voidsetRange(Date lower, Date upper)Sets the axis range.voidsetRange(Range range)Sets the upper and lower bounds for the axis and sends anAxisChangeEventto all registered listeners.voidsetRange(Range range, boolean turnOffAutoRange, boolean notify)Sets the range for the axis, if requested, sends anAxisChangeEventto all registered listeners.voidsetTickMarkPosition(DateTickMarkPosition position)Sets the tick mark position (start, middle or end of the time period).voidsetTickUnit(DateTickUnit unit)Sets the tick unit for the axis.voidsetTickUnit(DateTickUnit unit, boolean notify, boolean turnOffAutoSelection)Sets the tick unit attribute without any other side effects.voidsetTimeline(Timeline timeline)Sets the underlying timeline to use for this axis.doubletranslateDateToJava2D(Date date, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Deprecated.Use dataToJava2D() instead.doubletranslateJava2DToValue(double java2DValue, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Deprecated.Use java2DToValue instead.doubletranslateValueToJava2D(double value, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Deprecated.Use valueToJava2D instead.doublevalueToJava2D(double value, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Translates the data value to the display coordinates (Java 2D User Space) of the chart.voidzoomRange(double lowerPercent, double upperPercent)Zooms in on the current range.Methods inherited from class org.jfree.chart.axis.ValueAxis
centerRange, getAutoRangeMinimumSize, getDownArrow, getFixedAutoRange, getLeftArrow, getLowerBound, getLowerMargin, getMaximumAxisValue, getMinimumAxisValue, getRange, getRightArrow, getStandardTickUnits, getUpArrow, getUpperBound, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isInverted, isNegativeArrowVisible, isPositiveArrowVisible, isVerticalTickLabels, reserveSpace, resizeRange, resizeRange, setAutoRange, setAutoRangeMinimumSize, setAutoRangeMinimumSize, setAutoTickUnitSelection, setAutoTickUnitSelection, setDownArrow, setFixedAutoRange, setInverted, setLeftArrow, setLowerBound, setLowerMargin, setMaximumAxisValue, setMinimumAxisValue, setNegativeArrowVisible, setPositiveArrowVisible, setRangeAboutValue, setRangeWithMargins, setRangeWithMargins, setRangeWithMargins, setRightArrow, setStandardTickUnits, setUpArrow, setUpperBound, setUpperMargin, setVerticalTickLabels, translateJava2DtoValueMethods inherited from class org.jfree.chart.axis.Axis
addChangeListener, getAxisLinePaint, getAxisLineStroke, getFixedDimension, getLabel, getLabelAngle, getLabelFont, getLabelInsets, getLabelPaint, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, isAxisLineVisible, isTickLabelsVisible, isTickMarksVisible, isVisible, removeChangeListener, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setFixedDimension, setLabel, setLabelAngle, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
-
Field Details
-
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:
- Constant Field Values
-
DEFAULT_DATE_TICK_UNIT
The default date tick unit. -
DEFAULT_ANCHOR_DATE
The default anchor date.
-
-
Constructor Details
-
DateAxis
public DateAxis()Default constructor. -
DateAxis
Creates a date axis.- Parameters:
label- the axis label (nullpermitted).
-
DateAxis
Creates a date axis. A timeline is specified for the axis. This allows special transformations to occure between a domain of values and the values included in the axis.- Parameters:
label- the axis label (nullpermitted).timeline- the underlying timeline to use for the axis.- See Also:
SegmentedTimeline
-
-
Method Details
-
equals
Tests an object for equality with this instance. -
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, an
AxisChangeEventis sent to all registered listeners.- Parameters:
timeline- the new timeline.
-
getTickUnit
Returns the tick unit for the axis.- Returns:
- the tick unit for the axis.
-
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 new tick unit.
-
setTickUnit
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
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
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 (nullpermitted).
-
setRange
Sets the upper and lower bounds for the axis and sends anAxisChangeEventto 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 anAxisChangeEventto all registered listeners. As a side-effect, the auto-range flag is set tofalse(optional). -
setRange
Sets the axis range. AnAxisChangeEventis sent 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. AnAxisChangeEventis sent to all registered listeners. -
getMinimumDate
Returns the earliest date visible on the axis.- Returns:
- the earliest date visible on the axis.
-
setMinimumDate
Sets the minimum date visible on the axis. AnAxisChangeEventis sent to all registered listeners.- Parameters:
minimumDate- the new minimum date.
-
getMaximumDate
Returns the latest date visible on the axis.- Returns:
- the latest date visible on the axis.
-
setMaximumDate
Sets the maximum date visible on the axis. AnAxisChangeEventis sent to all registered listeners.- Parameters:
maximumDate- the new maximum date.
-
getTickMarkPosition
Returns the tick mark position (start, middle or end of the time period).- Returns:
- The position.
-
setTickMarkPosition
Sets the tick mark position (start, middle or end of the time period). AnAxisChangeEventis sent to all registered listeners.- Parameters:
position- the new position.
-
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)Returnstrueif the axis hides this value, andfalseotherwise.- 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:
valueToJava2Din 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.
-
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:
java2DToValuein 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.
-
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.
-
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 the setStandardTickUnits() method inherited from the ValueAxis 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 the setStandardTickUnits(...) method inherited from the ValueAxis class).- Parameters:
zone- the time zone.- Returns:
- A collection of standard date tick units.
-
refreshTicks
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.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:
refreshTicksin classAxis- Parameters:
g2- the graphics device.state- the axis state.plotArea- the area in which the plot and the axes should be drawn.dataArea- the area in which the plot should be drawn.edge- the location of the axis.- Returns:
- A list of ticks.
-
refreshTicksHorizontal
public List refreshTicksHorizontal(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)Recalculates the ticks for the date axis.- Parameters:
g2- the graphics device.cursor- the cursor location.plotArea- the area in which the axes and data are to be drawn.dataArea- the area in which the data is to be drawn.edge- the location of the axis.- Returns:
- A list of ticks.
-
refreshTicksVertical
public List refreshTicksVertical(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)Recalculates the ticks for the date axis.- Parameters:
g2- the graphics device.cursor- the cursor location.plotArea- the area in which the plot and the axes should be drawn.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, org.jfree.ui.RectangleEdge edge, PlotRenderingInfo plotState)Draws the axis on a Java 2D graphics device (such as the screen or a printer).- Specified by:
drawin classAxis- Parameters:
g2- the graphics device (nullnot permitted).cursor- the cursor location.plotArea- the area within which the axes and data should be drawn (nullnot permitted).dataArea- the area within which the data should be drawn (nullnot permitted).edge- the location of the axis (nullnot permitted).plotState- collects information about the plot (nullpermitted).- Returns:
- the axis state (never
null).
-
zoomRange
public void zoomRange(double lowerPercent, double upperPercent)Zooms in on the current range. -
clone
Returns a clone of the object.- Specified by:
clonein interfaceorg.jfree.util.PublicCloneable- Overrides:
clonein classValueAxis- Returns:
- A clone.
- Throws:
CloneNotSupportedException- if some component of the axis does not support cloning.
-
translateValueToJava2D
public double translateValueToJava2D(double value, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Deprecated.Use valueToJava2D instead.Translates the data value to the display coordinates (Java 2D User Space) of the chart.- Overrides:
translateValueToJava2Din 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.
-
translateJava2DToValue
public double translateJava2DToValue(double java2DValue, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Deprecated.Use java2DToValue instead.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.- Overrides:
translateJava2DToValuein 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.
-
translateDateToJava2D
Deprecated.Use dataToJava2D() instead.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.
-