Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.image.chart
Class Chart

java.lang.Object
  extended by org.hyperic.image.WebImage
      extended by org.hyperic.image.chart.Chart
Direct Known Subclasses:
AvailabilityReportChart, HorizontalChart, VerticalChart

public abstract class Chart
extends WebImage

Chart is an abstract base class for the Covalent charting library. Chart uses Java AWT drawing to draw charts dynamically into a Java Image which can be then be used to display the chart in an application. The most common use of the charting library is to draw the chart image and then convert the image to a GIF to send to a Web Browser. Chart is responsible for all of the background drawing of the Chart the Chart frame, text labels, data point crossing lines, etc. Sublcasses of Chart draw on top of the image produce by the Chart class to draw the actual lines, columns, etc. that represent the data points of the chart. To create a chart you instantiate a subclass of Chart (e.g., LineChart, ColumnChart, etc.), call getData() to retrieve a collection, poplulate the collection and then call Chart.getImage() to get a java.awt.Image object that represents the drawn chart. The chart class is very configurable through get/set methods including configuring things like the text for labels, fonts, line colors, etc. After changing one or more options you call Chart.getImage() again to get a new image based on your options. The chart should have at least three datums in its Datum collection to display without errors.

See Also:
Image

Field Summary
protected static java.lang.String ARG_MUST_BE_ZERO_OR_GREATER
           
 java.awt.Color averageLineColor
          Color of the average data point horizontal line.
protected static java.lang.String AVG
           
 double baseline
          Baseline in the chart.
protected static java.lang.String BASELINE
           
 java.awt.Color baselineColor
          Color of the baseline horizontal line.
 double ceiling
          Top number for the left axis of the chart.
 java.awt.Color chartColor
          Retrieves the chart's interior background color.
protected static java.awt.Font DEFAULT_LABEL_FONT
           
protected static java.awt.Font DEFAULT_LEGEND_FONT
           
protected static java.awt.Font DEFAULT_LEGEND_PLAIN
           
protected static java.lang.String DEFAULT_UNIT_LEGEND
           
protected static java.lang.String DEFAULT_VALUE_LEGEND
           
static java.lang.String EMPTY_STRING
           
 double floor
          Bottom number for the left axis of the chart.
 double highRange
          High range in the chart.
 java.awt.Color highRangeColor
          High range color in the chart.
 java.awt.Font legendFont
          Font that is used to draw the legend for the chart's X and Y axis.
 java.awt.Color legendTextColor
          Color that is used to draw the legend text for the chart's X and Y axis.
 int lineWidth
          Width of lines in the chart.
protected static java.lang.String LOW
           
 java.awt.Color lowLineColor
          Retrieves the color of the low data point horizontal line.
 double lowRange
          Low range in the chart.
 java.awt.Color lowRangeColor
          High range color in the chart.
protected  double[] m_adRangeMarks
           
protected  boolean m_bNoData
           
protected  double m_dAvgValue
           
protected  double m_dLowValue
           
protected  double m_dPeakValue
           
protected  double m_floor
           
protected  int m_fmtScale
           
protected  int m_fmtType
           
protected  java.awt.FontMetrics m_metricsLabel
           
protected  java.awt.FontMetrics m_metricsLegend
           
protected static java.lang.String PEAK
           
 java.awt.Color peakLineColor
          Color of the peak data point horizontal line.
 int rightLabelWidth
          Sets a fixed size for the label width on the right vertical axis.
 boolean showAverage
          Calculates and shows an Average line in the chart.
 boolean showBaseline
          Shows a Baseline in the chart.
 boolean showBottomLabels
          Shows labels on the X axis bottom side.
 boolean showBottomLegend
          Shows a top legend.
 boolean showEvents
          Shows events plotted on a chart.
 boolean showFullLabels
          Show full labels on the bottom x axis.
 boolean showHighRange
          Shows a shaded high range in the chart.
 boolean showLeftLabels
          Shows labels on the Y axis left side.
 boolean showLeftLegend
          Shows a Left legend.
 boolean showLow
          Calculates and shows a Low line in the chart.
 boolean showLowRange
          Shows a shaded low range in the chart.
 boolean showPeak
          Calculates and shows a peak line in the chart.
 boolean showRightLabels
          Shows labels on the Y axis right side.
 boolean showRightLegend
          Shows a Right legend.
 boolean showTopLabels
          Shows labels on the X axis top side.
 boolean showTopLegend
          Shows a top legend.
 boolean showUnitLines
          Shows vertical crossing lines at each data point on the y axis.
 boolean showValueLines
          Shows horizontal crossing lines at each data point on the x axis.
 boolean showValues
          Shows values.
 int textWhitespace
          The width of the white space between tick marks and the label text.
 int tickMarkHeight
          The height, in pixels, of the tick mark lines that extend outside the chart's border.
 int valueIndent
          Number of pixels to indent the value axis.
 int valueLines
          Number of value lines that the chart draws at data points along the chart's value axis.
