Class NumericAxis


  • public class NumericAxis
    extends Axis
    The most common type of Axis, a NumericAxis is used to display numbers, either as integers, real numbers, percentages, currency amounts or any type of format that can be created with a NumberFormat.
    • Constructor Detail

      • NumericAxis

        public NumericAxis​(NumberFormat format)
        Create a new NumericAxis with the specified format and the default density.
        Parameters:
        format - the format to use to display the values
      • NumericAxis

        public NumericAxis​(NumberFormat format,
                           int density)
        Create a new NumericAxis with the specified format and densty
        Parameters:
        format - the format to use to display the values
        density - the density to use - usually one of Axis.DENSITY_NORMAL, Axis.DENSITY_SPARSE or Axis.DENSITY_MINIMAL, but may be any integer which is roughly the number of intended teeth on the axis.
    • Method Detail

      • getIntegerAxis

        public static final NumericAxis getIntegerAxis()
        Return a NumericAxis that formats it's values as integers
      • getIntegerAxis

        public static final NumericAxis getIntegerAxis​(Locale locale)
        Return a NumericAxis that formats it's values as integers in the specified Locale
        Parameters:
        locale - the locale to format the numbers in
        Since:
        2.4.6
      • getFloatingPointAxis

        public static final NumericAxis getFloatingPointAxis()
        Return a NumericAxis that formats it's values as real numbers
      • getFloatingPointAxis

        public static final NumericAxis getFloatingPointAxis​(Locale locale)
        Return a NumericAxis that formats it's values as integers in the specified Locale
        Parameters:
        locale - the locale to format the numbers in
        Since:
        2.4.6
      • getCurrencyAxis

        public static final NumericAxis getCurrencyAxis​(Locale locale)
        Return a NumericAxis that formats it's values as currencies in the specified locale.
        Parameters:
        locale - which Locale to use for currencies, or null to use the default locale
      • format

        public String format​(double in)
        Description copied from class: Axis

        Given the specified number, return the text that should be placed against the tooth at that position. For example, an Axis that simply plotted integer values might return Integer.toString((int)in)

        Those wanting to create their own custom axis will typically override this method and Axis.steps(double, double).

        Specified by:
        format in class Axis
        Parameters:
        in - the value to format
        Returns:
        the value formatted as a String
      • setStretchEnds

        public void setStretchEnds​(boolean stretch)
        Whether to "stretch" the ends of the graph to a "useful" value or not. For instance, when this setting is on, plotting values from 0 to 98 will result in an axis that runs from 0 to 100. Turning it off means the top of the graph stops at exactly 98. This setting is on by default
        Parameters:
        stretch - whether to stretch the ends of the graph
      • steps

        public double[] steps​(double min,
                              double max)

        Which steps between min and max should be marked with a tooth. This method returns the default settings, which is to calculate a number of "useful" values between min and max, possibly rounding those two values up or down to fit the scale. The number of values returned depends on the density setting.

        Specified by:
        steps in class Axis
        Parameters:
        min - the minimum value of the data to plot
        max - the maximum value of the data to plot
        Returns:
        an array of doubles representing the positions to place teeth on this axis