Package org.faceless.graph2
Class NumericAxis
- java.lang.Object
-
- org.faceless.graph2.Axis
-
- 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 aNumberFormat
.
-
-
Field Summary
-
Fields inherited from class org.faceless.graph2.Axis
BOTTOM, DENSITY_MINIMAL, DENSITY_NORMAL, DENSITY_SPARSE, LEFT, RIGHT, TOP, ZAXIS
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 numbersstatic NumericAxis
getFloatingPointAxis(Locale locale)
Return a NumericAxis that formats it's values as integers in the specified Localestatic NumericAxis
getIntegerAxis()
Return a NumericAxis that formats it's values as integersstatic NumericAxis
getIntegerAxis(Locale locale)
Return a NumericAxis that formats it's values as integers in the specified Localevoid
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, setWallPaint, setZeroIntersection, toString
-
-
-
-
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 valuesdensity
- the density to use - usually one ofAxis.DENSITY_NORMAL
,Axis.DENSITY_SPARSE
orAxis.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, ornull
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)
.
-
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.
-
-