NumberAxis
org.jfree.chart.axis

Class NumberAxis

  • All Implemented Interfaces:
    Serializable, Cloneable, org.jfree.util.PublicCloneable
    Direct Known Subclasses:
    CyclicNumberAxis, LogarithmicAxis, ModuloAxis, NumberAxis3D, SymbolAxis


    public class NumberAxisextends ValueAxisimplements Cloneable, Serializable
    An axis for displaying numerical data.

    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 Detail

      • DEFAULT_AUTO_RANGE_INCLUDES_ZERO

        public static final boolean DEFAULT_AUTO_RANGE_INCLUDES_ZERO
        The default value for the autoRangeIncludesZero flag.
        See Also:
        Constant Field Values
      • DEFAULT_AUTO_RANGE_STICKY_ZERO

        public static final boolean DEFAULT_AUTO_RANGE_STICKY_ZERO
        The default value for the autoRangeStickyZero flag.
        See Also:
        Constant Field Values
      • DEFAULT_TICK_UNIT

        public static final NumberTickUnit DEFAULT_TICK_UNIT
        The default tick unit.
      • DEFAULT_VERTICAL_TICK_LABELS

        public static final boolean DEFAULT_VERTICAL_TICK_LABELS
        The default setting for the vertical tick labels flag.
        See Also:
        Constant Field Values
    • Constructor Detail

      • NumberAxis

        public NumberAxis()
        Default constructor.
      • NumberAxis

        public NumberAxis(String label)
        Constructs a number axis, using default values where necessary.
        Parameters:
        label - the axis label (null permitted).
    • Method Detail

      • setRangeType

        public void setRangeType(RangeType rangeType)
        Sets the axis range type.
        Parameters:
        rangeType - the range type (null not permitted).
        See Also:
        getRangeType()
      • getAutoRangeIncludesZero

        public boolean getAutoRangeIncludesZero()
        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.
        See Also:
        getAutoRangeIncludesZero()
      • getAutoRangeStickyZero

        public boolean getAutoRangeStickyZero()
        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.
        See Also:
        setAutoRangeStickyZero(boolean)
      • 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.
        See Also:
        getAutoRangeStickyZero()
      • getTickUnit

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

        Note: if the autoTickUnitSelection flag is true 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 for the axis.
        See Also:
        setTickUnit(NumberTickUnit), ValueAxis.isAutoTickUnitSelection()
      • setTickUnit

        public void setTickUnit(NumberTickUnit unit,               boolean notify,               boolean turnOffAutoSelect)
        Sets the tick unit for the axis and, if requested, sends an AxisChangeEvent 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 the ValueAxis.setAutoTickUnitSelection(boolean) method).
        Parameters:
        unit - the new tick unit (null not permitted).
        notify - notify listeners?
        turnOffAutoSelect - turn off the auto-tick selection?
      • getNumberFormatOverride

        public NumberFormat 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).
        See Also:
        setNumberFormatOverride(NumberFormat)
      • setNumberFormatOverride

        public void setNumberFormatOverride(NumberFormat formatter)
        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).
        See Also:
        getNumberFormatOverride()
      • setMarkerBand

        public void setMarkerBand(MarkerAxisBand band)
        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).
        See Also:
        getMarkerBand()
      • 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
      • valueToJava2D

        public 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.

        Note that it is possible for the coordinate to fall outside the plotArea.

        Specified by:
        valueToJava2D in class ValueAxis
        Parameters:
        value - the data value.
        area - the area for plotting the data.
        edge - the axis location.
        Returns:
        The Java2D coordinate.
        See Also:
        java2DToValue(double, Rectangle2D, RectangleEdge)
      • java2DToValue

        public 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.
        Specified by:
        java2DToValue in class ValueAxis
        Parameters:
        java2DValue - the coordinate in Java2D space.
        area - the area in which the data is plotted.
        edge - the location.
        Returns:
        The data value.
        See Also:
        valueToJava2D(double, Rectangle2D, RectangleEdge)
      • 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 class Axis
        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).
      • createStandardTickUnits

        public static TickUnitSource createStandardTickUnits(Locale locale)
        Creates a collection of standard tick units. The supplied locale is used to create the number formatter (a localised instance of NumberFormat).

        If you don't like these defaults, create your own instance of TickUnits and then pass it to the setStandardTickUnits() method.

        Parameters:
        locale - the locale.
        Returns:
        A tick unit collection.
        See Also:
        ValueAxis.setStandardTickUnits(TickUnitSource)
      • createIntegerTickUnits

        public static TickUnitSource createIntegerTickUnits(Locale locale)
        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.
        See Also:
        ValueAxis.setStandardTickUnits(TickUnitSource)
      • refreshTicks

        public List refreshTicks(Graphics2D g2,                AxisState state,                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 class Axis
        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.
      • equals

        public boolean equals(Object obj)
        Tests the axis for equality with an arbitrary object.
        Overrides:
        equals in class ValueAxis
        Parameters:
        obj - the object (null permitted).
        Returns:
        A boolean.
      • hashCode

        public int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class Object
        Returns:
        A hash code.

SCaVis 1.7 © jWork.org