com.jinsight.jetchart
Class GenericGraph

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--com.jinsight.jetchart.GradientPanel
                          |
                          +--com.jinsight.jetchart.GenericGraph
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
Graph, PieGraph, ScatterGraph

public class GenericGraph
extends GradientPanel

The chart context is a subclass of java.awt.Panel or javax.swing.JPanel, depending on whether AWT or Swing applications are developed with JetChart.
The GenericGraph class is the super class of all different chart contexts available in the JetChart package. Currently there are three types of chart contexts, as below:

See Also:
Graph, ScatterGraph, PieGraph, Serialized Form

Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static int CENTER
          Constant used to place the background image at the center of the chart.
static int TILE
          Constant used to arrange the background image side by side.
static int TOP_LEFT
          Constant used to place the background image at the top left corner of the chart area.
 
Fields inherited from class com.jinsight.jetchart.GradientPanel
BOTTOM_TO_TOP, LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Method Summary
 void addLegend(Legend l)
          Adds a new Legend box to the chart context.
 void addNote(Note note)
          Adds a Note object to the chart context.
 void addSerie(AbstractSerie serie)
          Adds series objects to the chart context.
 void addSerieListener(SerieListener serieListener)
          Adds a series event listener to handle series events.
protected  void finalize()
           
 BottomTitle getBottomTitle()
          Returns a reference to the BottomTitle object.
 LeftTitle getLeftTitle()
          Returns a reference to the LeftTitle object.
 Legend getLegend()
          Deprecated.  
 Legend getLegend(int index)
          Returns the legend box with the given index.
 RightTitle getRightTitle()
          Returns a reference to the RightTitle object.
 java.util.Vector getSeries()
          Returns a collection of references to series added to the graphic context.
 ToolTip getToolTip()
          Returns a reference to the ToolTip object.
 boolean isPainted()
          Deprecated.  
protected  void processMouseEvent(java.awt.event.MouseEvent evt)
          Overrides the processMouseEvent method to control dispatch of mouse events.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent evt)
          Overrides the processMouseMotionEvent method to control dispatch of mouse motion events.
 void readXMLData(java.io.Reader reader)
          Reads chart properties from an xml character stream.
 void refresh()
          Refreshes chart.
 void removeAllNotes()
          Removes all Note objects from the chart context.
 void removeAllSeries()
          Removes all series from the graphic context.
 void removeLegend(Legend l)
          Removes a Legend box.
 void removeNote(Note note)
          Removes a Note object from the chart context.
 void removeSerie(AbstractSerie serie)
          Removes a series from the graphic context.
 void removeSerieListener(SerieListener serieListener)
          Removes a series event listener.
 void set3DEnabled(boolean is3DEnabled)
          Enables/disables 3D chart.
 void setBackgroundImage(java.awt.Image backgroundImage, int imagePosition)
          Defines an image to be painted as the chart background.
 void setBottomMargin(int bottomMargin)
          Sets chart bottom margin, in pixels.
 void setBufferedImageEnabled(boolean isBufferedImageEnabled, int bufferedImageType)
          Enables/disables generation of offscreen images on a BufferedImage object.
 void setConnection(java.lang.String jdbcURL, java.lang.String user, java.lang.String password)
          Sets the database URL, user name and password to connect to a database and get chart labels and series values.
 void setDefaultCursor(java.awt.Cursor defaultCursor)
          Sets the default cursor of this component.
 void setDraggingBoxColor(java.awt.Color draggingBoxColor)
          Sets the dragging box color.
 void setDraggingEnabled(boolean isDraggingEnabled)
          Enables/disables chart dragging.
 void setDriver(java.lang.String jdbcDriver)
          Sets a JDBC driver to connect to a database and get chart labels and series values.
 void setLabelsQuery(java.lang.String labelsQuery)
          Sets a sql statement to access a database and get chart labels.
 void setLeftMargin(int leftMargin)
          Sets chart left margin, in pixels.
 void setLegendEnabled(boolean isLegendEnabled)
          Enables/disables display of the primary Legend object.
 void setOffScreenGraphEnabled(boolean isOffScreenGraphEnabled)
          Enables chart image generation from an offscreen application.
 void setRightMargin(int rightMargin)
          Sets chart right margin, in pixels.
 void setTitle(java.lang.String[] title)
          Sets chart title.
 void setTitleFont(java.awt.Font font)
          Sets chart title font.
 void setTitleForeground(java.awt.Color titleForeground)
          Sets chart title color.
 void setTitleGap(int titleGap)
          Sets the chart title gap.
 void setTopMargin(int topMargin)
          Sets chart top margin, in pixels.
 void setValueFormat(java.lang.String valueFormat)
          Deprecated.  
 
