com.java4less.rchart
Class Chart

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--com.java4less.rchart.Chart
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseMotionListener, java.io.Serializable

public class Chart
extends java.awt.Canvas
implements java.awt.event.MouseMotionListener

Main class of RChart, it links everythings together; axis, plotter, legend, title... RChart calculates the position and size of all the components and calls the draw method of all of them.
Chart is an extension of Canvas so you can put it on your frames, windows, etc...

See Also:
Serialized Form

Field Summary
 boolean activateSelection
          if true the selectedSerie and selectedSeriePoint will get a value of the point, bar or item the cursor is on.
 boolean autoSize
          if true (default) the position and size of the components will be calculated automatically.
 double axisMargin
           
 FillStyle back
          background of the chart.
 java.awt.Image backImage
           
 LineStyle border
          border of the chart.
 double bottomMargin
          area reserved for the x axis.
 double currentValueX
          position of the cursor.
 double currentValueY
          position of the cursor.
 double currentValueY2
          position of the cursor.
 int currentX
          position of the cursor.
 int currentY
          position of the cursor.
static int dnum
           
 boolean doubleBuffering
           
 boolean fullXAxis
           
 int layout
          position of the legend in the chart.
static int LAYOUT_LEGEND_BOTTOM
           
static int LAYOUT_LEGEND_RIGHT
           
static int LAYOUT_LEGEND_TOP
           
 double leftMargin
          area reserved for the y axis.
 Legend legend
           
 double legendMargin
          area reserved for the legend.
 int offsetX
           
 int offsetY
           
 Plotter[] Plotters
           
 boolean repaintAll
           
 boolean repaintAlways
           
 double rightMargin
          empty area to the right side of the chrta if the legend is on the top or the bottom
 double secondYAxisMargin
           
 java.lang.String selectedSerie
          returns name of the serie the cursor is on (points, bars or pie item).
 int selectedSeriePoint
          returns which point/bar/item of the serie the cursor is on or -1.
 Title title
           
static java.awt.Image tmpImage
          You must set this property if you want to draw vertical labels.
 double topMargin
          area reserved for the title.
 int virtualHeight
          height of the chart (in pixels).
 int virtualWidth
          width of the chart (in pixels).
 java.awt.Component visibleComponent
          intenal use
 boolean withScroll
           
 Axis XAxis
           
 HAxisLabel XLabel
          Label to be displayed along the X axis.
 Axis Y2Axis
           
 VAxisLabel Y2Label
          Label to be displayed along the second Y axis.
 Axis YAxis
           
 VAxisLabel YLabel
          Label to be displayed along the Y axis.
 
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
 
Constructor Summary
Chart(Title t, Plotter p, Axis X, Axis Y)
          creates a chart for the specified components.
 
Method Summary
 void addPlotter(Plotter p)
          adds an extra plotter to the chart.
 void addSerie(DataSerie s)
          adds a serie to the plotter (the one used in the constructor).
static int d()
           
static boolean drawVerticalText(java.awt.Graphics g2, java.awt.Font f, java.awt.Color c, java.lang.String t, int x, int y, boolean centered)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void paint(java.awt.Graphics pg)
           
 void removePlotters()
          removes all plotters
 void resetChart(Title t, Plotter p, Axis X, Axis Y)
          change title, plotter and axos
static java.awt.Image rotate(java.awt.Image im, int angle, int maxw, int maxh, java.awt.Color transparent)
           
 boolean saveToFile(java.lang.String psFile, java.lang.String psFormat)
          Saves the current chart to a graphics file (gif , png or jpeg).
 void setBounds(int x, int y, int w, int h)
           
 void setChartListener(ChartListener cl)
           
 void setSize(java.awt.Dimension s)
           
 void setSize(int x, int y)
           
 void setY2Scale(Axis a)
          Sets the second Y axis of the chart.
 
Methods inherited from class java.awt.Canvas
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LAYOUT_LEGEND_RIGHT

public static final int LAYOUT_LEGEND_RIGHT

LAYOUT_LEGEND_TOP

public static final int LAYOUT_LEGEND_TOP

LAYOUT_LEGEND_BOTTOM

public static final int LAYOUT_LEGEND_BOTTOM

dnum

public static final int dnum

activateSelection

public boolean activateSelection
if true the selectedSerie and selectedSeriePoint will get a value of the point, bar or item the cursor is on. Default is false.

currentX

public int currentX
position of the cursor. Is 0 if the curso is not over the chart.

currentY

public int currentY
position of the cursor. Is 0 if the curso is not over the chart.

currentValueX

public double currentValueX
position of the cursor. This is the value according to the scale X.

currentValueY

public double currentValueY
position of the cursor. This is the value according to the scale y.

currentValueY2

public double currentValueY2
position of the cursor. This is the value according to the second scale Y.

YLabel

public VAxisLabel YLabel
Label to be displayed along the Y axis.

Y2Label

public VAxisLabel Y2Label
Label to be displayed along the second Y axis.

XLabel

public HAxisLabel XLabel
Label to be displayed along the X axis.

legend

public Legend legend

XAxis

public Axis XAxis

YAxis

public Axis YAxis

Y2Axis

public Axis Y2Axis

title

public Title title

bottomMargin

public double bottomMargin
area reserved for the x axis. The default is 0.125 (12.5%).

topMargin

public double topMargin
area reserved for the title. The default is 0.125 (12.5%).

secondYAxisMargin

public double secondYAxisMargin

leftMargin

public double leftMargin
area reserved for the y axis. The default is 0.125 (12.5%).

rightMargin

public double rightMargin
empty area to the right side of the chrta if the legend is on the top or the bottom

legendMargin

public double legendMargin
area reserved for the legend. The default is 0.2 (20%).

axisMargin

public double axisMargin

autoSize

public boolean autoSize
if true (default) the position and size of the components will be calculated automatically. If not you must assign a value to the fields x,y,width and height of ChartComponent.

Plotters

public Plotter[] Plotters

layout

public int layout
position of the legend in the chart. Valid values are LAYOUT_LEGEND_TOP,LAYOUT_LEGEND_BOTTOM and LAYOUT_LEGEND_RIGHT (default).

back

public FillStyle back
background of the chart.

border

public LineStyle border
border of the chart.

offsetX

public int offsetX

offsetY

public int offsetY

selectedSerie

public java.lang.String selectedSerie
returns name of the serie the cursor is on (points, bars or pie item).

selectedSeriePoint

public int selectedSeriePoint
returns which point/bar/item of the serie the cursor is on or -1.

tmpImage

public static java.awt.Image tmpImage
You must set this property if you want to draw vertical labels. RChart uses this image for internal processes. If you are displaying the chart in a frame or applet you can set the image like this:

Chart.tmpImage= myVisibleComponent.createImage(500,500);
If you are not displaying the chart , but only encoding it as gif or jpeg you can create a BufferedImage like this:
Chart.tmpImage=new BufferedImage(500,500,java.awt.image.BufferedImage.TYPE_BYTE_INDEXED);

backImage

public java.awt.Image backImage

doubleBuffering

public boolean doubleBuffering

virtualWidth

public int virtualWidth
width of the chart (in pixels). The horizontal scroll bar will be activated if the chart is wider than the available space. (only interactive version)

virtualHeight

public int virtualHeight
height of the chart (in pixels). The vertical scroll bar will be activated if the chart is higher than the available space. (only interactive version)

withScroll

public boolean withScroll

repaintAll

public boolean repaintAll

repaintAlways

public boolean repaintAlways

fullXAxis

public boolean fullXAxis

visibleComponent

public java.awt.Component visibleComponent
intenal use
Constructor Detail

Chart

public Chart(Title t,
             Plotter p,
             Axis X,
             Axis Y)
creates a chart for the specified components. X and Y will be null for a PiePlotter.
Method Detail

resetChart

public void resetChart(Title t,
                       Plotter p,
                       Axis X,
                       Axis Y)
change title, plotter and axos

d

public static int d()

setChartListener

public void setChartListener(ChartListener cl)

addPlotter

public void addPlotter(Plotter p)
adds an extra plotter to the chart. In this way it is possible to combine bar charts and line charts.

removePlotters

public void removePlotters()
removes all plotters

setSize

public void setSize(int x,
                    int y)
Overrides:
setSize in class java.awt.Component

setSize

public void setSize(java.awt.Dimension s)
Overrides:
setSize in class java.awt.Component

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Overrides:
setBounds in class java.awt.Component

setY2Scale

public void setY2Scale(Axis a)
Sets the second Y axis of the chart. This axis will be displayed on the right side of the chart (see DataSerie.secondYAxis).

paint

public void paint(java.awt.Graphics pg)
Overrides:
paint in class java.awt.Canvas

addSerie

public void addSerie(DataSerie s)
adds a serie to the plotter (the one used in the constructor). This method just calls the addSerie method od the plotter, so you can call the plotter's method directly.

drawVerticalText

public static boolean drawVerticalText(java.awt.Graphics g2,
                                       java.awt.Font f,
                                       java.awt.Color c,
                                       java.lang.String t,
                                       int x,
                                       int y,
                                       boolean centered)

rotate

public static java.awt.Image rotate(java.awt.Image im,
                                    int angle,
                                    int maxw,
                                    int maxh,
                                    java.awt.Color transparent)

saveToFile

public boolean saveToFile(java.lang.String psFile,
                          java.lang.String psFormat)
Saves the current chart to a graphics file (gif , png or jpeg). The format can be "GIF", "PNG" or "JPEG". This method has the following retrictions:
The GIF encoder must be downloaded from: http://www.acme.com/resources/classes/Acme.tar.gz
The PNG encoder must be downloaded from: http://users.boone.net/wbrameld/pngencoder/
In order to use the JPEG encoder you must have the package com.sun.image.codec.jpeg installed (It is only available for java 1.2 or later.).

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener