All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.Graph

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----tea.set.Graph

public class Graph
extends Canvas
implements Observer, ItemSelectable
Graph widget supports the drawing of different types of graphs for multiple data sets. The labels for X axis must be supplied by the caller. If the Y axis parameters, YAxisMinimum and YAxisIncrement, are not set, the labels for Y axis will be generated automatically using the values supplied for drawing. The type of the graph can be changed dynamically after the graph is created.

There are nine styles of charts supported by this Graph widget:

Graph.LINE
line chart.
Graph.POINT
point chart.
Graph.BAR
plain bar chart.
Graph.STACKBAR
plain stacked bar chart.
Graph.BAR3D
3D bar chart in 2D coordinate.
Graph.STACKBAR3D
3D stacked bar chart in 2D coordinate.
Graph.BAR3D3D
3D bar chart in 3D coordinate.
Graph.PIE
plain pie chart.
Graph.PIE3D
3D pie chart.

For PIE and PIE3D types, only one dataset is displayed. If more than one dataset is added to the graph, only the first dataset is shown. To display multiple datasets using Pie charts, simply create a Panel or tea.set.Grid and create one Graph instance for each dataset.

If an user clicks inside a chart, ActionEvent.ACTION_PERFORMED and an ItemEvent.SELECTED events are generated. The ItemEvent.getItem() is a Point object. The Point.x is the x coordinate number, and Point.y is the dataset number. For example, if the mouse click is inside the third bar in a one dataset bar chart, the Event.arg would be set to Point(2, 0). If a mouse click is inside the third bar of the second dataset in a two datasets bar chart, the Event.arg would be set to Point(2, 1). An action event is also generated with the same Event.arg value.

The Y datasets can be constructed using tea.set.DataSet class. It takes a vector, array, or delimited string, and creates a one or two dimensional Vector that can be used by Graph. For more detail, refer to the document on DataSet class.

Graph supports the following properties:
Property NameProperty TypeDescription
XVector X axis labels.
YAxisMinimumdouble Y axis label minimum (starting) value.
YAxisIncrementdouble Y axis label increment value.
YCountint Number of datasets in this graph.
Styleint Graph styles.
ColorsColor (Indexed) Graph drawing colors.
SelectedObjectsObject (Indexed, Readonly) Index of the clicked data element.

Graph generates the following events:
Event TypeEvent IDGenerated Description
ActionEventActionEvent.ACTION_PERFORMED Mouse click in a data point area ActionEvent.getActionCommand() contains the x label of the data area.
ItemEventItemEvent.SELECTED Mouse click in a data point area. ItemEvent.getItem() contains a Point object, where Point.x is the x index of the data point, and Point.y is the index of the dataset where this data point belongs to. ItemEvent.getStateChange() is 1.

See Also:
Grid, DataSet, Observable, Observer

Variable Index

 o BAR
Bar chart style.
 o BAR3D
3D bar chart style.
 o BAR3D3D
3D bar chart in 3D coordinate space.
 o eventMgr
EventMgr object handles added event processing and dispatching.
 o LINE
Line graph style.
 o PIE
Pie chart style.
 o PIE3D
3D pie chart style.
 o POINT
Point graph style.
 o STACKBAR
Stacked bar chart style.
 o STACKBAR3D
Stacked 3D bar chart style.

Constructor Index

 o Graph()
Construct an empty graph.
 o Graph(Vector, Vector)
Construct a Graph with x as the x axis values, and y as y axis values.
 o Graph(Vector, Vector, int)
Construct a Graph with x as the x axis values, and y as y axis values.

Method Index

 o addActionListener(ActionListener)
Add an action listener.
 o addItemListener(ItemListener)
Add an item listener.
 o addObject(int, Number, Object)
Add a label to the specified location.
 o addY(Vector)
Add a data set to be displayed.
 o clearY()
Clear all data sets.
 o clearYAxis()
Clear the y axis label parameters.
 o getColor(int)
Return the color for the n'th data set.
 o getColors()
Get the colors used by Graph for display each data sets.
 o getContrast()
Return the current constrast value.
 o getMinimumSize()
Return the minimum size of Graph.
 o getPreferredSize()
Return the preferred size of Graph.
 o getSelectedObjects()
Return the index of the clicked data element.
 o getStyle()
Get the graph style.
 o getX()
Get the x axis labels vector.
 o getY(int)
Get the n'th dataset as a vector.
 o getYCount()
Return the number of datasets.
 o paint(Graphics)
