org.jfree.chart.axis
Class HorizontalDateAxis
java.lang.Object
|
+--org.jfree.chart.axis.Axis
|
+--org.jfree.chart.axis.ValueAxis
|
+--org.jfree.chart.axis.DateAxis
|
+--org.jfree.chart.axis.HorizontalDateAxis
- All Implemented Interfaces:
- AxisConstants, HorizontalAxis, java.io.Serializable
- public class HorizontalDateAxis
- extends DateAxis
- implements HorizontalAxis, java.io.Serializable
A horizontal axis that displays dates.
This axis can be used with the XYPlot
class for datasets where
the x-values are numbers interpreted as milliseconds since midnight 1-Jan-1970 GMT (the
encoding used by java.util.Date).
You can also use a HorizontalDateAxis as the range axis in a
HorizontalCategoryPlot
.
- Author:
- David Gilbert
- See Also:
XYPlot
,
HorizontalCategoryPlot
,
Serialized Form
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 |
HorizontalDateAxis(java.lang.String label)
Constructs a new date axis, using default attribute values where necessary. |
Method Summary |
protected void |
autoAdjustRange()
Rescales the axis to ensure that all data is visible. |
void |
configure()
Configures the axis to work with the specified plot. |
void |
draw(java.awt.Graphics2D g2,
java.awt.geom.Rectangle2D plotArea,
java.awt.geom.Rectangle2D dataArea,
int location)
Draws the axis on a Java 2D graphics device (such as the screen or a printer). |
boolean |
getVerticalTickLabels()
Returns true if the tick labels should be rotated to vertical, and false
for standard horizontal labels. |
protected boolean |
isCompatiblePlot(Plot plot)
Checks the compatibility of a plot with this type of axis, returning true if the plot is
compatible and false otherwise. |
void |
refreshTicks(java.awt.Graphics2D g2,
java.awt.geom.Rectangle2D plotArea,
java.awt.geom.Rectangle2D dataArea,
int location)
Recalculates the ticks for the date axis. |
double |
reserveHeight(java.awt.Graphics2D g2,
Plot plot,
java.awt.geom.Rectangle2D drawArea,
int location)
Returns the height required to draw the axis in the specified draw area. |
double |
reserveHeight(java.awt.Graphics2D g2,
Plot plot,
java.awt.geom.Rectangle2D drawArea,
int location,
double reservedWidth,
int verticalAxisLocation)
Returns area in which the axis will be displayed. |
protected void |
selectAutoTickUnit(java.awt.Graphics2D g2,
java.awt.geom.Rectangle2D drawArea,
java.awt.geom.Rectangle2D dataArea)
Selects an appropriate tick value for the axis. |
void |
setVerticalTickLabels(boolean flag)
Sets the flag that controls whether the tick labels are displayed vertically (that is,
rotated 90 degrees from horizontal). |
double |
translateDateToJava2D(java.util.Date date,
java.awt.geom.Rectangle2D dataArea)
Translates a date to Java2D coordinates, based on the range displayed by
this axis for the specified data area. |
double |
translateJava2DtoValue(float java2DValue,
java.awt.geom.Rectangle2D dataArea)
Translates the Java2D (horizontal) coordinate back to the corresponding
data value. |
double |
translateValueToJava2D(double value,
java.awt.geom.Rectangle2D dataArea)
Translates the data value to the display coordinates (Java 2D User Space)
of the chart. |
Methods inherited from class org.jfree.chart.axis.DateAxis |
calculateHighestVisibleTickValue, calculateLowestVisibleTickValue, createStandardDateTickUnits, getAnchorDate, getDateFormatOverride, getMaximumDate, getMinimumDate, getTickUnit, isTickMarksAtStartOfUnit, nextStandardDate, previousStandardDate, setAnchorDate, setAnchorValue, setAxisRange, setDateFormatOverride, setMaximumDate, setMinimumDate, setRange, setRange, setRange, setTickMarksAtStartOfUnit, setTickUnit, setTickUnit |
Methods inherited from class org.jfree.chart.axis.ValueAxis |
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 |
Methods inherited from class org.jfree.chart.axis.Axis |
addChangeListener, drawHorizontalLabel, drawVerticalLabel, equals, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getMaxTickLabelWidth, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, getTicks, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, 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 |
HorizontalDateAxis
public HorizontalDateAxis(java.lang.String label)
- Constructs a new date axis, using default attribute values where necessary.
- Parameters:
label
- the axis label (null
permitted).
getVerticalTickLabels
public boolean getVerticalTickLabels()
- Returns true if the tick labels should be rotated to vertical, and false
for standard horizontal labels.
- Returns:
true
or false
.
setVerticalTickLabels
public void setVerticalTickLabels(boolean flag)
- Sets the flag that controls whether the tick labels are displayed vertically (that is,
rotated 90 degrees from horizontal).
If the flag is changed, an AxisChangeEvent
is sent to all registered listeners.
- Parameters:
flag
- the flag.
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.
- Specified by:
configure
in class Axis
translateDateToJava2D
public double translateDateToJava2D(java.util.Date date,
java.awt.geom.Rectangle2D dataArea)
- Translates a date to Java2D coordinates, based on the range displayed by
this axis for the specified data area.
- Parameters:
date
- the date.dataArea
- the rectangle (in Java2D space) where the data is to be plotted.
- Returns:
- the horizontal coordinate corresponding to the supplied date.
translateValueToJava2D
public double translateValueToJava2D(double value,
java.awt.geom.Rectangle2D dataArea)
- Translates the data value to the display coordinates (Java 2D User Space)
of the chart.
- Specified by:
translateValueToJava2D
in class ValueAxis
- Parameters:
value
- the date to be plotted.dataArea
- the rectangle (in Java2D space) where the data is to be plotted.
- Returns:
- the horizontal coordinate corresponding to the supplied data value.
translateJava2DtoValue
public double translateJava2DtoValue(float java2DValue,
java.awt.geom.Rectangle2D dataArea)
- Translates the Java2D (horizontal) coordinate back to the corresponding
data value.
- Specified by:
translateJava2DtoValue
in class ValueAxis
- Parameters:
java2DValue
- the coordinate in Java2D space.dataArea
- the rectangle (in Java2D space) where the data is to be plotted.
- Returns:
- the data value corresponding to the Java2D coordinate.
autoAdjustRange
protected void autoAdjustRange()
- Rescales the axis to ensure that all data is visible.
- Specified by:
autoAdjustRange
in class ValueAxis
refreshTicks
public void refreshTicks(java.awt.Graphics2D g2,
java.awt.geom.Rectangle2D plotArea,
java.awt.geom.Rectangle2D dataArea,
int location)
- Recalculates the ticks for the date axis.
- Specified by:
refreshTicks
in class Axis
- Parameters:
g2
- the graphics device.plotArea
- the area in which the axes and data are to be drawn.dataArea
- the area in which the data is to be drawn.location
- the location of the axis.
draw
public void draw(java.awt.Graphics2D g2,
java.awt.geom.Rectangle2D plotArea,
java.awt.geom.Rectangle2D dataArea,
int location)
- Draws the axis on a Java 2D graphics device (such as the screen or a printer).
- Specified by:
draw
in class Axis
- Parameters:
g2
- the graphics device.plotArea
- the area within which the axes and data should be drawn.dataArea
- the area within which the data should be drawn.location
- the location of the axis.
reserveHeight
public double reserveHeight(java.awt.Graphics2D g2,
Plot plot,
java.awt.geom.Rectangle2D drawArea,
int location)
- Returns the height required to draw the axis in the specified draw area.
- Specified by:
reserveHeight
in interface HorizontalAxis
- Parameters:
g2
- the graphics device.plot
- the plot that the axis belongs to.drawArea
- the area within which the plot should be drawn.location
- the axis location (top or bottom).
- Returns:
- the height.
reserveHeight
public double reserveHeight(java.awt.Graphics2D g2,
Plot plot,
java.awt.geom.Rectangle2D drawArea,
int location,
double reservedWidth,
int verticalAxisLocation)
- Returns area in which the axis will be displayed.
- Specified by:
reserveHeight
in interface HorizontalAxis
- Parameters:
g2
- the graphics device.plot
- the plot.drawArea
- the drawing area.location
- the location of the axis.reservedWidth
- the width already reserved for the vertical axis.verticalAxisLocation
- the location of the vertical axis.
- Returns:
- the area to reserve for the horizontal axis.
selectAutoTickUnit
protected void selectAutoTickUnit(java.awt.Graphics2D g2,
java.awt.geom.Rectangle2D drawArea,
java.awt.geom.Rectangle2D dataArea)
- 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.drawArea
- the area in which the plot and axes should be drawn.dataArea
- the area defined by the axes.
isCompatiblePlot
protected boolean isCompatiblePlot(Plot plot)
- Checks the compatibility of a plot with this type of axis, returning true if the plot is
compatible and false otherwise.
The HorizontalDateAxis class required the plot to implement the HorizontalValuePlot
interface.
- Specified by:
isCompatiblePlot
in class Axis
- Parameters:
plot
- the plot.
- Returns:
- a boolean indicating whether the plot is compatible with the axis.