Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.java4less.rchart
Class Chart

    java.lang.Object
      |
      +--com.java4less.rchart.Chart

public class Chart
extends java.lang.Object

    Main class of RChart. The Chart class calculates the position and size of all the components and calls the draw method of them as required.

    Example of use:

    // data
    double[] d1={1,2,3,4,5,4,2};
    BarDataSerie data1= new BarDataSerie(d1,new FillStyle(GraphicsProvider.getColor(ChartColor.CYAN)));
    data1.border=new LineStyle(0.2f,GraphicsProvider.getColor(ChartColor.BLACK),LineStyle.LINE_NORMAL);
    //data1.borderType=BarDataSerie.BORDER_RAISED;
    data1.border=new LineStyle(0.2f,GraphicsProvider.getColor(ChartColor.BLACK),LineStyle.LINE_NORMAL);
    data1.valueFont=GraphicsProvider.getFont("Arial",ChartFont.BOLD,10);

    double[] d2={-2,3,4,4.2,6.4,4.5,6.1};
    BarDataSerie data2= new BarDataSerie(d2,new FillStyle(GraphicsProvider.getColor(ChartColor.GREEN)));
    data2.valueFont=GraphicsProvider.getFont("Arial",ChartFont.BOLD,10);
    data2.border=new LineStyle(0.2f,GraphicsProvider.getColor(ChartColor.BLACK),LineStyle.LINE_NORMAL);
    data2.negativeStyle=new FillStyle(GraphicsProvider.getColor(ChartColor.RED));

    Legend l=new Legend();
    l.border=new LineStyle(0.2f,GraphicsProvider.getColor(ChartColor.BLACK),LineStyle.LINE_NORMAL);
    l.addItem("Company A",new FillStyle(GraphicsProvider.getColor(ChartColor.CYAN)));
    l.addItem("Company B",new FillStyle(GraphicsProvider.getColor(ChartColor.GREEN)));

    // create title
    Title title=new Title("Benefits companies A & B");
    // create axis
    Axis  XAxis=new Axis(Axis.HORIZONTAL,new Scale());
    Axis  YAxis=new Axis(Axis.VERTICAL,new Scale());
    XAxis.tickAtBase=true; // draw also first tick
    XAxis.scale.min=-3;
    XAxis.scale.max=7;
    YAxis.scale.min=0;
    YAxis.scale.max=7;
    YAxis.IntegerScale=true;
    YAxis.scaleTickInterval=1;
    XAxis.scaleTickInterval=1;
    XAxis.gridStyle=new LineStyle(0.2f,GraphicsProvider.getColor(ChartColor.WHITE),LineStyle.LINE_DOTS);
    YAxis.gridStyle=new LineStyle(0.2f,GraphicsProvider.getColor(ChartColor.WHITE),LineStyle.LINE_DOTS);
    String[] lbls={"1998","1999","2000","2001","2002","2003","2004","2005"};
    YAxis.tickLabels=lbls;

    HAxisLabel XLabel= new HAxisLabel("million $",GraphicsProvider.getColor(ChartColor.BLACK),GraphicsProvider.getFont("Arial",ChartFont.BOLD,12));
    VAxisLabel YLabel= new VAxisLabel("Year",GraphicsProvider.getColor(ChartColor.BLACK),GraphicsProvider.getFont("Arial",ChartFont.BOLD,12));

    // plotter
    BarPlotter plot=new BarPlotter();
    plot.verticalBars=false;
    plot.interBarSpace=0;

    // create chart
    Chart chart=new Chart(title,plot,XAxis,YAxis);
    chart.XLabel=XLabel;
    chart.YLabel=YLabel;
    chart.legend=l;
    chart.addSerie(data2);
    chart.addSerie(data1);
    chart.back=new FillStyle(GraphicsProvider.getColor(ChartColor.LIGHTGRAY));
    chart.saveToFile("chart.gif","GIF");

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` | `autoRebuild` rebuild the chart (using the ChartLoader) automatically when the chart is updated using the updater thread?
`boolean` | `autoSize` if true (default) the position and size of the components will be calculated automatically.
`double` | `axisMargin`
`FillStyle` | `back` background of the chart.
`ChartImage` | `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` use double buffering for creating the chart?
`boolean` | `fullXAxis`
`java.lang.String` | `htmlLinkTarget` target of the html links when creating a html image map
`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` legend of the chart
`double` | `legendMargin` area reserved for the legend.
`ChartLoader` | `loader` loader using to create the chart and/or update it automatically
`long` | `msecs` reload the chart every x secodns
`static java.lang.String` | `numberLocale` locale used for decimal number formatting
`int` | `offsetX` used by th chart viewer only for scroll functions
`int` | `offsetY` used by th chart viewer only for scroll functions
`Plotter[]` | `plotters` array of plotter if the chart
`java.lang.String` | `reloadFrom` url where the chart should be reloaded from
`boolean` | `repaintAll` force the paint to be repainted
`boolean` | `repaintAlways` replaint the chart each time the paint() method is called?
`double` | `rightMargin` empty area to the right side of the chrta if the legend is on the top or the bottom
`double` | `secondYAxisMargin` margin reserved for the right Y axis
`ChartLabel` | `selectedLabel` holds the selected chartlabel
`DataSerie` | `selectedSerie` holds the DataSerie of the selected point
`int` | `selectedSeriePoint` returns which point/bar/item of the serie the cursor is on or -1.
`boolean` | `showPosition` show position of cursor (only if used inside an applet)
`boolean` | `showTips` show tips?
`Title` | `title` title of the chart
`double` | `topMargin` area reserved for the title.
`int` | `virtualHeight` height of the chart (in pixels).
`int` | `virtualWidth` width of the chart (in pixels).
`boolean` | `withScroll` used by the chart viewers to enable scroll
`Axis` | `XAxis` X axis of the chart
`HAxisLabel` | `XLabel` Label to be displayed along the X axis.
`Axis` | `Y2Axis` second Y axis of the chart
`VAxisLabel` | `Y2Label` Label to be displayed along the second Y axis.
`Axis` | `YAxis` Y axis of the chart
`VAxisLabel` | `YLabel` Label to be displayed along the Y axis.

Constructor Summary
`Chart(Title t, Plotter p, Axis X, Axis Y)` creates a chart for the specified components.

Method Summary
`void` | `addChartListener(ChartListener cl)` add a chart listener
`void` | `addNote(java.lang.String note)` add new note
`void` | `addPlotter(Plotter p)` adds an additional plotter to the chart.
`void` | `addSerie(DataSerie s)` adds a serie to the plotter (the one used in the constructor).
`void` | `addTargetZone(TargetZone zone)` add new targe zone
`void` | `dispose()` release resources used by the chart (only required for SWT)
`int` | `getHeight()` height of the component
`java.lang.String` | `getHTMLImageMap(java.lang.String name)` get HTML image map code.
`TargetZone[]` | `getTargetZones()` get list of all target zones
`int` | `getWidth()` width of the component
`void` | `mouseClick()` let rchart know the mouse has been clicked (this is normally called by the chartviewer)
`void` | `mouseMoved(int eX, int eY)` mouse has moved above the chart, notify new position.
`void` | `paint(ChartGraphics pg)` paint chart on the given graphic context
`void` | `removeAllChartListener()` remove all listeners
`void` | `removeChartListener(ChartListener cl)` remove a chart listener
`void` | `removeNotes()` delete all notes
`void` | `removePlotters()` remove all plotters
`void` | `removeTargetZones()` delete all target zones
`void` | `saveToFile(java.io.OutputStream os, java.lang.String psFormat)` Saves the current chart to an output stream If you use AWT the format can be "GIF", "PNG" or "JPEG".
`void` | `saveToFile(java.lang.String psFile, java.lang.String psFormat)` Saves the current chart to a graphics file.
`void` | `setHeight(int h)` height of the component
`void` | `setMinimumSize(int w, int h)` set minimum size of the chart
`void` | `setSize(int w, int h)` set size of the chart
`void` | `setWidth(int w)` width of the component
`void` | `setY2Scale(Axis a)` Sets the second Y axis of the chart.
`void` | `startUpdater()` start realtime/automatic chart updates
`void` | `stopUpdater()` stop realtime/automatic updating

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LAYOUT_LEGEND_RIGHT

    public static final int LAYOUT_LEGEND_RIGHT

See Also:
  Constant Field Values

### LAYOUT_LEGEND_TOP

    public static final int LAYOUT_LEGEND_TOP

See Also:
  Constant Field Values

### LAYOUT_LEGEND_BOTTOM

    public static final int LAYOUT_LEGEND_BOTTOM

See Also:
  Constant Field Values

### dnum

    public static final int dnum

See Also:
  Constant Field Values

### numberLocale

    public static java.lang.String numberLocale

  locale used for decimal number formatting

### 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

  legend of the chart

### XAxis

    public Axis XAxis

  X axis of the chart

### YAxis

    public Axis YAxis

  Y axis of the chart

### Y2Axis

    public Axis Y2Axis

  second Y axis of the chart

### title

    public Title title

  title of the chart

### 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

  margin reserved for the right Y axis

### 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

  array of plotter if the chart

### 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

  used by th chart viewer only for scroll functions

### offsetY

    public int offsetY

  used by th chart viewer only for scroll functions

### backImage

    public ChartImage backImage

### doubleBuffering

    public boolean doubleBuffering

  use double buffering for creating the chart?

### 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

  used by the chart viewers to enable scroll

### repaintAll

    public boolean repaintAll

  force the paint to be repainted

### repaintAlways

    public boolean repaintAlways

  replaint the chart each time the paint() method is called?

### fullXAxis

    public boolean fullXAxis

### selectedLabel

    public ChartLabel selectedLabel

  holds the selected chartlabel

### selectedSerie

    public DataSerie selectedSerie

  holds the DataSerie of the selected point

### selectedSeriePoint

    public int selectedSeriePoint

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

### 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.

### htmlLinkTarget

    public java.lang.String htmlLinkTarget

  target of the html links when creating a html image map

### showTips

    public boolean showTips

  show tips?

### showPosition

    public boolean showPosition

  show position of cursor (only if used inside an applet)

### loader

    public ChartLoader loader

  loader using to create the chart and/or update it automatically

### msecs

    public long msecs

  reload the chart every x secodns

### reloadFrom

    public java.lang.String reloadFrom

  url where the chart should be reloaded from

### autoRebuild

    public boolean autoRebuild

  rebuild the chart (using the ChartLoader) automatically when the chart is updated using the updater thread?

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.

Parameters:
  `t` - title
  `p` - plotter
  `X` - axis
  `Y` - axis

Method Detail

### getWidth

    public int getWidth()

  width of the component

### getHeight

    public int getHeight()

  height of the component

### setMinimumSize

    public void setMinimumSize(int w,
                               int h)

  set minimum size of the chart

  Parameters:
    `w` - width
    `h` - height

### setSize

    public void setSize(int w,
                        int h)

  set size of the chart

  Parameters:
    `w` - width
    `h` - height

### addTargetZone

    public void addTargetZone(TargetZone zone)

  add new targe zone

  Parameters:
    `zone` -

### removeTargetZones

    public void removeTargetZones()

  delete all target zones

### addNote

    public void addNote(java.lang.String note)

  add new note

  Parameters:
    `note` -

### removeNotes

    public void removeNotes()

  delete all notes

### getTargetZones

    public TargetZone[] getTargetZones()

  get list of all target zones

  Returns:

### setWidth

    public void setWidth(int w)

  width of the component

### setHeight

    public void setHeight(int h)

  height of the component

### addChartListener

    public void addChartListener(ChartListener cl)

  add a chart listener

  Parameters:
    `cl` -

### removeChartListener

    public void removeChartListener(ChartListener cl)

  remove a chart listener

  Parameters:
    `cl` -

### removeAllChartListener

    public void removeAllChartListener()

  remove all listeners

### addPlotter

    public void addPlotter(Plotter p)

  adds an additional plotter to the chart. In this way it is possible to combine bar charts and line charts.

  Parameters:
    `p` - plotter

### removePlotters

    public void removePlotters()

  remove all plotters

### 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(ChartGraphics pg)

  paint chart on the given graphic context

  Parameters:
    `pg` - graphic context

### 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.

  Parameters:
    `s` - series

### dispose

    public void dispose()

  release resources used by the chart (only required for SWT)

### saveToFile

    public void saveToFile(java.io.OutputStream os,
                           java.lang.String psFormat)
                    throws java.lang.Exception

  Saves the current chart to an output stream If you use AWT 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.). If you use SWT the format can be "GIF", "PNG", "BMP" or "JPEG".

  Parameters:
    `os` - output stream
    `psFormat` - file format
    `java.lang.Exception`

### saveToFile

    public void saveToFile(java.lang.String psFile,
                           java.lang.String psFormat)
                    throws java.lang.Exception

  Saves the current chart to a graphics file. If you use AWT 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.). If you use SWT the format can be "GIF", "PNG", "BMP" or "JPEG".

  Parameters:
    `psFile` - output file
    `psFormat` - file format
  Returns:
    true if the chart was successfully encoded
    `java.lang.Exception`

### mouseClick

    public void mouseClick()

  let rchart know the mouse has been clicked (this is normally called by the chartviewer)

### mouseMoved

    public void mouseMoved(int eX,
                           int eY)

  mouse has moved above the chart, notify new position. This is used by chart viewer to notify the position of the cursor and let rchart update the selected point.

  Parameters:
    `eX` - new x position
    `eY` - new Y position

### startUpdater

    public void startUpdater()

  start realtime/automatic chart updates

### stopUpdater

    public void stopUpdater()

  stop realtime/automatic updating

### getHTMLImageMap

    public java.lang.String getHTMLImageMap(java.lang.String name)

  get HTML image map code. This is used by the servlet to create images and maps

  Parameters:
    `name` - name of the image map
  Returns:
    html code

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD