com.fusioncharts
Class Graph

java.lang.Object
  extended by com.fusioncharts.Graph
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Graph>
Direct Known Subclasses:
FusionGraph

public class Graph
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable<Graph>

The Graph class provides a graph that the ChartFactory can work with in order to output the appropriate string data value for the type of chart to display on the page. Originally this was a subclass of WePopChart.java but we decided that it was a better solution to separate it from the class. This will be the parent Graph class for all graphing type packages in the future. A set of methods that all graphs can use is included. 20090323 - First created by David Lai

Author:
David Lai

Constructor Summary
Graph(java.lang.String graphId, ChartType graphType, int length, javax.servlet.http.HttpServletRequest request)
          Constructor for a Graph object.
 
Method Summary
 double calculateMax()
          Calculates the maximum value of all the series in the graph.
 double calculateMin()
          Calculates the minimum value of all the series in the graph.
 void clear()
          Clears the Series objects from this Graph.
 java.lang.Object clone()
          Creates and returns a copy of the graph object.
 int compareTo(Graph graph)
          Compares the graphType enum with the specified object for order.
 Series createSeries(int index, java.lang.String label)
          Creates a Series for this graph.
 Series createSeries(java.lang.String label)
          Creates a Series for this graph.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 java.lang.String getCategory(int index)
          Accessor method to get a graph category.
 java.lang.String getGraphId()
          Accessor method to return the object identifier.
 ChartType getGraphType()
          Accessor method to return the graph type
 int getHeight()
          Accessor method to get height of graph
static java.lang.String getMaxScale(double minValue, double maxValue)
           
static java.lang.String getMinScale(double minValue, double maxValue)
           
 java.util.LinkedList<Series> getNonTrendLineSeries()
          Retreives a linked list of series that are either bar, line or area type
 int getNumberOfCategories()
          Returns the number of categories for this graph.
 int getNumberOfSeries()
          Returns the current number of series.
 Series getSeries(int index)
          Returns the Series at a specified index.
 java.util.LinkedList<Series> getTrendLineSeries()
          Retreives a linked list of trendline series
 int getWidth()
          Accessor method to get width of graph
 int hashCode()
          Returns a hash code value for the object.
 void setCategory(int index, java.lang.String category)
          Manipulator method to set a graph category.
 void setCategory(java.lang.String... category)
          Manipulator method to set the graph categories.
 void setHeight(int height)
          Manipulator method to set the height of the graph.
 void setWidth(int width)
          Manipulator method to set the width.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph

public Graph(java.lang.String graphId,
             ChartType graphType,
             int length,
             javax.servlet.http.HttpServletRequest request)
      throws java.lang.IllegalArgumentException
Constructor for a Graph object. The default height is 300 pixels and the default width is 600 pixels

Parameters:
graphId - The graph name.
graphType - The graph type ie:(pie graph, column chart). From the chart type enum
length - The length of the categories.
request - The user request. HTTP request header fields allow the client to pass additional information about the request, and about the client itself, to the server. These fields also act as request modifiers by the responding script. For additional information on HTTP Headers, consult the W3C RFC2616.
Throws:
java.lang.IllegalArgumentException - If the graph object name is blank or length is less than or equal to zero.
Method Detail

getGraphType

public ChartType getGraphType()
Accessor method to return the graph type

Returns:
graphType The graph type.

getGraphId

public java.lang.String getGraphId()
Accessor method to return the object identifier.

Returns:
graphId The object identifier.

setCategory

public void setCategory(java.lang.String... category)
Manipulator method to set the graph categories. The categories will be set starting at index 0 until the min between the number of categories specified and the number of categories passed as arguments.

Parameters:
categories - The list of category labels.

setCategory

public void setCategory(int index,
                        java.lang.String category)
Manipulator method to set a graph category.

Parameters:
index - The index.
category - The category label.

getCategory

public java.lang.String getCategory(int index)
Accessor method to get a graph category.