protected static int VARIABLE_HEIGHT
           
protected static int VARIABLE_WIDTH
           
 int x2VertLabels
           
 int x2VertMarks
           
 int xLabelsSkip
           
 java.awt.Color xLineColor
          Color of the border lines, horizontal lines and tick marks
 int xOffset
          Amount to offset the chart on the X axis in pixels.
 int xRLabel
           
 int xVertLegend
           
 int xVertMarks
           
 int yBottomLegend
           
 int yHorzLabels
           
 int yOffset
          Amount to offset the chart on the Y axis in pixels.
 int yTopLegend
           
 
Fields inherited from class org.hyperic.image.WebImage
antiAliased, ARG_CANNOT_BE_NULL, backgroundColor, bottomBorder, DEFAULT_BACKGROUND_COLOR, DEFAULT_BOLD_TYPEFACE, DEFAULT_BORDER_COLOR, DEFAULT_BORDER_SIZE, DEFAULT_FONT, DEFAULT_FONT_METRICS, DEFAULT_HEIGHT, DEFAULT_PLAIN_TYPEFACE, DEFAULT_SHADOW_WIDTH, DEFAULT_WIDTH, font, frameImage, height, indexColors, leftBorder, m_graphics, rightBorder, shadowWidth, SMALL_FONT, textColor, topBorder, width
 
Constructor Summary
protected Chart()
          Constructs a Chart class with a default width of 755 pixels and a default height of 300 pixels.
protected Chart(int charts)
          Constructs a Chart class with a default width of 755 pixels and a default height of 300 pixels.
protected Chart(int width, int height)
          Constructs a Chart class with a specified width and height.
protected Chart(int width, int height, int charts)
          Constructs a Chart class with a specified width and height.
 
Method Summary
protected  java.awt.Rectangle adjustRectangle(java.awt.Graphics2D g, java.awt.Rectangle rect)
          Give the child class an opportunity to change the size of the interior rectangle.
protected  void calc(java.awt.Graphics2D g)
           
protected  void calcRanges()
          Calculates the high, low and average values of the chart data set.
protected  int calcVariableHeight()
           
protected  int calcVariableWidth()
           
protected  boolean checkHighLow()
           
protected  java.awt.Rectangle draw(ChartGraphics g)
           
protected  void draw(java.awt.Graphics2D g)
           
 double getAverageValue()
          Retrieves the average value of the chart's data set.
protected  java.lang.Class getDataCollectionClass()
           
protected  java.awt.Point getDataPoint(int valuePixels, int unitPixels, int datapoint, DataPointCollection coll)
          Retrieves the value and unit coordinate for a data point in the chart.
 DataPointCollection getDataPoints()
          Retrieves the data set of the chart.
 DataPointCollection getDataPoints(int index)
           
 int getDataSetCount()
           
 java.util.Iterator getDataSetIterator()
           
protected  java.awt.Point getDisplayPoint(int valuePixels, int unitPixels, int unitPoints, double value, int unitIndex)
          Retrieves the value and unit coordinate for a value on the x and y axis in the chart.
 EventPointCollection getEventPoints()
           
 EventPointCollection getEventPoints(int index)
           
 java.util.Iterator getEventSetIterator()
           
protected  int getExteriorHeight()
           
 java.awt.Rectangle getExteriorRectangle()
           
protected abstract  java.awt.Rectangle getInteriorRectangle(ChartGraphics g)
           
 double getLowValue()
          Retrieves the low value of the chart's data set.
 java.lang.String getNoDataString()
           
 double getPeakValue()
          Retrieves the peak value of the chart's data set.
 java.lang.String getTitle()
          Get the chart's title.
protected  java.lang.String getUnitLabel(IDisplayDataPoint data)
           
 java.lang.String getUnitLegend()
          Retrieves the legend for the chart's Unit axis.
 java.lang.String getValueLegend()
          Retrieves the legend for the chart's Value axis.
protected  int getXLabelHeight()
           
protected abstract  java.lang.String[] getXLabels()
           
protected  int getXLabelWidth()
          Calculates the label width of the horizontal axis of the chart.
protected  int getXLegendHeight()
           
protected abstract  int getYLabelWidth(java.awt.Graphics2D g)
          Calculates the label width of the vertical axis of the chart.
