org.faceless.graph2
Class NumericAxis

java.lang.Object
  extended by org.faceless.graph2.Axis
      extended by org.faceless.graph2.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.


Field Summary
 
Fields inherited from class org.faceless.graph2.Axis
BOTTOM, DENSITY_MINIMAL, DENSITY_NORMAL, DENSITY_SPARSE, LEFT, RIGHT, TOP, ZAXIS
 
Constructor Summary
NumericAxis(NumberFormat format)
          Create a new NumericAxis with the specified format and the default density.
NumericAxis(NumberFormat format, int density)
          Create a new NumericAxis with the specified format and densty
 
Method Summary
 String format(double in)
           Given the specified number, return the text that should be placed against the tooth at that position.
static NumericAxis getCurrencyAxis(Locale locale)
          Return a NumericAxis that formats it's values as currencies in the specified locale.
static NumericAxis getFloatingPointAxis()
          Return a NumericAxis that formats it's values as real numbers
static NumericAxis getIntegerAxis()
          Return a NumericAxis that formats it's values as integers
 void setStretchEnds(boolean stretch)
          Whether to "stretch" the ends of the graph to a "useful" value or not.
 double[] steps(double min, double max)
           Which steps between min and max should be marked with a tooth.
 
Methods inherited from class org.faceless.graph2.Axis
setLabel, setMaxValue, setMinValue, setSpineStyle, setToothLength, setToothTextStyle, setWallPaint, setWallPaint, setZeroIntersection, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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


getFloatingPointAxis

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


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


Copyright © 2001-2011 Big Faceless Organization