Methods inherited from class com.jinsight.jetchart.GradientPanel
paint, setGradientColors, setGradientOrientation
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TILE

public static final int TILE
Constant used to arrange the background image side by side.

TOP_LEFT

public static final int TOP_LEFT
Constant used to place the background image at the top left corner of the chart area.

CENTER

public static final int CENTER
Constant used to place the background image at the center of the chart.
Method Detail

addSerieListener

public void addSerieListener(SerieListener serieListener)
Adds a series event listener to handle series events. A series event listener is an object that adheres to the SerieListener interface, implementing callback methods to handle series events.
Parameters:
serieListener - A SerieListener object.
See Also:
removeSerieListener(com.jinsight.jetchart.SerieListener), SerieListener, SerieEvent

removeSerieListener

public void removeSerieListener(SerieListener serieListener)
Removes a series event listener. A series event listener is an object that adheres to the SerieListener interface, implementing callback methods to handle series events.
Parameters:
serieListener - A SerieListener object.
See Also:
addSerieListener(com.jinsight.jetchart.SerieListener), SerieListener, SerieEvent

addSerie

public void addSerie(AbstractSerie serie)
Adds series objects to the chart context. Except for pie series, JetChart can display more than one series simultaneously.

Only series belonging to the same type of chart context can be combined. For example, a line series can be combined with another line series, a bar series, an area series, etc., but can not be combined with an xy series, whose chart context is ScatterGraph.

Parameters:
serie - Any series that extends the AbstractSerie class.
See Also:
AbstractSerie, GraphException

getSeries

public java.util.Vector getSeries()
Returns a collection of references to series added to the graphic context.
Returns:
A Vector object.

removeSerie

public void removeSerie(AbstractSerie serie)
Removes a series from the graphic context.
Parameters:
serie - Any series that extends the AbstractSerie class and that was previously added to the chart context.
See Also:
AbstractSerie

removeAllSeries

public void removeAllSeries()
Removes all series from the graphic context.

addLegend

public void addLegend(Legend l)
Adds a new Legend box to the chart context.
Parameters:
l - A Legend object.
See Also:
removeLegend(com.jinsight.jetchart.Legend), Legend

removeLegend

public void removeLegend(Legend l)
Removes a Legend box. The primary Legend object has index 0 and cannot be removed. All series not added to secondaries Legend objects are added to the primary one.
Parameters:
l - A Legend object.
See Also:
addLegend(com.jinsight.jetchart.Legend), Legend

getLegend

public Legend getLegend(int index)
Returns the legend box with the given index. The primary Legend object always has index 0.
Parameters:
index - An integer number.
See Also:
addLegend(com.jinsight.jetchart.Legend), removeLegend(com.jinsight.jetchart.Legend), Legend

addNote

public void addNote(Note note)
Adds a Note object to the chart context. The Note class displays notes over the chart area. Note objects can be dropped onto any place and be dragged across the chart area.
Parameters:
note - A Note object.
See Also:
Note

removeNote

public void removeNote(Note note)
Removes a Note object from the chart context.
Parameters:
note - A Note object.
See Also:
Note

removeAllNotes

public void removeAllNotes()
Removes all Note objects from the chart context.
See Also:
Note

setOffScreenGraphEnabled

public void setOffScreenGraphEnabled(boolean isOffScreenGraphEnabled)
Enables chart image generation from an offscreen application. A chart image can be generated even if an application is not visible. If this method is set to true, an invisible Frame object and a non-null sized Image object on which the chart is painted are created. The chart size must be previously set with the setSize() method.
If the method setBufferedImageEnabled is set to true, a BufferedImage object is used to paint chart, rather than a invisible Frame object.
Parameters:
isOffScreenGraphEnabled - A boolean value(true/false).
See Also:
ChartEncoder, setBufferedImageEnabled(boolean, int)

setBufferedImageEnabled

public void setBufferedImageEnabled(boolean isBufferedImageEnabled,
                                    int bufferedImageType)
Enables/disables generation of offscreen images on a BufferedImage object. By default, an offscreen image is an Image object created with the Component.createImage(int width,int height) method. If this method is set to true, a BufferedImage object is used instead.
JetChart invokes the method GenericGraph.createImage when producing the left and right rotated titles, the bottom title and the rotated vertical labels, as well as when a chart is encoded into a GIF, JPEG or PNG image using the ChartEncoder class. Unless the GenericGraph instance is laid out on a valid container, like a Frame object, a null Image is returned and a NullPointerException is raised during execution of any of the processes above mentioned.
This method is especially useful if charts are generated with servlets using the BufferedImage class and explicitly invoking one of the image encoders available, rather than using the ChartEncoder class. In such scenario, the GenericGraph object is not laid out on a container and if a servlet tries to encode a chart displaying the left, right and bottom titles and vertical labels, a call to the method GenericGraph.createImage raises a NullPointerException. If this method is set to true, the offscreen images are created using the BufferedImage class, and no exception is raised.
The BufferedImage class was introduced in the JDK 1.2. Therefore, this method only affects applications running with a JVM 1.2 and newer versions.
Parameters:
isBufferedImageEnabled - A boolean value(true/false).
bufferedImageType - The image type, which can be one of the constants defined in the BufferedImage class.
See Also:
setOffScreenGraphEnabled(boolean), ChartEncoder, BufferedImage