Paint the graph.
 o processActionEvent(ActionEvent)
Process and dispatch action event.
 o processEvent(AWTEvent)
Process and dispatch event.
 o processItemEvent(ItemEvent)
Process and dispatch item event.
 o processMouseEvent(MouseEvent)
Process mouse click in data area.
 o removeActionListener(ActionListener)
Remove an action listener.
 o removeItemListener(ItemListener)
Remove an item listener.
 o removeObject(Object)
Remove the object added using Graph.addObject().
 o setColors(Color[])
Set the colors to use for each data sets.
 o setContrast(double)
Set the constrast value.
 o setStyle(ActionEvent)
Action handler for Graph style changes.
 o setStyle(int)
Set the graph style to the specified type.
 o setStyle(ItemEvent)
Action handler for Graph style changes.
 o setValues(Vector, Vector)
Set the data sets value.
 o setX(Vector)
Set the x axis labels.
 o setYAxisIncrement(double)
Set the y axis label increment value.
 o setYAxisMinimum(double)
Set the y axis label starting value.
 o update(Graphics)
Overriden for double buffering.
 o update(Observable, Object)
Called when observers in the observable list need to be updated.

Variables

 o LINE
 public static final int LINE
Line graph style.

 o POINT
 public static final int POINT
Point graph style.

 o BAR
 public static final int BAR
Bar chart style.

 o STACKBAR
 public static final int STACKBAR
Stacked bar chart style.

 o PIE
 public static final int PIE
Pie chart style.

 o BAR3D
 public static final int BAR3D
3D bar chart style.

 o STACKBAR3D
 public static final int STACKBAR3D
Stacked 3D bar chart style.

 o PIE3D
 public static final int PIE3D
3D pie chart style.

 o BAR3D3D
 public static final int BAR3D3D
3D bar chart in 3D coordinate space.

 o eventMgr
 protected EventMgr eventMgr
EventMgr object handles added event processing and dispatching.

Constructors

 o Graph
 public Graph()
Construct an empty graph. Caller must call setValues to pass in the data sets for displaying.

 o Graph
 public Graph(Vector x,
              Vector y)
Construct a Graph with x as the x axis values, and y as y axis values. The x Vector can be a vector of any object. The string representation of the x objects are printed as x labels. The y vector must be a vector of Number. If multiple data sets need to be displayed, y can be a vector of vectors of Number. The same effect can be achieved by repeatitively calling addY() method. @see java.lang.Number

Parameters:
x - a vector of x axis labels.
y - a vector of java.lang.Number for y axis values.
 o Graph
 public Graph(Vector x,
              Vector y,
              int style)
Construct a Graph with x as the x axis values, and y as y axis values. The x Vector can be a vector of any object. The string representation of the x objects are printed as x labels. The y vector must be a vector of Number. If multiple data sets need to be displayed, y can be a vector of vectors of Number. The same effect can be achieved by repeatitively calling addY() method. The style parameter specifies the style of the Graph. It must be one of the style values defined in Graph.

Parameters:
x - a vector of x axis labels.
y - a vector of java.lang.Number for y axis values.
style - graph style.

Methods

 o update
 public void update(Observable o,
                    Object arg)
Called when observers in the observable list need to be updated.

Parameters:
o - the list of observers
arg - the argument being notified
 o setValues
 public synchronized void setValues(Vector x,
                                    Vector y)
Set the data sets value. The parameters are the same as the constructor.

Parameters:
x - a vector of x axis labels.
y - a vector of java.lang.Number for y axis values.
 o getX
 public Vector getX()
Get the x axis labels vector.

Returns:
x axis labels.
 o setX
 public synchronized void setX(Vector x)
Set the x axis labels.

Parameters:
x - x axis labels.
 o setYAxisMinimum
 public synchronized void setYAxisMinimum(double min)
Set the y axis label starting value.

Parameters:
min - y axis label starting value.
 o setYAxisIncrement
 public synchronized void setYAxisIncrement(double inc)
Set the y axis label increment value.

Parameters:
inc - y axis label increment value.
 o clearYAxis
 public synchronized void clearYAxis()
Clear the y axis label parameters. Use automatically generated y axis labels.

 o getY
 public Vector getY(int n)
Get the n'th dataset as a vector. Each element in the vector should be a Number object.

Returns:
n'th dataset.
 o getYCount
 public int getYCount()
Return the number of datasets.

Returns:
number of datasets.
 o clearY
 public synchronized void clearY()
Clear all data sets.

 o addY
 public synchronized void addY(Vector y)
