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 leftaxes. 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. TheAxisclass is the superclass of all the different types of Axes which may be used, and thesetAxisandgetAxismethods 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.setWallPaintmethod. 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 intBOTTOMLEFTConstant used by theaddSeriesmethod to plot the series against the bottom and left axes.static intBOTTOMRIGHTConstant used by theaddSeriesmethod to plot the series against the bottom and right axes.static intTOPLEFTConstant used by theaddSeriesmethod to plot the series against the top and left axes.static intTOPRIGHTConstant used by theaddSeriesmethod 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 voidaddSeries(Series series)Add a series to this Graph, plotted against the bottom and left axes.voidaddSeries(Series series, int pos)Add a series to this Graph, plotted against the specified axes.AxisgetAxis(int pos)Get the axis that's currently in the specified position on the graph.SeriesgetSeries(String name)Return the series with the specified name from this AxesGraph, ornullif no such series has been added yetvoidsetAxis(int pos, Axis axis)Set the specified axis.voidsetBackWallPaint(Paint paint)Set the paint to use on the back wall.voidsetBackWallPaint(Paint[] paints, Color stripe, int axis, int alt, double[] dash)Set the paint to use on the back wall to a series of stripes.voidsetBackWallPaint(StripedPaint paint)Set the paint to use on the back wall to aStripedPaint.voidsetHorizontalScale(double b1, double t1, double b2, double t2)Change the scaling ratio for the horizontal axes.voidsetVerticalScale(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 theaddSeriesmethod to plot the series against the bottom and left axes.- See Also:
- Constant Field Values
-
BOTTOMRIGHT
public static final int BOTTOMRIGHT
Constant used by theaddSeriesmethod to plot the series against the bottom and right axes.- See Also:
- Constant Field Values
-
TOPLEFT
public static final int TOPLEFT
Constant used by theaddSeriesmethod to plot the series against the top and left axes.- See Also:
- Constant Field Values
-
TOPRIGHT
public static final int TOPRIGHT
Constant used by theaddSeriesmethod 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- theSeriesto 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,TOPLEFTorTOPRIGHT.- 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, ornullif no such series has been added yet- Parameters:
name- the name of the series to return- Returns:
- the specified Series, or
nullif 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 aZAxisobject to show the names of each Series plotted on the graph- Parameters:
pos- which axis to set - one ofAxis.LEFT,Axis.TOP,Axis.RIGHTAxis.BOTTOMorAxis.ZAXISaxis- 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
setAxisto set it, then that's the one that's returned. If one hasn't been set, a default axis is used - this will be aNullAxisif no series have been plotted against this axis, aNumericAxisif a series has been plotted, or in the case of the X-axis of a BarSeries, aBarAxisis 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.RIGHTAxis.BOTTOMorAxis.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, ornullto 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 ifstripeis not null the stripes will be separated by lines of that color. The stripes will be aligned with the Axis specified byaxis, and ifaltis 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 morePaintobjects which will be used to stripe the wallstripe- the color to use to draw lines between the stripes, ornullfor no stripesaxis- The axis to align the stripes to. One ofAxis.LEFT,Axis.RIGHT,Axis.TOPorAxis.BOTTOMalt- The alternate axis to use when drawing a grid. IfaxisisAxis.LEFTorAxis.RIGHT, must beAxis.TOPorAxis.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)
-
-