Class NumberAxis
- All Implemented Interfaces:
Serializable
,Cloneable
,org.jfree.util.PublicCloneable
- Direct Known Subclasses:
CyclicNumberAxis
,LogarithmicAxis
,NumberAxis3D
,SymbolicAxis
public class NumberAxis extends ValueAxis implements Cloneable, Serializable
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.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description 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.static boolean
DEFAULT_VERTICAL_TICK_LABELS
The default setting for the vertical tick labels flag.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 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 Constructor Description NumberAxis()
Default constructor.NumberAxis(String label)
Constructs a number axis, using default values where necessary. -
Method Summary
Modifier and Type Method Description 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.Object
clone()
Returns a clone of the axis.void
configure()
Configures the axis to work with the specified plot.static TickUnitSource
createIntegerTickUnits()
Returns a collection of tick units for integer values.static TickUnitSource
createIntegerTickUnits(Locale locale)
Returns a collection of tick units for integer values.static TickUnitSource
createStandardTickUnits()
Creates the standard tick units.static TickUnitSource
createStandardTickUnits(Locale locale)
Creates a collection of standard tick units.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).boolean
equals(Object object)
Tests an object for equality with this instance.static DecimalFormat
getDecimalFormat(String pattern)
MarkerAxisBand
getMarkerBand()
Returns the (optional) marker band for the axis.NumberFormat
getNumberFormatOverride()
Returns the number format override.NumberTickUnit
getTickUnit()
Returns the tick unit for the axis.double
java2DToValue(double java2DValue, Rectangle2D area, org.jfree.ui.RectangleEdge edge)
Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.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).void
setAutoRangeIncludesZero(boolean flag)
Sets the flag that indicates whether or not the axis range, if automatically calculated, 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
setMarkerBand(MarkerAxisBand band)
Sets the marker band for the axis.void
setNumberFormatOverride(NumberFormat formatter)
Sets the number format override.void
setTickUnit(NumberTickUnit unit)
Sets the tick unit for the axis and sends anAxisChangeEvent
to all registered listeners.void
setTickUnit(NumberTickUnit unit, boolean notify, boolean turnOffAutoSelect)
Sets the tick unit for the axis and, if requested, sends anAxisChangeEvent
to all registered listeners.static String
stringReplace(String s, String find, String replace)
Replace occurrences of a substring.double
translateJava2DToValue(double java2DValue, Rectangle2D area, org.jfree.ui.RectangleEdge edge)
Deprecated.Use java2DToValue() instead.double
translateValueToJava2D(double value, Rectangle2D area, org.jfree.ui.RectangleEdge edge)
Deprecated.Use valueToJava2D() instead.double
valueToJava2D(double value, Rectangle2D area, org.jfree.ui.RectangleEdge edge)
Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.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, setRange, setRange, setRange, setRangeAboutValue, setRangeWithMargins, setRangeWithMargins, setRangeWithMargins, setRightArrow, setStandardTickUnits, setUpArrow, setUpperBound, setUpperMargin, setVerticalTickLabels, translateJava2DtoValue, zoomRange
Methods 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_AUTO_RANGE_INCLUDES_ZERO
public static final boolean DEFAULT_AUTO_RANGE_INCLUDES_ZEROThe default value for the autoRangeIncludesZero flag.- See Also:
- Constant Field Values
-
DEFAULT_AUTO_RANGE_STICKY_ZERO
public static final boolean DEFAULT_AUTO_RANGE_STICKY_ZEROThe default value for the autoRangeStickyZero flag.- See Also:
- Constant Field Values
-
DEFAULT_TICK_UNIT
The default tick unit. -
DEFAULT_VERTICAL_TICK_LABELS
public static final boolean DEFAULT_VERTICAL_TICK_LABELSThe default setting for the vertical tick labels flag.- See Also:
- Constant Field Values
-
-
Constructor Details
-
NumberAxis
public NumberAxis()Default constructor. -
NumberAxis
Constructs a number axis, using default values where necessary.- Parameters:
label
- the axis label (null
permitted).
-
-
Method Details
-
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 axis range, if automatically calculated, is forced to include zero.If the flag is changed to
true
, the axis range is recalculated.Any change to the flag will trigger an
AxisChangeEvent
.- 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
Returns the tick unit for the axis.- Returns:
- The tick unit for the axis.
-
setTickUnit
Sets the tick unit for the axis and sends anAxisChangeEvent
to all registered listeners. A side effect of calling this method is that the "auto-select" feature for tick units is switched off (you can restore it using theValueAxis.setAutoTickUnitSelection(boolean)
method).- Parameters:
unit
- the new tick unit (null
not permitted).
-
setTickUnit
Sets the tick unit for the axis and, if requested, sends anAxisChangeEvent
to all registered listeners. In addition, an option is provided to turn off the "auto-select" feature for tick units (you can restore it using theValueAxis.setAutoTickUnitSelection(boolean)
method).- Parameters:
unit
- the new tick unit (null
not permitted).notify
- notify listeners?turnOffAutoSelect
- turn off the auto-tick selection?
-
getNumberFormatOverride
Returns the number format override. If this is non-null, then it will be used to format the numbers on the axis.- Returns:
- the number formatter (possibly
null
).
-
setNumberFormatOverride
Sets the number format override. If this is non-null, then it will be used to format the numbers on the axis.- Parameters:
formatter
- the number formatter (null
permitted).
-
getMarkerBand
Returns the (optional) marker band for the axis.- Returns:
- The marker band (possibly
null
).
-
setMarkerBand
Sets the marker band for the axis.The marker band is optional, leave it set to
null
if you don't require it.- Parameters:
band
- the new band (null
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. -
translateValueToJava2D
public double translateValueToJava2D(double value, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Deprecated.Use valueToJava2D() instead.Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.Note that it is possible for the coordinate to fall outside the plotArea.
- Overrides:
translateValueToJava2D
in classValueAxis
- Parameters:
value
- the data value.area
- the area for plotting the data.edge
- the axis location.- Returns:
- The Java2D coordinate.
-
valueToJava2D
Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.Note that it is possible for the coordinate to fall outside the plotArea.
- Specified by:
valueToJava2D
in classValueAxis
- Parameters:
value
- the data value.area
- the area for plotting the data.edge
- the axis location.- Returns:
- The Java2D coordinate.
-
translateJava2DToValue
public double translateJava2DToValue(double java2DValue, Rectangle2D area, org.jfree.ui.RectangleEdge edge)Deprecated.Use java2DToValue() instead.Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.- Overrides:
translateJava2DToValue
in classValueAxis
- Parameters:
java2DValue
- the coordinate in Java2D space.area
- the area in which the data is plotted.edge
- the location.- Returns:
- The data value.
-
java2DToValue
Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.- Specified by:
java2DToValue
in classValueAxis
- Parameters:
java2DValue
- the coordinate in Java2D space.area
- the area in which the data is plotted.edge
- the location.- Returns:
- The data value.
-
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.
-
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:
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
).
-
stringReplace
Replace occurrences of a substring. http://ostermiller.org/utils/StringHelper.html StringHelper.replace("1-2-3", "-", "|");
result: "1|2|3"
StringHelper.replace("-1--2-", "-", "|");
result: "|1||2|"
StringHelper.replace("123", "", "|");
result: "123"
StringHelper.replace("1-2---3----4", "--", "|");
result: "1-2|-3||4"
StringHelper.replace("1-2---3----4", "--", "---");
result: "1-2----3------4"- Parameters:
s
- String to be modified.find
- String to find.replace
- String to replace.- Returns:
- a string with all the occurrences of the string to find replaced.
- Throws:
NullPointerException
- if s is null.
-
getDecimalFormat
-
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
Returns a collection of tick units for integer values.- Returns:
- a collection of tick units for integer values.
-
createStandardTickUnits
Creates a collection of standard tick units. The supplied locale is used to create the number formatter (a localised instance ofNumberFormat
).If you don't like these defaults, create your own instance of
TickUnits
and then pass it to thesetStandardTickUnits(...)
method.- Parameters:
locale
- the locale.- Returns:
- a tick unit collection.
-
createIntegerTickUnits
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.
-
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:
refreshTicks
in 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.
-
clone
Returns a clone of the axis.- Specified by:
clone
in interfaceorg.jfree.util.PublicCloneable
- Overrides:
clone
in classValueAxis
- Returns:
- A clone
- Throws:
CloneNotSupportedException
- if some component of the axis does not support cloning.
-
equals
Tests an object for equality with this instance.
-