protected  boolean hasData()
           
protected  java.util.Collection initData(java.util.Collection coll)
           
protected  void initFonts()
           
protected  void postInit(java.awt.Graphics2D g)
           
protected  void preInit()
           
protected  double scale(int height)
          Calculates the scale of the graph data points.
 void setAbsTimeLabels(boolean useAbsTimeLabels, long interval)
           
 void setFormat(int type, int scale)
           
 void setNoDataString(java.lang.String s)
           
 void setNumberDataSets(int number)
           
 void setTitle(java.lang.String title)
          Set the chart's title.
 void setUnitLegend(java.lang.String legend)
          Sets the legend for the chart's Unit axis.
 void setValueLegend(java.lang.String legend)
          Sets the legend for the chart's Value axis.
 
Methods inherited from class org.hyperic.image.WebImage
getFontMetrics, getImage, getTextCenter, getTextCenter, getTextCenter, isRunnable, setBorder, writeJpegImage, writeJpegImage, writePngImage, writePngImage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING

public static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

ARG_MUST_BE_ZERO_OR_GREATER

protected static final java.lang.String ARG_MUST_BE_ZERO_OR_GREATER
See Also:
Constant Field Values

AVG

protected static final java.lang.String AVG
See Also:
Constant Field Values

BASELINE

protected static final java.lang.String BASELINE
See Also:
Constant Field Values

LOW

protected static final java.lang.String LOW
See Also:
Constant Field Values

PEAK

protected static final java.lang.String PEAK
See Also:
Constant Field Values

DEFAULT_UNIT_LEGEND

protected static final java.lang.String DEFAULT_UNIT_LEGEND
See Also:
Constant Field Values

DEFAULT_VALUE_LEGEND

protected static final java.lang.String DEFAULT_VALUE_LEGEND
See Also:
Constant Field Values

VARIABLE_HEIGHT

protected static final int VARIABLE_HEIGHT
See Also:
Constant Field Values

VARIABLE_WIDTH

protected static final int VARIABLE_WIDTH
See Also:
Constant Field Values

DEFAULT_LABEL_FONT

protected static final java.awt.Font DEFAULT_LABEL_FONT

DEFAULT_LEGEND_PLAIN

protected static final java.awt.Font DEFAULT_LEGEND_PLAIN

DEFAULT_LEGEND_FONT

protected static final java.awt.Font DEFAULT_LEGEND_FONT

m_metricsLabel

protected java.awt.FontMetrics m_metricsLabel

m_metricsLegend

protected java.awt.FontMetrics m_metricsLegend

m_fmtType

protected int m_fmtType

m_fmtScale

protected int m_fmtScale

m_dAvgValue

protected double m_dAvgValue

m_dLowValue

protected double m_dLowValue

m_dPeakValue

protected double m_dPeakValue

m_adRangeMarks

protected double[] m_adRangeMarks

m_floor

protected double m_floor

m_bNoData

protected boolean m_bNoData

yTopLegend

public int yTopLegend

yBottomLegend

public int yBottomLegend

xVertLegend

public int xVertLegend

yHorzLabels

public int yHorzLabels

x2VertLabels

public int x2VertLabels

xRLabel

public int xRLabel

xVertMarks

public int xVertMarks

x2VertMarks

public int x2VertMarks

xLabelsSkip

public int xLabelsSkip

averageLineColor

public java.awt.Color averageLineColor
Color of the average data point horizontal line.


baselineColor

public java.awt.Color baselineColor
Color of the baseline horizontal line.


ceiling

public double ceiling
Top number for the left axis of the chart.


chartColor

public java.awt.Color chartColor
Retrieves the chart's interior background color.


floor

public double floor
Bottom number for the left axis of the chart.


baseline

public double baseline
Baseline in the chart.


highRange

public double highRange
High range in the chart.


highRangeColor

public java.awt.Color highRangeColor
High range color in the chart.


legendFont

public java.awt.Font legendFont
Font that is used to draw the legend for the chart's X and Y axis.


legendTextColor

public java.awt.Color legendTextColor
Color that is used to draw the legend text for the chart's X and Y axis.


lineWidth

public int lineWidth
Width of lines in the chart.


lowLineColor

public java.awt.Color lowLineColor
Retrieves the color of the low data point horizontal line.


lowRange

public double lowRange
Low range in the chart.


lowRangeColor

public java.awt.Color lowRangeColor
High range color in the chart.


peakLineColor

public java.awt.Color peakLineColor
Color of the peak data point horizontal line.


rightLabelWidth

public int rightLabelWidth
Sets a fixed size for the label width on the right vertical axis.


showAverage