setDraggingEnabled

public void setDraggingEnabled(boolean isDraggingEnabled)
Enables/disables chart dragging. If chart dragging is enabled, a double-click alternates between size adjustment and dragging. The legend box can also be moved to the left, right and bottom positions. To move the legend box, double-click it and a surrounding border in red is displayed indicating that the chart is in a 'moving legend' state. Then move mouse cursor to the position where the legend box must be dropped. If the cursor is within a valid area, an outlined rectangle is displayed. Click inside the rectangle to move the legend box to that position and return chart to normal state. To return from a 'moving legend' state without changing legend box position, double click the legend box again.

Pie chart dragging is performed by clicking the area outside a pie series bounds. Chart dragging is disabled, by default.

Parameters:
isDraggingEnabled - A boolean value(true/false).
See Also:
PieSerie

setTitleGap

public void setTitleGap(int titleGap)
Sets the chart title gap. The title gap is the distance in pixels from the title bottom to the top of the chart area. Default value is 10 pixels.
Parameters:
titleGap - An integer number.

setBackgroundImage

public void setBackgroundImage(java.awt.Image backgroundImage,
                               int imagePosition)
Defines an image to be painted as the chart background.
Parameters:
backgroundImage - An Image object.
imagePosition - One of the following constants: GenericGraph.TILE, GenericGraph.TOP_LEFT, GenericGraph.CENTER.
See Also:
TILE, TOP_LEFT, CENTER

isPainted

public boolean isPainted()
Deprecated.  

This method is deprecated.
Returns:
a boolean value(true/false)

setDefaultCursor

public void setDefaultCursor(java.awt.Cursor defaultCursor)
Sets the default cursor of this component.
Parameters:
defaultCursor - A Cursor object.

setLabelsQuery

public void setLabelsQuery(java.lang.String labelsQuery)
Sets a sql statement to access a database and get chart labels. The query must return only one column, otherwise an exception is raised.
Parameters:
labelsQuery - A sql statement.
See Also:
setDriver(java.lang.String), setConnection(java.lang.String, java.lang.String, java.lang.String)

setDriver

public void setDriver(java.lang.String jdbcDriver)
Sets a JDBC driver to connect to a database and get chart labels and series values.
Parameters:
jdbcDriver - A JDBC driver to connect to a database.
See Also:
setConnection(java.lang.String, java.lang.String, java.lang.String), Graph.setLabelsQuery(java.lang.String), AbstractSerie.setValuesQuery(java.lang.String)

setConnection

public void setConnection(java.lang.String jdbcURL,
                          java.lang.String user,
                          java.lang.String password)
Sets the database URL, user name and password to connect to a database and get chart labels and series values.
Parameters:
jdbcURL - The database URL
user - The user name
password - The user password
See Also:
setDriver(java.lang.String), Graph.setLabelsQuery(java.lang.String), AbstractSerie.setValuesQuery(java.lang.String)

setTitle

public void setTitle(java.lang.String[] title)
Sets chart title. Chart title can have multiple lines. Each line must be passed as an element of an array of strings.
Parameters:
title - An array of strings.

setTitleForeground

public void setTitleForeground(java.awt.Color titleForeground)
Sets chart title color.
Parameters:
titleForeground - A Color object.

setTitleFont

public void setTitleFont(java.awt.Font font)
Sets chart title font.
Parameters:
font - A Font object.

setValueFormat

public void setValueFormat(java.lang.String valueFormat)
Deprecated.  

This method is now implemented in the AbstractSerie class. Migration was necessary to bring more flexibility. It is possible, now, to have tooltips displaying values with different patterns, since the value format is associated with each series, rather than with the entire graph.
See Also:
AbstractSerie.setValueFormat(java.lang.String)

setLeftMargin

public void setLeftMargin(int leftMargin)
Sets chart left margin, in pixels.
Parameters:
leftMargin - An integer representing left margin.

setRightMargin

public void setRightMargin(int rightMargin)
Sets chart right margin, in pixels.
Parameters:
rightMargin - An integer representing right margin.

setTopMargin

public void setTopMargin(int topMargin)
Sets chart top margin, in pixels.
Parameters:
topMargin - An integer representing top margin.

