org.faceless.graph2
Class DateAxis

java.lang.Object
  extended by org.faceless.graph2.Axis
      extended by org.faceless.graph2.DateAxis

public class DateAxis
extends Axis

A subclass of Axis to be used for plotting date values. Dates are stored internally as doubles, and the two can be converted back and forth using the toDouble and toDate methods. For example, to plot a number of dates on a LineSeries you could use code like the following:

 AxesGraph graph = new AxesGraph();
 LineSeries series = new LineSeries("Dates");
 series.set(DateAxis.toDouble(date1), value1);
 series.set(DateAxis.toDouble(date2), value2);
 graph.setAxis(Axis.BOTTOM, new DateAxis());
 
(here date1 and date2 are Date objects). Bars can also be plotted against a DateAxis - see the GeneralBarSeries API documentation for more info.


Field Summary
 
Fields inherited from class org.faceless.graph2.Axis
BOTTOM, DENSITY_MINIMAL, DENSITY_NORMAL, DENSITY_SPARSE, LEFT, RIGHT, TOP, ZAXIS
 
Constructor Summary
DateAxis()
          Create a new DateAxis with a format of "dd-MMM-yyyy"
DateAxis(DateFormat format)
          Create a new DateAxis with the specified format
DateAxis(DateFormat format, int density)
          Create a new DateAxis with the specified format and density
 
Method Summary
 String format(double in)
           Given the specified number, return the text that should be placed against the tooth at that position.
 void setBarsAtNoon(boolean noon)
          When plotting a GeneralBarSeries against a DateAxis, whether to center the bars on the tick, ie. midnight (false) or midway between the tick and the next tick, ie. noon (true).
 void setBarWidth(int seconds)
          When plotting bars against this axis, this method can be used to specify the width of those bars.
 void setStretchEnds(double stretch)
           Determines whether to "stretch" the ends of the graph to the next useful value.
 void setTimeZone(TimeZone tz)
          Set the timezone in use for this date axis.
 double[] steps(double min, double max)
           The steps method controls where the teeth are placed on the spine.
static Date toDate(double in)
          Convert a double to a Date.
static double toDouble(Date in)
          Convert a date to a double, so it can be stored internally.
 
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

DateAxis

public DateAxis()
Create a new DateAxis with a format of "dd-MMM-yyyy"


DateAxis

public DateAxis(DateFormat format)
Create a new DateAxis with the specified format


DateAxis

public DateAxis(DateFormat format,
                int density)
Create a new DateAxis with the specified format and density

Parameters:
format - how each date should be formatted
density - the density of the values on the axis - 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

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

setTimeZone

public void setTimeZone(TimeZone tz)
Set the timezone in use for this date axis.

Since:
2.2.1

setBarWidth

public void setBarWidth(int seconds)
When plotting bars against this axis, this method can be used to specify the width of those bars. By default this width is determined automatically based on the format (for example, a format that has a resolution of one day will result in bars one day wide). If the library guesses incorrectly however, this method may be used to hard-code the width. For example, setBarWidth(5*60) would give mean bars drawn against this axis are 5-minutes wide.

Parameters:
seconds - the number of seconds each bar should cover, or 0 to ask the library to guess (the default).
Since:
2.3

setBarsAtNoon

public void setBarsAtNoon(boolean noon)
When plotting a GeneralBarSeries against a DateAxis, whether to center the bars on the tick, ie. midnight (false) or midway between the tick and the next tick, ie. noon (true). Typically you will want to set this method to true when plotting bars against lines that represent hour values, not just day values. When not plotting Bars, this method has no effect.

Parameters:
noon - whether to center bars plotted against this axis at midday

setStretchEnds

public void setStretchEnds(double stretch)

Determines whether to "stretch" the ends of the graph to the next useful value. An example of when you would do this is plotting days of a month - although your data might only start on the 3rd of the month, you want the axis to start on the 1st.

The "stretch" parameter takes a value from 0 to 1, where 0 means "never stretch the axis" and 1 means "always stretch". If necessary, values between 0 and 1 can be specified which will cause the axis to be stretched depending on how far from the next "useful" endpoint the data is.

Parameters:
stretch - when to stretch the axis - 0 for never, 1 for always, or any value in between
Since:
2.3.1

toDouble

public static final double toDouble(Date in)
Convert a date to a double, so it can be stored internally. For example, to plot todays date on a Line Graph, you would do something like this:
   LineSeries data = new LineSeries("Dates");
   Date today = new Date();
   data.set(DateAxis.toDouble(today), 123.45);
 

See Also:
toDate(double)

toDate

public static final Date toDate(double in)
Convert a double to a Date. The opposite of toDouble(java.util.Date). Use this to convert a double passed in to the format(double) method back to a Date.


steps

public double[] steps(double min,
                      double max)
Description copied from class: Axis

The steps method controls where the teeth are placed on the spine. Each subclass of Axis has a different strategy - for instance, the DateAxis will try and place ticks on the 1st of the month, the NumericAxis will try and place them evenly across the range and so on.

The returned array should consist of a range of numbers, ordered from low to high, which mark the locations of the teeth on the spine. min and max are the minimum and maximum values of the data to plot, and these values will usually be the first and last values in the returned array.

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

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