Parameters:
index - The index.
Returns:
categories The category.

getNumberOfCategories

public int getNumberOfCategories()
Returns the number of categories for this graph.

Returns:
length The number of categories.

getSeries

public Series getSeries(int index)
                 throws java.lang.IndexOutOfBoundsException
Returns the Series at a specified index.

Returns:
series The series.
Throws:
java.lang.IndexOutOfBoundsException - If the indice specified is less than 0 or greater than or equal to the number of series.

getNumberOfSeries

public int getNumberOfSeries()
Returns the current number of series.

Returns:
size The number of series.

createSeries

public Series createSeries(int index,
                           java.lang.String label)
                    throws java.lang.IndexOutOfBoundsException,
                           java.lang.IllegalArgumentException
Creates a Series for this graph. The series will be inserted at the index specified. The length of the series will equal the length of the categories

Parameters:
index - The index to insert the series at (first index is 0).
label - The series label.
Returns:
Series The series that was created.
Throws:
java.lang.IndexOutOfBoundsException - If the index specified is out of range.
java.lang.IllegalArgumentException - If an invalid argument was passed.
See Also:
com.pointclickcare.charts.Series#Series(String, int)} The Series constructor definition.

createSeries

public Series createSeries(java.lang.String label)
                    throws java.lang.IllegalArgumentException
Creates a Series for this graph. The series will be appended to the existing list of series.

Parameters:
label - The series label.
Returns:
Series The series that was created.
Throws:
java.lang.IllegalArgumentException - If an invalid argument was passed.
See Also:
com.pointclickcare.charts.Series#Series(String, int)} The Series constructor definition.

getHeight

public int getHeight()
Accessor method to get height of graph

Returns:
height Height of the graph

setHeight

public void setHeight(int height)
Manipulator method to set the height of the graph.

Parameters:
height - The height of the graph

getWidth

public int getWidth()
Accessor method to get width of graph

Returns:
width Width of the graph

setWidth

public void setWidth(int width)
Manipulator method to set the width.

Parameters:
width - the width to set it to

calculateMin

public double calculateMin()
Calculates the minimum value of all the series in the graph.

Returns:
double The minimum of the series.

calculateMax

public double calculateMax()
Calculates the maximum value of all the series in the graph.

Returns:
double The maximum of the series.

clear

public void clear()
Clears the Series objects from this Graph. Graph properties such as category names, number of lines and auto-scale are maintained.


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates and returns a copy of the graph object.

Overrides:
clone in class java.lang.Object
Returns:
Object A clone of this instance.
Throws:
java.lang.CloneNotSupportedException - If the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
See Also:
java.lang.Cloneable}

compareTo

public int compareTo(Graph graph)
Compares the graphType enum with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. Enum constants are only comparable to other enum constants of the same enum type. The natural order implemented by this method is the order in which the constants are declared.

Specified by:
compareTo in interface java.lang.Comparable<Graph>
Parameters:
o - The Object to be compared.
Returns:
int A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - If the specified object's type prevents it from being compared to this Object.

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. A graph object is equal to the other if the object identifiers are the same.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The reference object with which to compare.
Returns:
true If this object is the same as the obj argument.

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashMaps such as those provided by java.util.HashMap.

Overrides:
hashCode in class java.lang.Object
Returns:
int A hash code value for this object.
See Also:
java.util.HashMap}

getTrendLineSeries

public java.util.LinkedList<Series> getTrendLineSeries()
Retreives a linked list of trendline series

Returns:
trendSeries Linked list of trend series for the particular chart

getNonTrendLineSeries

public java.util.LinkedList<Series> getNonTrendLineSeries()
Retreives a linked list of series that are either bar, line or area type

Returns:
series Linked list of series for the particular chart that are either bar, line or area type

getMinScale

public static java.lang.String getMinScale(double minValue,
                                           double maxValue)

getMaxScale

public static java.lang.String getMaxScale(double minValue,
                                           double maxValue)