setBottomMargin

public void setBottomMargin(int bottomMargin)
Sets chart bottom margin, in pixels.
Parameters:
bottomMargin - An integer representing bottom margin.

set3DEnabled

public void set3DEnabled(boolean is3DEnabled)
Enables/disables 3D chart. Scatter charts and OHLC charts are always displayed in 2D mode. Charts are bidimensional by default.
Parameters:
is3DEnabled - A boolean value(true/false).

getLegend

public Legend getLegend()
Deprecated.  

Returns a reference to the primary Legend object. This method is deprecated. Use getLegend(0) instead.
Returns:
Legend object.
See Also:
getLegend(int index), Legend

getToolTip

public ToolTip getToolTip()
Returns a reference to the ToolTip object.
Returns:
ToolTip object.
See Also:
ToolTip

getLeftTitle

public LeftTitle getLeftTitle()
Returns a reference to the LeftTitle object.
Returns:
LeftTitle object.
See Also:
LeftTitle

getRightTitle

public RightTitle getRightTitle()
Returns a reference to the RightTitle object.
Returns:
RightTitle object.
See Also:
RightTitle

getBottomTitle

public BottomTitle getBottomTitle()
Returns a reference to the BottomTitle object.
Returns:
BottomTitle object.
See Also:
BottomTitle

setLegendEnabled

public void setLegendEnabled(boolean isLegendEnabled)
Enables/disables display of the primary Legend object. This method is deprecated. Use getLegend(int index).setEnabled(boolean isEnabled) instead.
Parameters:
isLegendEnabled - A boolean value(true/false).
See Also:
addLegend(com.jinsight.jetchart.Legend), removeLegend(com.jinsight.jetchart.Legend), Legend

setDraggingBoxColor

public void setDraggingBoxColor(java.awt.Color draggingBoxColor)
Sets the dragging box color. The dragging box is displayed either when the chart is dragged/ resized or the mouse cursor is moved to the chart left, right, or bottom sides while the legend box is in a 'moving-legend' state. In the latter case, the box represents a valid area within which the legend box can be dropped. Default color is blue.
Parameters:
draggingBoxColor - A Color object.
See Also:
setDraggingEnabled(boolean)

readXMLData

public void readXMLData(java.io.Reader reader)
                 throws java.io.IOException
Reads chart properties from an xml character stream. The incoming data must follow some rules regarding the xml elements to be parsed. Currently, only chart labels and series values are supported. Future versions of JetChart will support a complete set of xml elements to specify all chart properties. The structure of the xml character stream is the following:

<chart>
  <labels>
     l1
     l2
     l3
     l4

  </labels>
  <series id="1">
    <values>
       80
       100
       70
       60

    </values>
  </series>
  <series id="2">
    <multiplevalues qty="4" delimiter="|">
       10|20|15|35
       22|38|12|40
       17|50|20|13
       25|14|38|55

    </multiplevalues>
  </series>
</chart>

In the xml sequence above, we can see the following xml elements and attributes:

<chart> - This is the root element, and it must be closed at the end of the xml file.

<labels> - Used to list textual data representing the chart labels.

<series> - Encloses the properties of a series. The id attribute is used to identify the series within the chart context. It is compared with the value returned by the AbstractSerie.getId() method, and if they match, the properties read from this xml file are assigned to the identified series.

<values> - Used to list textual data representing a series values.

<multiplevalues> - Used to set values of series that display data points associated with multiple values, like ohlc series, for example. The qty attribute is mandatory, and it is used to set the exact number of values expected from each line listed within the <multiplevalues> tag. The delimiter attribute is optional. It is used by the xml parser to tokenize values. If not informed, a space character is used.

Every opened xml element must be closed, otherwise the xml parser raises an exception.
Parameters:
reader - The reader from which to retrieve the XML data.
Throws:
java.io.IOException - If an error occured while reading the input.
GraphException - If the XML data does not follow certain rules related to the definition of acceptable tags.
See Also:
AbstractSerie.getId()

refresh

public void refresh()
Refreshes chart. The first time a chart is displayed, some private methods of several classes are invoked, and these processes are executed just one time, unless any change that affects chart data or appearance takes place. If labels and series values are retrieved from a database, the sql queries are resubmitted.

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent evt)
Overrides the processMouseEvent method to control dispatch of mouse events. This method consumes mouse events if the chart has not been painted yet. After the first painting, mouse events are dispatched normally.
Overrides:
processMouseEvent in class java.awt.Component

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent evt)
Overrides the processMouseMotionEvent method to control dispatch of mouse motion events. This method consumes mouse motion events if the chart has not been painted yet. After the first painting, mouse motion events are dispatched normally.
Overrides:
processMouseMotionEvent in class java.awt.Component

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class GradientPanel