|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.graph2.Axis
org.faceless.graph2.DateAxis
public class DateAxis
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 |
---|
public DateAxis()
public DateAxis(DateFormat format)
public DateAxis(DateFormat format, int density)
format
- how each date should be formatteddensity
- 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 |
---|
public String format(double in)
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)
.
format
in class Axis
in
- the value to format
public void setTimeZone(TimeZone tz)
public void setBarWidth(int seconds)
setBarWidth(5*60)
would give mean bars
drawn against this axis are 5-minutes wide.
seconds
- the number of seconds each bar should cover, or 0 to ask
the library to guess (the default).public void setBarsAtNoon(boolean noon)
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.
noon
- whether to center bars plotted against this axis at middaypublic 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.
stretch
- when to stretch the axis - 0 for never, 1 for always, or any
value in betweenpublic static final double toDouble(Date in)
LineSeries data = new LineSeries("Dates"); Date today = new Date(); data.set(DateAxis.toDouble(today), 123.45);
toDate(double)
public static final Date toDate(double in)
toDouble(java.util.Date)
. Use this
to convert a double passed in to the format(double)
method back to
a Date.
public double[] steps(double min, double max)
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)
.
steps
in class Axis
min
- the minimum value of the data to plotmax
- the maximum value of the data to plot
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |