shh.util
Class LineChart

Object
  extended byComponent
      extended byContainer
          extended byJComponent
              extended byJPanel
                  extended byLineChart
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
StatWin

public class LineChart
extends JPanel

A simple chart showing one or more line graphs. As the mouse moves over the chart, a tooltip displays the coordinates of the points. To use the chart, call the setXXX methods in roughly the order they appear here. Only handles y ≥ 0, and always displays the y-axis. The x-coordinates in the line graphs are the consecutive integers 0, 1, 2, ....

Author:
Karen Wang, Mark McConnell
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
LineChart()
           
 
Method Summary
 Dimension getMinimumSize()
           
 Dimension getPreferredSize()
           
static void main(String[] args)
          Takes arguments u0 v0 u1 v1 u2 v2, etc., all ≥ 0, and plots a chart with two line graphs, one for u and one for v.
protected  void paintComponent(Graphics g)
           
 void setData(float[][] dd, String[] l, Color[] c)
          Main method to set the chart's data.
 void setDataSetVisible(int i, boolean isVisible)
          Set the visibility of the i-th data series (default true).
 void setMaxY(float max)
          Sets the maximum y value.
 void setSignificantFigures(int sigFig)
          Sets the number of significant figures (default 3) in the labels on the y-axis.
 void setTitles(String title, String xaxis, String yaxis)
          Sets the titles.
protected  void setToolTip(MouseEvent e)
          Sets a tooltip on this LineChart.
 
Methods inherited from class JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LineChart

public LineChart()
Method Detail

setMaxY

public void setMaxY(float max)
Sets the maximum y value.


setTitles

public void setTitles(String title,
                      String xaxis,
                      String yaxis)
Sets the titles.


setData

public void setData(float[][] dd,
                    String[] l,
                    Color[] c)
Main method to set the chart's data.

Parameters:
dd - Holds the y values. Of size (number of x-coordinates) × (number of line graphs).
l - Labels for the x values. Of length (number of x-coordinates). If it's null, no labels are used.
c - Colors for the line graphs. Of length (number of line graphs).
Throws:
NullPointerException - If dd is null.

setDataSetVisible

public void setDataSetVisible(int i,
                              boolean isVisible)
Set the visibility of the i-th data series (default true).


setSignificantFigures

public void setSignificantFigures(int sigFig)
Sets the number of significant figures (default 3) in the labels on the y-axis. See Format.roundToSigFig(float, int) for restrictions.


getMinimumSize

public Dimension getMinimumSize()

getPreferredSize

public Dimension getPreferredSize()

paintComponent

protected void paintComponent(Graphics g)

setToolTip

protected void setToolTip(MouseEvent e)
Sets a tooltip on this LineChart.


main

public static void main(String[] args)
Takes arguments u0 v0 u1 v1 u2 v2, etc., all ≥ 0, and plots a chart with two line graphs, one for u and one for v. If there is no data, plots two sine waves.