public boolean showAverage
Calculates and shows an Average line in the chart.


showBaseline

public boolean showBaseline
Shows a Baseline in the chart.


showBottomLabels

public boolean showBottomLabels
Shows labels on the X axis bottom side.


showBottomLegend

public boolean showBottomLegend
Shows a top legend.


showEvents

public boolean showEvents
Shows events plotted on a chart.


showFullLabels

public boolean showFullLabels
Show full labels on the bottom x axis.


showHighRange

public boolean showHighRange
Shows a shaded high range in the chart.


showLeftLabels

public boolean showLeftLabels
Shows labels on the Y axis left side.


showLeftLegend

public boolean showLeftLegend
Shows a Left legend.


showLow

public boolean showLow
Calculates and shows a Low line in the chart.


showLowRange

public boolean showLowRange
Shows a shaded low range in the chart.


showPeak

public boolean showPeak
Calculates and shows a peak line in the chart.


showRightLabels

public boolean showRightLabels
Shows labels on the Y axis right side.


showRightLegend

public boolean showRightLegend
Shows a Right legend.


showTopLabels

public boolean showTopLabels
Shows labels on the X axis top side.


showTopLegend

public boolean showTopLegend
Shows a top legend.


showUnitLines

public boolean showUnitLines
Shows vertical crossing lines at each data point on the y axis.


showValueLines

public boolean showValueLines
Shows horizontal crossing lines at each data point on the x axis.


showValues

public boolean showValues
Shows values.


textWhitespace

public int textWhitespace
The width of the white space between tick marks and the label text.


tickMarkHeight

public int tickMarkHeight
The height, in pixels, of the tick mark lines that extend outside the chart's border. The tick marks for data points that don't have a label are drawn at half this height.


valueIndent

public int valueIndent
Number of pixels to indent the value axis.


valueLines

public int valueLines
Number of value lines that the chart draws at data points along the chart's value axis. For vertical chart's this is the Y axis. For horizontal charts this is the chart's X axis. This number includes the chart's top and bottom border.


xLineColor

public java.awt.Color xLineColor
Color of the border lines, horizontal lines and tick marks


xOffset

public int xOffset
Amount to offset the chart on the X axis in pixels.


yOffset

public int yOffset
Amount to offset the chart on the Y axis in pixels.

Constructor Detail

Chart

protected Chart()
Constructs a Chart class with a default width of 755 pixels and a default height of 300 pixels.


Chart

protected Chart(int charts)
Constructs a Chart class with a default width of 755 pixels and a default height of 300 pixels.

Parameters:
charts - The number of charts to display.

Chart

protected Chart(int width,
                int height)
Constructs a Chart class with a specified width and height.

Parameters:
width - The width of the chart in pixels.
height - The height of the chart in pixels.

Chart

protected Chart(int width,
                int height,
                int charts)
Constructs a Chart class with a specified width and height.

Parameters:
width - The width of the chart in pixels.
height - The height of the chart in pixels.
charts - The number of charts to display.
Method Detail

draw

protected void draw(java.awt.Graphics2D g)
Overrides:
draw in class WebImage

draw

protected java.awt.Rectangle draw(ChartGraphics g)

calc

protected void calc(java.awt.Graphics2D g)

adjustRectangle

protected java.awt.Rectangle adjustRectangle(java.awt.Graphics2D g,
                                             java.awt.Rectangle rect)
Give the child class an opportunity to change the size of the interior rectangle. This is done to make the tick marks fit symetrically in the chart rectangle.


calcRanges

protected void calcRanges()
Calculates the high, low and average values of the chart data set.


calcVariableHeight

protected int calcVariableHeight()

calcVariableWidth

protected int calcVariableWidth()

getXLabelWidth

protected int getXLabelWidth()
Calculates the label width of the horizontal axis of the chart.

Parameters:
graph - The java.awt.Graphics context to draw into.
Returns:
The width of the widest label on the X (horizontal) axis.

getXLegendHeight

protected int getXLegendHeight()

getYLabelWidth

protected abstract int getYLabelWidth(java.awt.Graphics2D g)
Calculates the label width of the vertical axis of the chart.

Parameters:
graph - The ChartGraphics context to draw into.
Returns:
The width of the widest label on the Y (vertical) axis.

getXLabels

protected abstract java.lang.String[] getXLabels()

getXLabelHeight

protected int getXLabelHeight()

getInteriorRectangle

protected abstract java.awt.Rectangle getInteriorRectangle(ChartGraphics g)

getExteriorHeight

protected int getExteriorHeight()

initData

protected java.util.Collection initData(java.util.Collection coll)

initFonts

protected void initFonts()

preInit

protected void preInit()
Overrides:
preInit in class WebImage

postInit

protected void postInit(java.awt.Graphics2D g)
Overrides:
postInit in class WebImage

getDataPoint

protected java.awt.Point getDataPoint(int valuePixels,
                                      int unitPixels,
                                      int datapoint,
                                      DataPointCollection coll)
Retrieves the value and unit coordinate for a data point in the chart.

Parameters:
valuePixels - An int that specifies the size of the value axis in pixels.
unitPixels - An int that specifies the size of the unit axis in pixels.
datapoint - An int that specifies the zero-based index of the datum to calculate coordinates for.
collection - The DataPointCollection the datapoint is located in.
Returns:
A java.awt.Point object that contains the X and Y coordinate.
See Also:
Rectangle

getDisplayPoint

protected java.awt.Point getDisplayPoint(int valuePixels,
                                         int unitPixels,
                                         int unitPoints,
                                         double value,
                                         int unitIndex)
Retrieves the value and unit coordinate for a value on the x and y axis in the chart.

Parameters:
valuePixels - An int that specifies the size of the value axis in pixels.
unitPixels - An int that specifies the size of the unit axis in pixels.
unitPoints - Number of ticks on the unit axis.
value - A double that specifies the value to get coordinates for.
unitIndex - Ticks on the unit axis to get coordinates for.
Returns:
A java.awt.Point object that contains the X and Y coordinate.

getUnitLabel

protected java.lang.String getUnitLabel(IDisplayDataPoint data)

hasData

protected boolean hasData()

scale

protected double scale(int height)
Calculates the scale of the graph data points. This is the number of pixels per data point.

Parameters:
height - The height of the rectangle to calculate the vertical scale for.
Returns:
A floating point value that specifies the scale multiplier of the vertical axis.

getDataCollectionClass

protected java.lang.Class getDataCollectionClass()

checkHighLow

protected boolean checkHighLow()

getAverageValue

public double getAverageValue()
Retrieves the average value of the chart's data set.

Returns:
A floating point value that is the average value of the chart's data set.

getNoDataString

public java.lang.String getNoDataString()

setNoDataString

public void setNoDataString(java.lang.String s)

getDataPoints

public DataPointCollection getDataPoints()
Retrieves the data set of the chart.

Returns:
A net.hyperic.chart.DataPointCollection object that contains the current data set points.
See Also:
net.hyperic.chart.DataPointCollection

getEventPoints

public EventPointCollection getEventPoints()

getDataPoints

public DataPointCollection getDataPoints(int index)

getEventPoints

public EventPointCollection getEventPoints(int index)

getDataSetCount

public int getDataSetCount()

getDataSetIterator

public java.util.Iterator getDataSetIterator()

getEventSetIterator

public java.util.Iterator getEventSetIterator()

setNumberDataSets

public void setNumberDataSets(int number)

setFormat

public void setFormat(int type,
                      int scale)

getExteriorRectangle

public java.awt.Rectangle getExteriorRectangle()

getLowValue

public double getLowValue()
Retrieves the low value of the chart's data set.

Returns:
A floating point value that is the low value of the chart's data set.

getPeakValue

public double getPeakValue()
Retrieves the peak value of the chart's data set.

Returns:
A floating point value that is the peak value of the chart's data set.

getTitle

public java.lang.String getTitle()
Get the chart's title.

Returns:
A string containing the chart's title.

setTitle

public void setTitle(java.lang.String title)
Set the chart's title.

Parameters:
title - A string containing the chart's title.

getUnitLegend

public java.lang.String getUnitLegend()
Retrieves the legend for the chart's Unit axis. The default legend is "TIME".

Returns:
A java.lang.String object that contains the chart's Unit axis lagend.

setUnitLegend

public void setUnitLegend(java.lang.String legend)
Sets the legend for the chart's Unit axis.

Parameters:
label - A java.lang.String object that contains the chart's Unit axis legend.
Throws:
java.lang.IllegalArgumentException - If the legend parameter is null.

getValueLegend

public java.lang.String getValueLegend()
Retrieves the legend for the chart's Value axis. The default legend is "VALUE".

Returns:
A java.lang.String object that contains the chart's Value axis legend.

setValueLegend

public void setValueLegend(java.lang.String legend)
Sets the legend for the chart's Value axis.

Parameters:
label - A java.lang.String object that contains the chart's Value axis legend.
Throws:
java.lang.IllegalArgumentException - If the legend parameter is null.

setAbsTimeLabels

public void setAbsTimeLabels(boolean useAbsTimeLabels,
                             long interval)

Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.