Class AxesGraph
- java.lang.Object
-
- org.faceless.graph2.Graph
-
- org.faceless.graph2.AxesGraph
-
public class AxesGraph extends Graph
The AxesGraph class represents any type of graph that's plotted against an axis - bar graphs, line graphs and so on.
An AxesGraph is made up of several components.
-
One or more
Series
, representing the data plotted on the graph. A series may consist of bars, lines etc. A series is plotted against exactly twoAxes
- the typical arrangement for a graph is against thebottom and left
axes. Each series is plotted in the order they are added to the graph, one behind the other. -
Between 2 and 4
Axes
, positioned at the left, bottom, right or top of the graph. These represent the scale against which anything on the graph is plotted. TheAxis
class is the superclass of all the different types of Axes which may be used, and thesetAxis
andgetAxis
methods used to set and get the specified axis on the graph. -
Each axis may have a "Wall", which is used to create a background behind the series and is set
via the
Axis.setWallPaint
method. The AxesGraph as a whole may have a "back wall", which is set using thesetBackWallPaint(java.awt.Paint)
method.
AxesGraph graph = new AxesGraph(); BarSeries series = new BarSeries("Fruit"); series.set("Apples", 20); series.set("Oranges", 30); series.set("Bananas", 15); graph.addSeries(series);
- See Also:
BarSeries
,LineSeries
,NumericAxis
,Graph
-
One or more
-
-
Field Summary
Fields Modifier and Type Field Description static int
BOTTOMLEFT
Constant used by theaddSeries
method to plot the series against the bottom and left axes.static int
BOTTOMRIGHT
Constant used by theaddSeries
method to plot the series against the bottom and right axes.static int
TOPLEFT
Constant used by theaddSeries
method to plot the series against the top and left axes.static int
TOPRIGHT
Constant used by theaddSeries
method to plot the series against the top and right axes.
-
Constructor Summary
Constructors Constructor Description AxesGraph()
Create a new AxesGraph
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSeries(Series series)
Add a series to this Graph, plotted against the bottom and left axes.void
addSeries(Series series, int pos)
Add a series to this Graph, plotted against the specified axes.Axis
getAxis(int pos)
Get the axis that's currently in the specified position on the graph.Series
getSeries(String name)
Return the series with the specified name from this AxesGraph, ornull
if no such series has been added yetvoid
setAxis(int pos, Axis axis)
Set the specified axis.void
setBackWallPaint(Paint paint)
Set the paint to use on the back wall.void
setBackWallPaint(Paint[] paints, Color stripe, int axis, int alt, double[] dash)
Set the paint to use on the back wall to a series of stripes.void
setBackWallPaint(StripedPaint paint)
Set the paint to use on the back wall to aStripedPaint
.void
setHorizontalScale(double b1, double t1, double b2, double t2)
Change the scaling ratio for the horizontal axes.void
setVerticalScale(double l1, double r1, double l2, double r2)
Change the scaling ratio for the vertical axes.-
Methods inherited from class org.faceless.graph2.Graph
addKey, addKey, addText, draw, getActualOffset, getActualZoom, getLocale, interrupt, isInterrupted, isOverlapping, setAutoColors, setColorOrdering, setDefaultColors, setFixedAspectRatio, setFixedSize, setLicenseKey, setLightLevel, setLightVector, setLocale, setMetaData, setOption, setXRotation, setYRotation, setZRotation
-
-
-
-
Field Detail
-
BOTTOMLEFT
public static final int BOTTOMLEFT
Constant used by theaddSeries
method to plot the series against the bottom and left axes.- See Also:
- Constant Field Values
-
BOTTOMRIGHT
public static final int BOTTOMRIGHT
Constant used by theaddSeries
method to plot the series against the bottom and right axes.- See Also:
- Constant Field Values
-
TOPLEFT
public static final int TOPLEFT
Constant used by theaddSeries
method to plot the series against the top and left axes.- See Also:
- Constant Field Values
-
TOPRIGHT
public static final int TOPRIGHT
Constant used by theaddSeries
method to plot the series against the top and right axes.- See Also:
- Constant Field Values
-
-
Method Detail
-
addSeries
public void addSeries(Series series)
Add a series to this Graph, plotted against the bottom and left axes.- Parameters:
series
- theSeries
to add to the graph- Throws:
IllegalArgumentException
- if the series has already been added
-
addSeries
public void addSeries(Series series, int pos)
Add a series to this Graph, plotted against the specified axes.- Parameters:
series
- the Series to add to the graphpos
- the axes to plot the series against. One ofBOTTOMLEFT
,BOTTOMRIGHT
,TOPLEFT
orTOPRIGHT
.- Throws:
IllegalArgumentException
- if the series has already been added
-
getSeries
public Series getSeries(String name)
Return the series with the specified name from this AxesGraph, ornull
if no such series has been added yet- Parameters:
name
- the name of the series to return- Returns:
- the specified Series, or
null
if it doesn't exist in this Graph
-
setAxis
public void setAxis(int pos, Axis axis)
Set the specified axis. The default Axis is usually a plainNumericAxis
, but this method can be used to override this to plot dates, currencies and so on. The "Z" axis can be useful when graphs are displayed in 3D - it can be set to aZAxis
object to show the names of each Series plotted on the graph- Parameters:
pos
- which axis to set - one ofAxis.LEFT
,Axis.TOP
,Axis.RIGHT
Axis.BOTTOM
orAxis.ZAXIS
axis
- the axis to use- Throws:
IllegalArgumentException
- if the specified Axis has already been used elsewhere- See Also:
getAxis(int)
-
getAxis
public Axis getAxis(int pos)
Get the axis that's currently in the specified position on the graph. If you've already called
setAxis
to set it, then that's the one that's returned. If one hasn't been set, a default axis is used - this will be aNullAxis
if no series have been plotted against this axis, aNumericAxis
if a series has been plotted, or in the case of the X-axis of a BarSeries, aBarAxis
is returned.Because the returned axis may change depending on which Series have been added to the graph, it's recommended that this method is called after all the Series have been added.
- Parameters:
pos
- which axis to get - one ofAxis.LEFT
,Axis.TOP
,Axis.RIGHT
Axis.BOTTOM
orAxis.ZAXIS
- Returns:
- the Axis currently in use on the specified side of the Graph
- See Also:
setAxis(int, org.faceless.graph2.Axis)
-
setBackWallPaint
public void setBackWallPaint(Paint paint)
Set the paint to use on the back wall. This method is intended for simple paints - for stripes, see thesetBackWallPaint(Paint[], Color, int, int, double[])
method.- Parameters:
paint
- the paint to use on the back wall, ornull
to not paint the back wall- See Also:
Axis.setWallPaint(java.awt.Paint)
-
setBackWallPaint
public void setBackWallPaint(Paint[] paints, Color stripe, int axis, int alt, double[] dash)
Set the paint to use on the back wall to a series of stripes. Note this now method calls
setBackWallPaint(StripedPaint)
, which is a more flexible way to achieve the same results. The stripes will be painted in the colors specified bypaints
, and ifstripe
is not null the stripes will be separated by lines of that color. The stripes will be aligned with the Axis specified byaxis
, and ifalt
is not 0, lines will also be drawn matching that axis (which must be perpendicular toaxis
).Some examples to clarify: To draw horizontal stripes in blue and green:
setBackWallPaint(new Paint[] { Color.blue, Color.green }, null, Axis.LEFT, 0, null);
To draw a grid of gray lines with no fill color
setBackWallPaint(null, Color.gray, Axis.LEFT, Axis.BOTTOM, null);
- Parameters:
paints
- the colors to use to paint the background - may be null for no paint, or an array of one or morePaint
objects which will be used to stripe the wallstripe
- the color to use to draw lines between the stripes, ornull
for no stripesaxis
- The axis to align the stripes to. One ofAxis.LEFT
,Axis.RIGHT
,Axis.TOP
orAxis.BOTTOM
alt
- The alternate axis to use when drawing a grid. Ifaxis
isAxis.LEFT
orAxis.RIGHT
, must beAxis.TOP
orAxis.BOTTOM
, and vice versa. If no grid is required this value may be -1.dash
- The dash pattern to use to draw the stripe - specified the same way asStyle.setLineDash(double[])
. If no stripe is to be drawn (or if it's not going to be dashed) this may be null.
-
setBackWallPaint
public void setBackWallPaint(StripedPaint paint)
Set the paint to use on the back wall to a
StripedPaint
. See the other method with the same name for some examples of what sort of functionality is available
-
setHorizontalScale
public void setHorizontalScale(double b1, double t1, double b2, double t2)
Change the scaling ratio for the horizontal axes. When plotting different Series against the top and bottom axes, the library needs to work out how the two axes are scaled against eachother. This method allows the user to specify to "control points" on each axis which are aligned against eachother - one to the left, and one to the right. From these two points the two axes can be scaled.- Parameters:
b1
- first value on the bottom axis (aligned with t1)t1
- first value on the top axis (aligned with b1)b2
- second value on the bottom axis (aligned with t2)t2
- second value on the top axis (aligned with b2)- Throws:
IllegalArgumentException
- if b1<=b2 and t1>=t2- See Also:
setVerticalScale(double, double, double, double)
-
setVerticalScale
public void setVerticalScale(double l1, double r1, double l2, double r2)
Change the scaling ratio for the vertical axes. When plotting series against the left and right axes, the library needs to work out how the two axes are scaled against eachother. This method allows the user to specify to "control points" on each axis which are aligned against eachother - one near the bottom, and one near the top. From these two points the two axes can be scaled.- Parameters:
l1
- first value on the left axis (aligned with r1)r1
- first value on the right axis (aligned with l1)l2
- second value on the left axis (aligned with r2)r2
- second value on the right axis (aligned with r2)- Throws:
IllegalArgumentException
- if l1<=l2 and r1>=r2- See Also:
setHorizontalScale(double, double, double, double)
-
-