public class RrdGraphDef extends Object implements RrdGraphConstants
RrdGraph
class which
will actually create the graph.
The text printed below the actual graph can be formated by appending
special escaped characters at the end of a text. When ever such a
character occurs, all pending text is pushed onto the graph according to
the character specified.
Valid markers are: \j for justified, \l for left aligned, \r for right
aligned and \c for centered.
Normally there are two space characters inserted between every two
items printed into the graph. The space following a string can be
suppressed by putting a \g at the end of the string. The \g also squashes
any space inside the string if it is at the very end of the string.
This can be used in connection with %s to suppress empty unit strings.
A special case is COMMENT:\s this inserts some additional vertical
space before placing the next row of legends.
When text has to be formated without special instructions from your
side, RRDTool will automatically justify the text as soon as one string
goes over the right edge. If you want to prevent the justification
without forcing a newline, you can use the special tag \J at the end of
the string to disable the auto justification.RrdGraphConstants.FontConstructor
ALIGN_CENTER_MARKER, ALIGN_JUSTIFIED_MARKER, ALIGN_LEFT_MARKER, ALIGN_LEFTNONL_MARKER, ALIGN_RIGHT_MARKER, BLIND_COLOR, COLOR_ARROW, COLOR_BACK, COLOR_CANVAS, COLOR_FONT, COLOR_FRAME, COLOR_GRID, COLOR_MGRID, COLOR_NAMES, COLOR_SHADEA, COLOR_SHADEB, COLOR_XAXIS, DAY, DEFAULT_ARROW_COLOR, DEFAULT_BACK_COLOR, DEFAULT_BASE, DEFAULT_CANVAS_COLOR, DEFAULT_END, DEFAULT_FONT_COLOR, DEFAULT_FRAME_COLOR, DEFAULT_GRID_COLOR, DEFAULT_HEIGHT, DEFAULT_IMAGE_FORMAT, DEFAULT_IMAGE_QUALITY, DEFAULT_LARGE_FONT, DEFAULT_MGRID_COLOR, DEFAULT_SHADEA_COLOR, DEFAULT_SHADEB_COLOR, DEFAULT_SMALL_FONT, DEFAULT_START, DEFAULT_UNITS_LENGTH, DEFAULT_WIDTH, DEFAULT_XAXIS_COLOR, FIRST_DAY_OF_WEEK, FRIDAY, GATOR_FONT, GLUE_MARKER, GRID_STROKE, HOUR, IN_MEMORY_IMAGE, LEGEND_BOX, LEGEND_BOX_SPACE, LEGEND_INTERSPACING, LEGEND_LEADING, LEGEND_LEADING_SMALL, MARKERS, MINUTE, MONDAY, MONTH, NO_JUSTIFICATION_MARKER, PADDING_BOTTOM, PADDING_LEFT, PADDING_LEGEND, PADDING_PLOT, PADDING_RIGHT, PADDING_TITLE, PADDING_TOP, PADDING_VLABEL, SATURDAY, SECOND, SUNDAY, THURSDAY, TICK_STROKE, TUESDAY, VERTICAL_SPACING_MARKER, WEDNESDAY, WEEK, YEAR
Constructor and Description |
---|
RrdGraphDef()
Creates RrdGraphDef object and sets default time span (default ending time is 'now',
default starting time is 'end-1day'.
|
Modifier and Type | Method and Description |
---|---|
void |
area(String srcName,
Paint color)
Plots requested data in the form of the filled area starting from zero, using
the color specified.
|
void |
area(String srcName,
Paint color,
String legend)
Plots requested data in the form of the filled area starting from zero, using
the color specified.
|
void |
comment(String text)
Comment to be printed on the graph.
|
void |
datasource(String name,
FetchData fetchData)
Creates a new 'fetched' datasource.
|
void |
datasource(String name,
Plottable plottable)
Creates a new (plottable) datasource.
|
void |
datasource(String name,
String rpnExpression)
Create a new virtual datasource by evaluating a mathematical
expression, specified in Reverse Polish Notation (RPN).
|
void |
datasource(String name,
String defName,
ConsolFun consolFun)
Creates a new (static) virtual datasource.
|
void |
datasource(String name,
String rrdPath,
String dsName,
ConsolFun consolFun)
Defines virtual datasource.
|
void |
datasource(String name,
String rrdPath,
String dsName,
ConsolFun consolFun,
String backend)
Defines virtual datasource.
|
void |
gprint(String srcName,
ConsolFun consolFun,
String format)
This method does basically the same thing as
print(String, ConsolFun, String) ,
but the result is printed on the graph itself, below the chart area. |
void |
hrule(double value,
Paint color)
Draws a horizontal rule into the graph.
|
void |
hrule(double value,
Paint color,
String legend)
Draws a horizontal rule into the graph and optionally adds a legend.
|
void |
hrule(double value,
Paint color,
String legend,
float width)
Draws a horizontal rule into the graph and optionally adds a legend.
|
void |
hspan(double start,
double end,
Paint color)
Draws a horizontal span into the graph.
|
void |
hspan(double start,
double end,
Paint color,
String legend)
Draws a horizontal span into the graph and optionally adds a legend.
|
void |
line(String srcName,
Paint color)
Plots requested data as a line, using the color specified.
|
void |
line(String srcName,
Paint color,
float width)
Plots requested data as a line, using the color and the line width specified.
|
void |
line(String srcName,
Paint color,
String legend)
Plots requested data as a line, using the color specified.
|
void |
line(String srcName,
Paint color,
String legend,
float width)
Plots requested data as a line, using the color and the line width specified.
|
void |
percentile(String name,
String defName)
Create a new virtual datasource to get the 95th percentile value from another datasource
|
void |
percentile(String name,
String defName,
double percent)
Create a new virtual datasource to get a percentile value from another datasource
|
void |
print(String srcName,
ConsolFun consolFun,
String format)
Calculates the chosen consolidation function CF over the given datasource
and creates the result by using the given format string.
|
void |
setAltAutoscale(boolean altAutoscale)
Computes Y range based on function absolute minimum and maximum
values.
|
void |
setAltAutoscaleMax(boolean altAutoscaleMax)
Computes Y range based on function absolute minimum and maximum
values.
|
void |
setAltYGrid(boolean altYGrid)
Places Y grid dynamically based on graph Y range.
|
void |
setAltYMrtg(boolean altYMrtg)
Use this method to request MRTG-like graph (false by default)
|
void |
setAntiAliasing(boolean antiAliasing)
Controls if the chart area of the image should be antialiased or not.
|
void |
setBackgroundImage(String backgroundImage)
Sets background image - currently, only PNG images can be used as background.
|
void |
setBase(double base)
Sets default base for magnitude scaling.
|
void |
setColor(int colorTag,
Paint color)
Overrides the colors for the standard elements of the graph.
|
void |
setColor(String colorName,
Paint color)
Overrides the colors for the standard elements of the graph by element name.
|
void |
setDrawXGrid(boolean drawXGrid)
Sets visibility of the X-axis grid.
|
void |
setDrawYGrid(boolean drawYGrid)
Sets visibility of the Y-axis grid.
|
void |
setEndTime(long time)
Sets the time when the graph should end.
|
void |
setFilename(String filename)
Sets the name of the graph to generate.
|
void |
setFirstDayOfWeek(int firstDayOfWeek)
Sets first day of the week.
|
void |
setForceRulesLegend(boolean forceRulesLegend)
Force the generation of HRULE and VRULE legend even if those HRULE
or VRULE will not be drawn because out of graph boundaries.
|
void |
setGridStroke(Stroke gridStroke)
Set the Stroke used to draw grid
|
void |
setHeight(int height)
Sets height of the drawing area within the graph.
|
void |
setImageFormat(String imageFormat)
Sets image format.
|
void |
setImageInfo(String imageInfo)
Creates additional image information.
|
void |
setImageQuality(float imageQuality)
Sets image quality.
|
void |
setInterlaced(boolean interlaced)
Creates interlaced or progressive mode image.
|
void |
setLargeFont(Font largeFont)
Sets title font.
|
void |
setLazy(boolean lazy)
Creates graph only if the current graph is out of date or not existent.
|
void |
setLocale(Locale locale)
Set the locale used for the legend.
|
void |
setLogarithmic(boolean logarithmic)
Sets logarithmic y-axis scaling.
|
void |
setMaxValue(double maxValue)
Defines the value normally located at the upper border of the
graph.
|
void |
setMinValue(double minValue)
Sets the lower limit of a graph.
|
void |
setNoLegend(boolean noLegend)
Suppress generation of legend, only render the graph.
|
void |
setNoMinorGrid(boolean noMinorGrid)
Use this method to turn off minor grid lines (printed by default)
|
void |
setOnlyGraph(boolean onlyGraph)
Suppresses anything but the graph.
|
void |
setOverlayImage(String overlayImage)
Sets overlay image - currently, only PNG images can be used as overlay.
|
void |
setPoolUsed(boolean poolUsed)
Sets RrdDbPool usage policy (defaults to true).
|
void |
setRigid(boolean rigid)
Sets rigid boundaries mode.
|
void |
setShowSignature(boolean showSignature)
Shows or hides graph signature (gator) in the top right corner of the graph
|
void |
setSmallFont(Font smallFont)
Sets default font for graphing.
|
void |
setStartTime(long time)
Sets the time when the graph should begin.
|
void |
setStep(long step)
Suggests which time step should be used by Rrd4j while processing data from RRD files.
|
void |
setTextAntiAliasing(boolean textAntiAliasing)
Controls if the text should be antialiased or not.
|
void |
setTickStroke(Stroke tickStroke)
Set the stroke used to draw ticks
|
void |
setTimeAxis(int minorUnit,
int minorUnitCount,
int majorUnit,
int majorUnitCount,
int labelUnit,
int labelUnitCount,
int labelSpan,
String simpleDateFormat)
Configures x-axis grid and labels.
|
void |
setTimeSpan(long[] timestamps)
Sets starting and ending time for the for the graph.
|
void |
setTimeSpan(long startTime,
long endTime)
Sets starting and ending time for the for the graph.
|
void |
setTimeZone(TimeZone tz)
Set the time zone used for the legend.
|
void |
setTitle(String title)
Defines a title to be written into the graph.
|
void |
setUnit(String unit)
Sets unit to be displayed on y axis.
|
void |
setUnitsExponent(int unitsExponent)
Sets the 10**unitsExponent scaling of the y-axis values.
|
void |
setUnitsLength(int unitsLength)
Sets the character width on the left side of the graph for
y-axis values.
|
void |
setValueAxis(double gridStep,
int labelFactor)
Sets vertical axis grid and labels.
|
void |
setVerticalLabel(String verticalLabel)
Sets vertical label on the left side of the graph.
|
void |
setWidth(int width)
Sets width of the drawing area within the graph.
|
void |
stack(String srcName,
Paint color)
Does the same as
line(String, java.awt.Paint) ,
but the graph gets stacked on top of the
previous LINE, AREA or STACK graph. |
void |
stack(String srcName,
Paint color,
String legend)
Does the same as
line(String, java.awt.Paint, String) ,
but the graph gets stacked on top of the
previous LINE, AREA or STACK graph. |
void |
vrule(long timestamp,
Paint color)
Draws a vertical rule into the graph.
|
void |
vrule(long timestamp,
Paint color,
String legend)
Draws a vertical rule into the graph and optionally adds a legend
|
void |
vrule(long timestamp,
Paint color,
String legend,
float width)
Draws a vertical rule into the graph and optionally adds a legend
|
void |
vspan(long start,
long end,
Paint color)
Draws a vertical span into the graph.
|
void |
vspan(long start,
long end,
Paint color,
String legend)
Draws a vertical span into the graph and optionally adds a legend.
|
public RrdGraphDef()
public void setStartTime(long time)
time
- Starting time for the graph in seconds since epochpublic void setEndTime(long time)
time
- Ending time for the graph in seconds since epochpublic void setTimeSpan(long startTime, long endTime)
startTime
- Starting time in seconds since epochendTime
- Ending time in seconds since epochpublic void setTimeSpan(long[] timestamps)
timestamps
- Array of timestamps. The first array item will be chosen for the starting
timestamp. The last array item will be chosen for the ending timestamp.public void setPoolUsed(boolean poolUsed)
RrdDbPool
will be used to
access individual RRD files. If set to false, RRD files will be accessed directly.poolUsed
- true, if RrdDbPool class should be used. False otherwise.public void setFilename(String filename)
filename
- Path to the image filepublic void setTimeAxis(int minorUnit, int minorUnitCount, int majorUnit, int majorUnitCount, int labelUnit, int labelUnitCount, int labelSpan, String simpleDateFormat)
setTimeAxis(RrdGraphConstants.MINUTE, 10, RrdGraphConstants.HOUR, 1, RrdGraphConstants.HOUR, 1, 0, "%H:%M")The precision in this example is 0 because the %X format is exact. If the label was the name of the day, we would have had a precision of 24 hours, because when you say something like 'Monday' you mean the whole day and not Monday morning 00:00. Thus the label should be positioned at noon. By defining a precision of 24 hours or rather 86400 seconds, you make sure that this happens.
minorUnit
- Minor grid unit. Minor grid, major grid and label units
can be one of the following constants defined in
RrdGraphConstants
: SECOND
,
MINUTE
, HOUR
,
DAY
, WEEK
,
MONTH
, YEAR
.minorUnitCount
- Number of minor grid units between minor grid lines.majorUnit
- Major grid unit.majorUnitCount
- Number of major grid units between major grid lines.labelUnit
- Label unit.labelUnitCount
- Number of label units between labels.labelSpan
- Label precisionsimpleDateFormat
- Date format (SimpleDateFormat pattern of strftime-like pattern)public void setValueAxis(double gridStep, int labelFactor)
gridStep
- Minor grid steplabelFactor
- Specifies how many minor minor grid steps will appear between labels
(major grid lines)public void setAltYGrid(boolean altYGrid)
altYGrid
- true, if Y grid should be calculated dynamically (defaults to false)public void setNoMinorGrid(boolean noMinorGrid)
noMinorGrid
- true, to turn off, false to turn on (default)public void setAltYMrtg(boolean altYMrtg)
altYMrtg
- true, to create MRTG-like graph, false otherwise (default)public void setAltAutoscale(boolean altAutoscale)
altAutoscale
- true to request alternative autoscaling, false otherwise
(default).public void setAltAutoscaleMax(boolean altAutoscaleMax)
altAutoscaleMax
- true to request alternative autoscaling, false
otherwise (default)public void setUnitsExponent(int unitsExponent)
unitsExponent
- a int.public void setUnitsLength(int unitsLength)
unitsLength
- Number of characters on the left side of the graphs
reserved for vertical axis labels.public void setVerticalLabel(String verticalLabel)
verticalLabel
- Vertical axis labelpublic void setWidth(int width)
width
- Width of the drawing area.public void setHeight(int height)
height
- Height of the drawing area.public void setInterlaced(boolean interlaced)
interlaced
- true, if GIF image should be interlaced.public void setImageInfo(String imageInfo)
print(String, ConsolFun, String)
function.
The format string is supplied with the following parameters:
filename, xsize and ysize (in that particular order).
For example, in order to generate an IMG tag
suitable for including the graph into a web page, the command
would look like this:
setImageInfo("<IMG SRC='/img/%s' WIDTH='%d' HEIGHT='%d' ALT='Demo'>");
imageInfo
- Image info format. Use %s placeholder for filename, %d placeholder for
image width and height.public void setImageFormat(String imageFormat)
imageFormat
- Any value as return by ImageIO.getReaderFormatNames()
public void setBackgroundImage(String backgroundImage)
backgroundImage
- Path to background imagepublic void setOverlayImage(String overlayImage)
overlayImage
- Path to overlay imagepublic void setUnit(String unit)
unit
- Unit descriptionpublic void setLazy(boolean lazy)
lazy
- true, if graph should be 'lazy', false otherwise (default)public void setMinValue(double minValue)
minValue
- Minimal value displayed on the graphpublic void setMaxValue(double maxValue)
setRigid(boolean)
method as well.maxValue
- Maximal value displayed on the graph.public void setRigid(boolean rigid)
true
argument you can disable this behavior.rigid
- true if upper and lower limits should not be expanded to accommodate
values outside of the specified range. False otherwise (default).public void setBase(double base)
base
- Base value (defaults to 1000.0)public void setLogarithmic(boolean logarithmic)
logarithmic
- true, for logarithmic scaling, false otherwise (default).public void setColor(int colorTag, Paint color)
RrdGraphConstants
:
COLOR_BACK
ground,
COLOR_CANVAS
,
COLOR_XAXIS
,
COLOR_SHADEA
left/top border,
COLOR_SHADEB
right/bottom border,
COLOR_GRID
,
COLOR_MGRID
major grid,
COLOR_FONT
,
COLOR_FRAME
and axis of the graph or
COLOR_ARROW
. This
method can be called multiple times to set several colors.colorTag
- Color tag, as explained above.color
- Any color (paint) you likepublic void setColor(String colorName, Paint color)
setColor(int, java.awt.Paint)
for full explanation.colorName
- One of the following strings: "BACK", "CANVAS", "SHADEA", "SHADEB",
"GRID", "MGRID", "FONT", "FRAME", "ARROW"color
- Any color (paint) you likepublic void setNoLegend(boolean noLegend)
noLegend
- true if graph legend should be omitted. False otherwise (default).public void setOnlyGraph(boolean onlyGraph)
onlyGraph
- true if only graph should be created, false otherwise (default).public void setForceRulesLegend(boolean forceRulesLegend)
forceRulesLegend
- true if rule legend should be always printed,
false otherwise (default).public void setTitle(String title)
title
- Graph title.public void setStep(long step)
step
- Desired time step (don't use this method if you don't know what you're doing).public void setSmallFont(Font smallFont)
smallFont
- Default font for graphing. Use only monospaced fonts.public void setLargeFont(Font largeFont)
largeFont
- Font to be used for graph title.public void datasource(String name, String rrdPath, String dsName, ConsolFun consolFun)
datasource(String, String)
or
gprint(String, ConsolFun, String)
.name
- Source namerrdPath
- Path to RRD filedsName
- Datasource name in the specified RRD fileconsolFun
- Consolidation function (AVERAGE, MIN, MAX, LAST)public void datasource(String name, String rrdPath, String dsName, ConsolFun consolFun, String backend)
datasource(String, String)
or
gprint(String, ConsolFun, String)
.name
- Source namerrdPath
- Path to RRD filedsName
- Datasource name in the specified RRD fileconsolFun
- Consolidation function (AVERAGE, MIN, MAX, LAST)backend
- Backend to be used while fetching data from a RRD file.public void datasource(String name, String rpnExpression)
name
- Source namerpnExpression
- RPN expression.public void datasource(String name, String defName, ConsolFun consolFun)
name
- Source namedefName
- Other source nameconsolFun
- Consolidation function to be applied to other datasource.public void datasource(String name, Plottable plottable)
name
- Source name.plottable
- Plottable object.public void datasource(String name, FetchData fetchData)
FetchData
object.name
- Source name.fetchData
- FetchData object.public void percentile(String name, String defName)
name
- Source name.defName
- Other source name.public void percentile(String name, String defName, double percent)
name
- Source name.defName
- Other source name.percent
- The percent valuepublic void print(String srcName, ConsolFun consolFun, String format)
RrdGraphInfo
object which is retrieved
from the object
once the graph is created.srcName
- Virtual source nameconsolFun
- Consolidation function to be applied to the sourceformat
- Format string (like "average = %10.3f %s")public void gprint(String srcName, ConsolFun consolFun, String format)
print(String, ConsolFun, String)
,
but the result is printed on the graph itself, below the chart area.srcName
- Virtual source nameconsolFun
- Consolidation function to be applied to the sourceformat
- Format string (like "average = %10.3f %s")public void comment(String text)
text
- Comment textpublic void hrule(double value, Paint color)
value
- Position of the rulecolor
- Rule colorpublic void hrule(double value, Paint color, String legend)
value
- Position of the rulecolor
- Rule colorlegend
- Legend text. If null, legend text will be omitted.public void hrule(double value, Paint color, String legend, float width)
value
- Position of the rulecolor
- Rule colorlegend
- Legend text. If null, legend text will be omitted.width
- Rule widthpublic void vrule(long timestamp, Paint color)
timestamp
- Position of the rule (seconds since epoch)color
- Rule colorpublic void vrule(long timestamp, Paint color, String legend)
timestamp
- Position of the rule (seconds since epoch)color
- Rule colorlegend
- Legend text. Use null to omit the text.public void vrule(long timestamp, Paint color, String legend, float width)
timestamp
- Position of the rule (seconds since epoch)color
- Rule colorlegend
- Legend text. Use null to omit the text.width
- Rule widthpublic void hspan(double start, double end, Paint color)
start
- Starting value of the spanend
- Ending value of the spancolor
- Rule colorpublic void hspan(double start, double end, Paint color, String legend)
start
- Starting value of the spanend
- Ending value of the spancolor
- Rule colorlegend
- Legend text. Use null to omit the text.public void vspan(long start, long end, Paint color)
start
- Start time for the span (seconds since epoch)end
- End time for the span (seconds since epoch)color
- Rule colorpublic void vspan(long start, long end, Paint color, String legend)
start
- Start time for the span (seconds since epoch)end
- End time for the span (seconds since epoch)color
- Rule colorlegend
- Legend text. Use null to omit the text.public void line(String srcName, Paint color)
srcName
- Virtual source namecolor
- Line colorpublic void line(String srcName, Paint color, String legend)
srcName
- Virtual source namecolor
- Line colorlegend
- Legend textpublic void line(String srcName, Paint color, float width)
srcName
- Virtual source namecolor
- Line colorwidth
- Line width (default: 1.0F)public void line(String srcName, Paint color, String legend, float width)
srcName
- Virtual source namecolor
- Line colorlegend
- Legend textwidth
- Line width (default: 1.0F)public void area(String srcName, Paint color)
srcName
- Virtual source name.color
- Color of the filled area.public void area(String srcName, Paint color, String legend)
srcName
- Virtual source name.color
- Color of the filled area.legend
- Legend text.public void stack(String srcName, Paint color)
line(String, java.awt.Paint)
,
but the graph gets stacked on top of the
previous LINE, AREA or STACK graph. Depending on the type of the
previous graph, the STACK will be either a LINE or an AREA. This
obviously implies that the first STACK must be preceded by an AREA
or LINE.
Note, that when you STACK onto *UNKNOWN* data, Rrd4j will not
draw any graphics ... *UNKNOWN* is not zero.srcName
- Virtual source namecolor
- Stacked graph colorIllegalArgumentException
- Thrown if this STACK has no previously defined AREA, STACK or LINE
graph bellow it.public void stack(String srcName, Paint color, String legend)
line(String, java.awt.Paint, String)
,
but the graph gets stacked on top of the
previous LINE, AREA or STACK graph. Depending on the type of the
previous graph, the STACK will be either a LINE or an AREA. This
obviously implies that the first STACK must be preceded by an AREA
or LINE.
Note, that when you STACK onto *UNKNOWN* data, Rrd4j will not
draw any graphics ... *UNKNOWN* is not zero.srcName
- Virtual source namecolor
- Stacked graph colorlegend
- Legend textIllegalArgumentException
- Thrown if this STACK has no previously defined AREA, STACK or LINE
graph bellow it.public void setDrawXGrid(boolean drawXGrid)
drawXGrid
- True if X-axis grid should be created (default), false otherwise.public void setDrawYGrid(boolean drawYGrid)
drawYGrid
- True if Y-axis grid should be created (default), false otherwise.public void setImageQuality(float imageQuality)
imageQuality
- (0F=worst, 1F=best).public void setAntiAliasing(boolean antiAliasing)
antiAliasing
- use true to turn antialiasing on, false to turn it off (default)public void setTextAntiAliasing(boolean textAntiAliasing)
textAntiAliasing
- use true to turn text-antialiasing on, false to turn it off (default)public void setShowSignature(boolean showSignature)
showSignature
- true, if signature should be seen (default), false otherwisepublic void setFirstDayOfWeek(int firstDayOfWeek)
public void setLocale(Locale locale)
locale
- the locale to setpublic void setTimeZone(TimeZone tz)
tz
- the time zone to setpublic void setGridStroke(Stroke gridStroke)
gridStroke
- a Stroke
object.Copyright © 2015. All rights reserved.