Add a data set to be displayed. This method can be used to display multiple data sets in one graph. The parameter can either be a Vector of Numbers, or a Vector of Vector of Numbers. In the later case each vector is a dataset.

Parameters:
y - a vector of java.lang.Number for y axis values.
 o setStyle
 public synchronized void setStyle(int style)
Set the graph style to the specified type. The default style is LINE. This causes a repaint of the graph if style is different from the current one.

Parameters:
style - graph style.
 o getStyle
 public int getStyle()
Get the graph style.

Returns:
graph style.
 o getColors
 public Color[] getColors()
Get the colors used by Graph for display each data sets. The colors are chosen in the insertion order of data sets.

Returns:
an array of colors used by graph to display data sets.
 o getColor
 public Color getColor(int n)
Return the color for the n'th data set.

Returns:
dataset color.
 o setColors
 public synchronized void setColors(Color colors[])
Set the colors to use for each data sets.

Parameters:
colors - an arrow of colors used by graph to display data sets.
 o addObject
 public void addObject(int x,
                       Number y,
                       Object comp)
Add a label to the specified location. The x value should be 0, 1, 2, and so on. Position 0 on x coordinate is the position of the first data point. The y value should be between the range of minimum and maximum of all datasets values. Currently two types of objects are supported: String and Image. The object will be displayed at the specified location along with the graph.

Parameters:
x - x coordinate, 0, 1, 2...
y - y coordinate value, will be translated to screen location.
comp - object, String or Image to be displayed at the specified location.
 o removeObject
 public void removeObject(Object comp)
Remove the object added using Graph.addObject(). The parameter must be same as the one passed into Graph.addObject().

Parameters:
comp - object, String or Image to be displayed at the specified location.
 o getSelectedObjects
 public Object[] getSelectedObjects()
Return the index of the clicked data element.

Returns:
index of clicked data element.
 o getMinimumSize
 public Dimension getMinimumSize()
Return the minimum size of Graph.

Returns:
minimum size of graph.
Overrides:
getMinimumSize in class Component
 o setStyle
 public void setStyle(ItemEvent e)
Action handler for Graph style changes. ItemEvent.getItem() should return the name of the graph style.

Parameters:
e - event object.
 o setStyle
 public void setStyle(ActionEvent e)
Action handler for Graph style changes. ItemEvent.getItem() should return the name of the graph style.

Parameters:
e - event object.
 o getPreferredSize
 public Dimension getPreferredSize()
Return the preferred size of Graph. It's fixed at (200, 100).

Overrides:
getPreferredSize in class Component
 o paint
 public void paint(Graphics g)
Paint the graph.

Parameters:
g - Graphics context for this component.
Overrides:
paint in class Canvas
 o addActionListener
 public void addActionListener(ActionListener listener)
Add an action listener.

Parameters:
listener - action listener.
 o removeActionListener
 public void removeActionListener(ActionListener listener)
Remove an action listener.

Parameters:
listener - action listener.
 o addItemListener
 public void addItemListener(ItemListener listener)
Add an item listener.

Parameters:
listener - item listener.
 o removeItemListener
 public void removeItemListener(ItemListener listener)
Remove an item listener.

Parameters:
listener - item listener.
 o processEvent
 public void processEvent(AWTEvent e)
Process and dispatch event.

Parameters:
e - event object.
Overrides:
processEvent in class Component
 o processActionEvent
 public void processActionEvent(ActionEvent e)
Process and dispatch action event.

Parameters:
e - action event.
 o processItemEvent
 public void processItemEvent(ItemEvent e)
Process and dispatch item event.

Parameters:
e - item event.
 o processMouseEvent
 public void processMouseEvent(MouseEvent e)
Process mouse click in data area. If a mouse click happens in a data area, an ItemEvent.SELECTED and ActionEvent.ACTION_PERFORMED events are generated.

Overrides:
processMouseEvent in class Component
 o update
 public void update(Graphics g)
Overriden for double buffering.

Parameters:
g - Graphics context for this component.
Overrides:
update in class Component
 o setContrast
 public void setContrast(double contrast)
Set the constrast value. The constrast affects the brightness of 3D surfaces. The larger the value, the smaller difference will be. Depending on the color display type, some color may not be available, so experiment before changing the contrast value to something else. The default contrast is 0.8.

Parameters:
contrast - color contrast value.
 o getContrast
 public double getContrast()
Return the current constrast value.

Returns:
contrast value.

All Packages  Class Hierarchy  This Package  Previous  Next  Index