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 Name | Property Type | Description |
X | Vector |
X axis labels. |
YAxisMinimum | double |
Y axis label minimum (starting) value. |
YAxisIncrement | double |
Y axis label increment value. |
YCount | int |
Number of datasets in this graph. |
Style | int |
Graph styles. |
Colors | Color (Indexed) |
Graph drawing colors. |
SelectedObjects | Object (Indexed, Readonly) |
Index of the clicked data element. |
Graph generates the following events:
Event Type | Event ID | Generated |
Description |
ActionEvent | ActionEvent.ACTION_PERFORMED |
Mouse click in a data point area |
ActionEvent.getActionCommand() contains the x label of the
data area. |
ItemEvent | ItemEvent.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
-
BAR
- Bar chart style.
-
BAR3D
- 3D bar chart style.
-
BAR3D3D
- 3D bar chart in 3D coordinate space.
-
eventMgr
- EventMgr object handles added event processing and dispatching.
-
LINE
- Line graph style.
-
PIE
- Pie chart style.
-
PIE3D
- 3D pie chart style.
-
POINT
- Point graph style.
-
STACKBAR
- Stacked bar chart style.
-
STACKBAR3D
- Stacked 3D bar chart style.
-
Graph()
- Construct an empty graph.
-
Graph(Vector, Vector)
- Construct a Graph with x as the x axis values, and y as y axis
values.
-
Graph(Vector, Vector, int)
- Construct a Graph with x as the x axis values, and y as y axis
values.
-
addActionListener(ActionListener)
- Add an action listener.
-
addItemListener(ItemListener)
- Add an item listener.
-
addObject(int, Number, Object)
- Add a label to the specified location.
-
addY(Vector)
- Add a data set to be displayed.
-
clearY()
- Clear all data sets.
-
clearYAxis()
- Clear the y axis label parameters.
-
getColor(int)
- Return the color for the n'th data set.
-
getColors()
- Get the colors used by Graph for display each data sets.
-
getContrast()
- Return the current constrast value.
-
getMinimumSize()
- Return the minimum size of Graph.
-
getPreferredSize()
- Return the preferred size of Graph.
-
getSelectedObjects()
- Return the index of the clicked data element.
-
getStyle()
- Get the graph style.
-
getX()
- Get the x axis labels vector.
-
getY(int)
- Get the n'th dataset as a vector.
-
getYCount()
- Return the number of datasets.
-
paint(Graphics)
- Paint the graph.
-
processActionEvent(ActionEvent)
- Process and dispatch action event.
-
processEvent(AWTEvent)
- Process and dispatch event.
-
processItemEvent(ItemEvent)
- Process and dispatch item event.
-
processMouseEvent(MouseEvent)
- Process mouse click in data area.
-
removeActionListener(ActionListener)
- Remove an action listener.
-
removeItemListener(ItemListener)
- Remove an item listener.
-
removeObject(Object)
- Remove the object added using Graph.addObject().
-
setColors(Color[])
- Set the colors to use for each data sets.
-
setContrast(double)
- Set the constrast value.
-
setStyle(ActionEvent)
- Action handler for Graph style changes.
-
setStyle(int)
- Set the graph style to the specified type.
-
setStyle(ItemEvent)
- Action handler for Graph style changes.
-
setValues(Vector, Vector)
- Set the data sets value.
-
setX(Vector)
- Set the x axis labels.
-
setYAxisIncrement(double)
- Set the y axis label increment value.
-
setYAxisMinimum(double)
- Set the y axis label starting value.
-
update(Graphics)
- Overriden for double buffering.
-
update(Observable, Object)
- Called when observers in the observable list need to be
updated.
LINE
public static final int LINE
- Line graph style.
POINT
public static final int POINT
- Point graph style.
BAR
public static final int BAR
- Bar chart style.
STACKBAR
public static final int STACKBAR
- Stacked bar chart style.
PIE
public static final int PIE
- Pie chart style.
BAR3D
public static final int BAR3D
- 3D bar chart style.
STACKBAR3D
public static final int STACKBAR3D
- Stacked 3D bar chart style.
PIE3D
public static final int PIE3D
- 3D pie chart style.
BAR3D3D
public static final int BAR3D3D
- 3D bar chart in 3D coordinate space.
eventMgr
protected EventMgr eventMgr
- EventMgr object handles added event processing and dispatching.
Graph
public Graph()
- Construct an empty graph. Caller must call setValues to pass in
the data sets for displaying.
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.
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.
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
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.
getX
public Vector getX()
- Get the x axis labels vector.
- Returns:
- x axis labels.
setX
public synchronized void setX(Vector x)
- Set the x axis labels.
- Parameters:
- x - x axis labels.
setYAxisMinimum
public synchronized void setYAxisMinimum(double min)
- Set the y axis label starting value.
- Parameters:
- min - y axis label starting value.
setYAxisIncrement
public synchronized void setYAxisIncrement(double inc)
- Set the y axis label increment value.
- Parameters:
- inc - y axis label increment value.
clearYAxis
public synchronized void clearYAxis()
- Clear the y axis label parameters. Use automatically generated
y axis labels.
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.
getYCount
public int getYCount()
- Return the number of datasets.
- Returns:
- number of datasets.
clearY
public synchronized void clearY()
- Clear all data sets.
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.
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.
getStyle
public int getStyle()
- Get the graph style.
- Returns:
- graph style.
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.
getColor
public Color getColor(int n)
- Return the color for the n'th data set.
- Returns:
- dataset color.
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.
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.
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.
getSelectedObjects
public Object[] getSelectedObjects()
- Return the index of the clicked data element.
- Returns:
- index of clicked data element.
getMinimumSize
public Dimension getMinimumSize()
- Return the minimum size of Graph.
- Returns:
- minimum size of graph.
- Overrides:
- getMinimumSize in class Component
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.
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.
getPreferredSize
public Dimension getPreferredSize()
- Return the preferred size of Graph. It's fixed at (200, 100).
- Overrides:
- getPreferredSize in class Component
paint
public void paint(Graphics g)
- Paint the graph.
- Parameters:
- g - Graphics context for this component.
- Overrides:
- paint in class Canvas
addActionListener
public void addActionListener(ActionListener listener)
- Add an action listener.
- Parameters:
- listener - action listener.
removeActionListener
public void removeActionListener(ActionListener listener)
- Remove an action listener.
- Parameters:
- listener - action listener.
addItemListener
public void addItemListener(ItemListener listener)
- Add an item listener.
- Parameters:
- listener - item listener.
removeItemListener
public void removeItemListener(ItemListener listener)
- Remove an item listener.
- Parameters:
- listener - item listener.
processEvent
public void processEvent(AWTEvent e)
- Process and dispatch event.
- Parameters:
- e - event object.
- Overrides:
- processEvent in class Component
processActionEvent
public void processActionEvent(ActionEvent e)
- Process and dispatch action event.
- Parameters:
- e - action event.
processItemEvent
public void processItemEvent(ItemEvent e)
- Process and dispatch item event.
- Parameters:
- e - item event.
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
update
public void update(Graphics g)
- Overriden for double buffering.
- Parameters:
- g - Graphics context for this component.
- Overrides:
- update in class Component
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.
getContrast
public double getContrast()
- Return the current constrast value.
- Returns:
- contrast value.
All Packages Class Hierarchy This Package Previous Next Index