Package org.faceless.graph
Class LineGraph
- java.lang.Object
-
- org.faceless.graph.Graph
-
- org.faceless.graph.AxesGraph
-
- org.faceless.graph.AbstractLineGraph
-
- org.faceless.graph.LineGraph
-
public class LineGraph extends AbstractLineGraph
A subclass of AbstractLineGraph that plots one or more separate curves - a typical Line Graph.
This class changes the default for
optionXAxisAtZeroandoptionYAxisAtZeroto true.Here is a simple example that graphs two curves - the first, a set of datapoints defined by a
DataCurve, the second aSplinecurve that's fitted to theDataCurve.import org.faceless.graph.output.ImageOutput; import org.faceless.graph.math.*; import java.awt.Color; // Create a simple datacurve with 4 points. // DataCurve data = new DataCurve(); data.set(1,10); data.set(2,15); data.set(3,8); data.set(5,11); // Plot the data in red on a linegraph, with a diamond // at each point. // LineGraph g = new LineGraph(); g.setCurve("My Data", data, Color.red); g.setCurveMarker("My Data", LineGraph.MARKER_DIAMOND); // Add a "smoothed" version of this DataCurve in green. // Curve smooth = new Spline(Spline.CATMULLROM, data); g.setCurve("Smoothed Data", smooth, Color.green); // Add a title to the graph // g.optionTitle("My First Line Graph"); // Render to an image that's 400x400 // ImageOutput out = new ImageOutput(400,400); out.render(g);
-
-
Field Summary
Fields Modifier and Type Field Description static intKEY_SHOW_MARKERSIf markers are to be displayed on the key, add this value to the parameter passed toGraph.optionDisplayKey(int).static intMARKER_BIGAdd this value to the marker type to double the size of the marker.static intMARKER_CIRCLEA marker in the shape of a circlestatic intMARKER_DIAMONDA marker in the shape of a diamondstatic intMARKER_DOWNTRIANGLEA marker in the shape of a triangle pointing downstatic intMARKER_LINEA marker that looks like a join in the line.static intMARKER_NOBORDERAdd this value to the marker type to remove the border from around the marker.static intMARKER_NONENo marker at all.static intMARKER_OCTAGONA marker in the shape of an octagonstatic intMARKER_SMALLAdd this value to the marker type to reduce the size of the marker.static intMARKER_SQUAREA marker in the shape of a squarestatic intMARKER_UPTRIANGLEA marker in the shape of a triangle pointing upstatic intMARKERS_ONLYA special type of marker indicator that should be OR'ed with the marker type to indicate that only markers should be drawn - i.e. no lines, just markers.-
Fields inherited from class org.faceless.graph.AbstractLineGraph
maxval, maxx, minval, minx
-
Fields inherited from class org.faceless.graph.AxesGraph
absolutemaxy, absoluteminy, axesmaxx, axesmaxy, axesmaxz, axesminx, axesminy, axesminz, axesstyle, boxstyle, data, xaxeslabelstyle, xaxestextstyle, xfloat, xformatter, xwallstyle, yaxeslabelstyle, yaxestextstyle, yfloat, yformatter, ywallstyle, zaxestextstyle, zfloat, zformatter, zwallstyle
-
Fields inherited from class org.faceless.graph.Graph
canvas, key, KEY_BOXED_BOTTOM, KEY_BOXED_LEFT, KEY_BOXED_RIGHT, KEY_BOXED_TOP, KEY_NONE, keyboxstyle, keypadding, keystyle, keytype, subtitle, subtitlestyle, title, titlepadding, titlestyle, xrotation, yrotation, zrotation
-
-
Constructor Summary
Constructors Constructor Description LineGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomplete()Complete is the first method that's called by a Graph when it's rendered.voidoptionLineThickness(double val)Set the "thickness" of the lines when drawing two-dimensional graphs.protected doubleplotLine(int set, Curve c, double prevlastval, double prevval, double lastx, double x, double linewidth, boolean isLast, Map m)Actually plot the line.protected voidpostDrawLines()voidsetCurveMarker(String name, int marker)Set a marker to show significant points on the curve Not all points have significant points, but forDataCurvecurves there is a significant point at each data item.-
Methods inherited from class org.faceless.graph.AbstractLineGraph
optionCurveDepth, optionFunctionSmoothness, optionMaxDataPoints, optionMaxX, optionMinX, setCurve, setCurve
-
Methods inherited from class org.faceless.graph.AxesGraph
optionAxisStyle, optionBoxColor, optionFloorStyle, optionMaxY, optionMinY, optionXAxisAtZero, optionXAxisLabel, optionXAxisLabelStyle, optionXAxisStyle, optionXAxisTextRotation, optionXFormatter, optionXStretchToZero, optionYAxisAtZero, optionYAxisLabel, optionYAxisLabelStyle, optionYAxisStyle, optionYAxisTextRotation, optionYFormatter, optionYStretchToZero, optionYWallStyle, optionZAxisStyle, optionZFormatter, optionZWallStyle, postcomplete, postpostcomplete, prescalecomplete
-
Methods inherited from class org.faceless.graph.Graph
addElement, getDefaultBorderColor, getFontScale, optionDisplayKey, optionFixedAspectRatio, optionKeyBoxStyle, optionKeyStyle, optionRemoveBackFace, optionSubTitle, optionSubTitleStyle, optionTitle, optionTitleStyle, optionXRotation, optionYRotation, optionZRotation, setDefaultBorderColor, setDefaultColors, setDefaultLineThickness, setFontScale, setLicenseKey, setLightLevel, setLightVector, setPieEdgeDegrees, toCanvas
-
-
-
-
Field Detail
-
KEY_SHOW_MARKERS
public static final int KEY_SHOW_MARKERS
If markers are to be displayed on the key, add this value to the parameter passed toGraph.optionDisplayKey(int). For example,linegraph.optionDisplayKey(Graph.KEY_BOXED_BOTTOM + LineGraph.KEY_SHOW_MARKERS)- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_NONE
public static final int MARKER_NONE
No marker at all.- See Also:
- Constant Field Values
-
MARKER_CIRCLE
public static final int MARKER_CIRCLE
A marker in the shape of a circle- Since:
- 1.0.10
- See Also:
- Constant Field Values
-
MARKER_SQUARE
public static final int MARKER_SQUARE
A marker in the shape of a square- See Also:
- Constant Field Values
-
MARKER_OCTAGON
public static final int MARKER_OCTAGON
A marker in the shape of an octagon- See Also:
- Constant Field Values
-
MARKER_DIAMOND
public static final int MARKER_DIAMOND
A marker in the shape of a diamond- See Also:
- Constant Field Values
-
MARKER_LINE
public static final int MARKER_LINE
A marker that looks like a join in the line. This is the default.- See Also:
- Constant Field Values
-
MARKER_UPTRIANGLE
public static final int MARKER_UPTRIANGLE
A marker in the shape of a triangle pointing up- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_DOWNTRIANGLE
public static final int MARKER_DOWNTRIANGLE
A marker in the shape of a triangle pointing down- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_BIG
public static final int MARKER_BIG
Add this value to the marker type to double the size of the marker. For example,setCurveMarker("mycurve", MARKER_SQUARE+MARKER_BIG)- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_SMALL
public static final int MARKER_SMALL
Add this value to the marker type to reduce the size of the marker. For example,setCurveMarker("mycurve", MARKER_SQUARE+MARKER_SMALL)- Since:
- 1.0.10
- See Also:
- Constant Field Values
-
MARKER_NOBORDER
public static final int MARKER_NOBORDER
Add this value to the marker type to remove the border from around the marker. For example,setCurveMarker("mycurve", MARKER_CIRCLE+MARKER_NOBORDER)- Since:
- 1.0.10
- See Also:
- Constant Field Values
-
MARKERS_ONLY
public static final int MARKERS_ONLY
A special type of marker indicator that should be OR'ed with the marker type to indicate that only markers should be drawn - i.e. no lines, just markers. This needs to be used with SQUARES, OCTAGONS, DIAMONDS, CIRCLES and TRIANGLES only - the line will simply disappear if it's used with any other type. For example, to draw a small circle at each point but no line inbetween, do:setCurveMarker("mycurve", MARKER_CIRCLE+MARKER_SMALL+MARKERS_ONLY)- See Also:
- Constant Field Values
-
-
Method Detail
-
setCurveMarker
public void setCurveMarker(String name, int marker)
Set a marker to show significant points on the curve Not all points have significant points, but forDataCurvecurves there is a significant point at each data item. Whether a marker is plotted depends on the value passed to this function.- Parameters:
name- The name of the curvemarker- The type if marker. Can beMARKER_NONE,MARKER_LINE(the default),MARKER_SQUARE,MARKER_CIRCLEMARKER_DIAMOND,MARKER_OCTAGON,MARKER_UPTRIANGLEorMARKER_DOWNTRIANGLE
-
optionLineThickness
public void optionLineThickness(double val)
Set the "thickness" of the lines when drawing two-dimensional graphs. This has no effect if the graph is rotated in the X or Y direction, and may not be supported by all subclasses ofOutput. It's mainly intended for plotting graphs to high-resolution output devices like PDF or PostScript.
-
complete
protected void complete()
Description copied from class:GraphComplete is the first method that's called by a Graph when it's rendered. It should take the data from the dataset and add the various elements that it needs to the Graph. The first thing it should do, however, is callsuper.complete().
-
plotLine
protected double plotLine(int set, Curve c, double prevlastval, double prevval, double lastx, double x, double linewidth, boolean isLast, Map m)Description copied from class:AbstractLineGraphActually plot the line. This method needs to be filled in by concrete subclasses of this class. This method must handleNaNand Infinite values. All current subclasses deal with these by skipping those points and leaving a gap in the line.- Specified by:
plotLinein classAbstractLineGraph- Parameters:
set- The number of the set that's being plottedc- The curve that's being plottedprevlastval- The value returned by the last X value from the previous set. Set toDouble.NaNif there was no previous set, or no last X value.prevval- The value returned by this X value from the previous set. Set toDouble.NaNif no previous set.lastx- The last X value passed in. Set toDouble.NaNif no previous X value exists.x- The current X value.linewidth- The width (or rather depth) of the line to be plotted.isLast- Whether this X value is the last value in the set.m- A map which can be used by plotLine to pass data between other calls to plotLine. A common use is to set a "start" value if this is the first X value in the set.
-
postDrawLines
protected void postDrawLines()
- Overrides:
postDrawLinesin classAbstractLineGraph
-
-