|
INTRODUCTION
With this powerful and advanced line chart applet you can setup an interactive
chart of your data. Many advanced features are included such as a tool
tip text window and bezier curve fitting abilities. The applet has the
following features:
- Smooth bezier curves can be fitted to your data.
- The applet has a tip text measurer, which is activated when the user
moves the mouse pointer across the chart.
- An unlimited number of curves are supported and axis ranges are automatically
calculated for the curves.
- A color value, label text and tip text description for each line can
be specified.
- Supports a background image.
- You can specify the axis color, text color, title color, selection
color, background color, the description text and background color.
- Very simple to use but can be customized with numberous amount of
methods. See the API.
Before using this Java bean you must read the license
agreement.
BEAN GENERAL INFORMATION
| Developer: |
Anibal Wainstein |
| Version: |
1.0 |
| Version date: |
2000-12-17 |
| Last update information: |
<NONE> |
DEPENDENT FILES
The following file must be included with your project in order for this
bean to function properly:
linechart.jar (or linechartunregistered.jar)
ADDING THE JAVA BEAN TO YOUR PROJECT
To add this Java bean to your Java application project. Make sure this
bean is in your classpath. If you want to make an applet. Make sure to
add the jar file to the "ARCHIVE" HTML parameter in the applet
head HTML code. This bean is part of the mandomartis.* package, so use
this line to import the bean to your Java application or applet. Note
that this applet is written for Java 1.1 and above and will only work
in Java programming projects. Make sure to check that the Java Virtual
Machine or the target browser supports this version of Java.
THE JAVA BEAN API
Class mandomartis.linechart
Object
|
+----Component
|
+----Container
|
+----Panel
|
+----mandomartis.linechart
- public class linechart
- extends Panel
- implements Runnable
Constuctors
public linechart()
Methods
public void addLine(String text,
String description,
Color color,
double[] numberdatax,
double[] numberdatay)
- Adds a chart line with data with x values. NOTE, you may not use
the other addLine method when using this one. Don't mix the both methods.
-
- Parameters:
- text - The line item text.
- description - The tooltip description text.
- color - The line color.
- numberdatax - Array with x-axis number data
- numberdatay - Array with the y-axis number data.
public void addLine(String text,
String description,
Color color,
double[] numberdatay)
- Adds a chart line with data without any x values. NOTE, you may not
use the other addLine method when using this one. Don't mix the both
methods.
-
- Parameters:
- text - The text item for the line.
- description - The tooltip description.
- color - The color of the line.
- numberdatay - Array with the number data.
public void createEffect()
- This method will initialize and execute the animation and effect.
Make sure you do any parameter settings BEFORE running this method.
Otherwise they will not be used in the effect.
public java.awt.Color getAxisColor()
- Gets the axis color.
-
- Returns:
- The axis color.
public java.awt.Color getBackgroundColor()
- Sets the chart's background color.
-
- Returns:
- The background color.
public java.awt.Image getBackgroundImage()
- Gets the background image used in the chart.
-
- Returns:
- The background image.
public boolean getCenterItems()
- This will get the status of the items, if they are centered vertically
or not.
-
- Returns:
- The center items flag.
public int getChartWidth()
- This gets the chart width.
-
- Returns:
- The width in pixels.
public int getDelay()
- This gets the general frame delay in milliseconds. The default value
is 70.
-
- Returns:
- The frame delay in milliseconds
public java.awt.Color getDescriptionBackgroundColor()
- Sets the description background color (the tooltip background color).
-
- Returns:
- The description background color.
public java.awt.Color getDescriptionTextColor()
- Gets the description text color (the tooltip text color).
-
- Returns:
- The description text color.
public int getDescriptionTextSpeed()
- Sets the description text scrolling speed.
-
- Returns:
- The description text scrolling speed in pixels.
public int getDescriptionWindowWidth()
- This gets the description tooltip window width.
-
- Returns:
- The width in pixels.
public boolean getInitialAnimationEnabled()
- This gets the status of the initial animation flag.
-
- Returns:
- The initial animation flag.
public int getInitialAnimationSpeed()
- Gets the initial animation speed. Default value 1.
-
- Returns:
- The initial animation speed.
public int getItemTextDistance()
- Gets the vertical distance between each text label.
-
- Returns:
- The distance in pixels.
public java.awt.Color getLineMarkerColor()
- Gets the line marker color
-
- Returns:
- The line marker color.
public int getMarkerSize()
- This sets line marker size.
-
- Returns:
- The size in pixels.
public java.awt.Color getSelectedColor()
- Gets the general color for a selected line.
-
- Returns:
- The selected line color.
public int getSleeptime()
- This gets the "sleeptime" which is the pause before the next image
appears.
-
- Returns:
- The sleeptime in milliseconds
public java.awt.Color getTextColor()
- Gets the text color (for the text items).
-
- Returns:
- The text color.
public int getTextDistanceX()
- This gets the text label distance from the left border.
-
- Returns:
- The text distance.
public java.awt.Font getTextFont()
- Gets the text font
-
- Returns:
- The text font
public java.awt.Font getTitleFont()
- Gets the title font.
-
- Returns:
- The title font.
public java.lang.String getTitleText()
- Gets the title text.
- Returns:
- The title text
-
-
public java.awt.Color getTitleTextColor()
- Gets the current title text color
-
- Returns:
- The title text color
public boolean getUseCircleMarker()
- Gets if the chart is using circular markers.
-
- Returns:
- The circle marker flag.
public boolean getUseCurveFitting()
- Gives you information if smooth curve fitting is used.
-
- Returns:
- If curve fitting is used.
public boolean getUseLineMarkers()
- Gets if the chart is using line markers.
-
- Returns:
- The line marker flag.
public boolean getUseTitle()
- Gives you information if the title is being displayed or not.
-
- Returns:
- The use title flag.
public boolean getUseXData()
- Gives you information if the x data is being used for each line.
-
- Returns:
- The usexdata flag.
public void removeLine(int linenumber)
- Removes a chart line. Can be done at real-time (after running createEffect).
-
- Parameters:
- linenumber - The line index to remove.
public void setAxisColor(Color axiscolor)
- Sets the axis color.
-
- Parameters:
- axiscolor - The axis color
public void setBackgroundColor(Color backgroundcolor)
- Sets the chart's background color.
-
- Parameters:
- backgroundcolor - The background color.
public void setBackgroundImage(Image backgroundimage)
- Sets the background image to be used in the chart (optionally).
-
- Parameters:
- backgroundimage - The background image, setting this to null
will disable the background image.
public void setCenterItems(boolean centeritems)
- This will center the line item texts vertically.
-
- Parameters:
- centeritems - Center by setting this variable to true.
public void setChartWidth(int chartwidth)
- This sets the chart width. Any labels will be placed to the right
of this area.
-
- Parameters:
- chartwidth - The width in pixels.
public void setDelay(int delay)
- This controls the general frame delay in milliseconds, and thus the
frames per second (FPS). The default value is 70.
-
- Parameters:
- delay - The frame delay in milliseconds
public void setDescriptionBackgroundColor( Color descriptionbackgroundcolor)
- Sets the description background color (the tooltip background color).
-
- Parameters:
- descriptionbackgroundcolor - The description background color.
public void setDescriptionTextColor( Color descriptiontextcolor)
- Sets the description text color (the tooltip text color).
-
- Parameters:
- descriptiontextcolor - The description text color.
public void setDescriptionTextSpeed( int descriptiontextspeed)
- Sets the description text scrolling speed.
-
- Parameters:
- descriptiontextspeed - The description text scrolling speed in
pixels
public void setDescriptionWindowWidth( int descriptionwindowwidth)
- This sets the description tooltip window width.
-
- Parameters:
- descriptionwindowwidth - The width in pixels.
public void setInitialAnimationEnabled( boolean enableinitialanimation)
- This enables the initial animation.
-
- Parameters:
- enableinitialanimation - Set to true to enable.
public void setInitialAnimationSpeed(
int initialanimationspeed)
- Sets the initial animation speed. Default value 1.
-
- Parameters:
- initialanimationspeed - The initial animation speed.
public void setItemTextDistance(int itemtextdistance)
- The vertical distance between each text label.
-
- Parameters:
- itemtextdistance - The distance in pixels
public void setLineMarkerColor(Color linemarkercolor)
- Sets the line marker color.
-
- Parameters:
- linemarkercolor - The line marker color.
public void setMarkerSize(int markersize)
- This sets line marker size.
-
- Parameters:
- markersize - The size in pixels.
public void setSelectedColor(Color selectedcolor)
- Sets the general color for a selected line.
-
- Parameters:
- selectedcolor - The selected line color.
public void setSleeptime(int sleeptime)
- This sets the "sleeptime" which is the pause before the next image
appears.
-
- Parameters:
- sleeptime - The value in milliseconds
public void setTextColor(Color textcolor)
- Sets the text color (for the text items).
-
- Parameters:
- textcolor - The text color.
public void setTextDistanceX(int textdistancex)
- The text distance x position affect the text label distance from the
left border.
-
- Parameters:
- textdistancex - The text distance x position.
public void setTextFont(Font font)
- Sets the text font
-
- Parameters:
- font - The text font
public void setTitleFont(Font font)
- Sets the font for the title text.
-
- Parameters:
- font - The title font
public void setTitleText(String titletext)
- Sets the title text.
-
- Parameters:
- titletext - The title text.
public void setTitleTextColor(Color titletextcolor)
- Sets the title text color
-
- Parameters:
- titletextcolor - The title text color
public void setUseCircleMarker(boolean usecirclemarker)
- By setting this flag the chart will display circular line markers.
-
- Parameters:
- usecirclemarker - The circle marker flag.
public void setUseCurveFitting(boolean usecurvefitting)
- Sets if curve fitting using smooth bezier curves should be used for
all your chart lines. Note that the bezier curves will only give good
results for data with small fluctuation. This flag will be overridden
if you set the usexdata flag to false and no curve fitting will be done
then.
-
- Parameters:
- usecurvefitting - Set to true to enable curve fitting.
public void setUseLineMarkers(boolean uselinemarkers)
- By setting this flag the chart will use the line markers.
-
- Parameters:
- uselinemarkers - The use line marker flag.
public void setUseTitle(boolean usetitle)
- Sets the use of title
-
- Parameters:
- usetitle - Set to true to use the title text
public void setUseXData(boolean usexdata)
- Sets if the x data is being used. If this parameter is set to false
once, then you will not be able to set it later to true later. Also
if you use the addLine parameter without using the x-axis, then this
parameter will be set to false too. Note also that by setting this parameter
to false, the curve fitting feature will be disabled.
-
- Parameters:
- usexdata - The usexdata flag.
SETTING UP THE JAVA BEAN WITH CHART LINES
The following example will setup the bean to display a sine and cosine
curve (this example can be run if you try to run the bean as an application):
linechart chart=new linechart();
double x[][]=new double[2][10]; double y[][]=new double[2][10]; int j=0; for (double i=0; i<10.0; i++) { y[0][j]=20.0*Math.sin(40.0*i*Math.PI/180.0)+20.0; y[1][j]=20.0*Math.cos(40.0*i*Math.PI/180.0)+20.0; x[0][j]=40.0*i*Math.PI/180.0; x[1][j]=40.0*i*Math.PI/180.0; j++; } chart.addLine("Sine","A sine curve." ,Color.orange,x[0],y[0]); chart.addLine("Cosine","A cosine curve." ,Color.pink,x[1],y[1]); chart.setUseTitle(true); chart.setTitleText("Mandomartis LineChart Bean"); chart.setBackgroundColor(new Color(0x7f7fff)); chart.createEffect();
To add chart lines use the addLine methods. Note carefully that you should
not use both these methods in one linechart component, since one uses
the x-axis data and the other doesn't. To prevent errors, the setUseXData
method has been tweaked and if it's set to false once, then you will not
be able to change it back after that. Make sure you use the "set"
methods BEFORE using the createEffect() method, otherwise all the properties
set will not be used in the displayed chart. The createEffect() method
executes the code. If you want to use bezier curve fitting you should
know that it works best with data with small fluctuation (with small difference
between the values). Note that the only image formats supported are JPEG
and GIF files. Do not use transparent GIF files in this bean. Also note
that each image will NOT be automatically resized to fit in the bean component
area. Here is the screenshot of the bean running in an application:

|