[Index]
[Introduction] [Installation]
[Cookbook] [Package]
[Component] [Chart]
[Axis] [Utility]
[Servlet] [Appndx
A] [Appndx B] [API]
FRAMES
NO FRAMES NO
FRAMES INDEX
Applets
KavaChart includes a range of sample applets
that implement a majority of the chart package's functionality in applet
form. Along with basic charting functions, these applets also provide data
reading utilities, URL data polling functions, and image management functions.
Overview
KavaChart applets are organized into the javachart.applet
package. Individual applets provide the majority of KavaChart's chart package
functionality in applet form for use on Internet or Intranet web pages.
By convention, these applets are generally named javachart.applet.chartTypeApp.class.
Unlike other charting packages, KavaChart applets typically implement a
single chart type to reduce the applet "footprint" or download size. KavaChart
applets can be well under 50k in size.
In addition to basic charting, the applet
collection includes several "active" applets that implement scrolling,
zooming, drill-down, and other frequently requested features.
KavaChart applets share a parameter parsing
mechanism with KavaChart servlets to make it easy to translate your servlets
to applets, or vice-versa.
Installation
Install the applets by placing the necessary
"jar" files in an accessible location on your server. These jar files share
names with the applets they contain: lineApp.jar contains javachart.applet.lineApp.class
and all the class files necessary for lineApp to run. You can use the applet
CODEBASE tag to point to the location of your jar files, or you can name
it directly with your applet ARCHIVE tag. Here's an example of an applet
definiton:
<applet code=javachart.applet.lineApp archive=http://myserver/jars/lineApp.jar
width=500 height=300>
</applet>
Or, if you want to use the CODEBASE tag to
point to your jar files:
<applet code=javachart.applet.lineApp archive=lineApp.jar codebase=../../jars
width=500 height=300>
</applet>
Although you'll see a chart with this definition,
it isn't very interesting. For starters, it contains internally generated
data, and a default style. To improve the look of your chart, redefine
some applet parameters. Applets definitions can include a lengthy list
of parameters with this form:
<param name=parameterName value=parameterValue>
Each applet understands a set of general parameters
that are shared by all applets and servlets, and a set of parameters that
are specific to the chart type you're working with. For example, all applets
and servlets let you change the backgroundImage beneath the chart, but
only speedoApp lets you change the type of gauge from full to 1/4. In addition,
there are a few parameters shared by all the applets, but not relevant
to servlets, such as "networkInterval", which describes how frequently
the applet should check for new data.
Applet Parameters
All applets share a common set of applet parameters
for managing features that are useful to applets (and not useful for servlets).
These include the following:
Parameter |
value
type |
effect |
networkInterval |
Integer |
Applets that use URL datasets will check
for new data every networkInterval seconds. |
dwellLabelsOn |
true/false |
Tells the applet whether to use dwell
labels. |
dwellUseLabelString |
true/false |
Tells the applet whether to use each datapoint's
label as a part of the popup dwell labels. |
dwellUseXLabel |
true/false |
Tells the applet whether to use each datapoint's
X value as a part of the popup dwell labels. |
dwellUseYLabel |
true/false |
Tells the applet whether to use each datapoint's
Y value as a part of the popup dwell labels. |
dwellXString |
String |
A text string containing the character
"#" to add descriptive text to the dwell label X value. Example: "Category
#" |
dwellYString |
String |
A text string containing the character
"#" to add descriptive text to the dwell label Y value. Example: "Unit
Sales: $#" |
dwellLabelPrecision |
Integer |
Number of digits of precision for dwell
label values. For example, if precision is "2", labels will look like this:
123.45 or 123,45. |
Shared
Parameters
Other parameters are shared by all applets
and servlets. Most applets use any of the parameters
listed in KavaChart's ParameterParser document. If a parameter isn't
relevant to a particular applet, it will be ignored.
Unique Applet Parameters
Each applet has its own set of parameters
in addition to the shared parameter set. You can find links to individual
applet parameters here:
Area Charts
Bar and
Column Charts
Line Charts
Pie Charts
Speedo
and Polar Charts
Combination
Charts
Finance
Charts
Extending KavaChart
Applets
All KavaChart applets (except the purposely
trivial simpleApp.java) are extensions of ChartAppShell. This superclass
contains functionality common to all Chart
classes. ChartAppShell implements a simple interface, GetParam,
which requires implementations of simple parameter parsing and file I/O.
It also uses a ParameterParser
class to provide general functions for reading URLs, parsing parameter
strings, etc. ChartAppShell also reads its own parameters to manage dwell
labels and performs simple thread management to re-read URL data and ensure
that necessary chart images are available before drawing.
KavaChart applets are provided in source
code form for easy extension. In general, applet definitions and servlet
definitions are identical, except that applets extend javachart.applet.ChartAppShell,
and servlets extend javachart.servlet.ServletShell. Both servlets and applets
use ParameterParser
or one of its subclasses to interpret incoming parameters and apply them
to the chart.
ChartAppShell extensions work by overriding
the following methods:
init
overriding this method creates variant
instances of Chart subclasses.
Your init() method should start by calling the superclass initLocale()
method. This will initialize both the locale, including TimeZones for date
axes, as well as a default font. Next, generally, your init() will
initialized the variable chart to some Chart
subclass or ChartInterface.
Finally, call getOptions() which initializes a ParameterParser
class for use by this applet, and reads any required options from your
parameter list.
getMyOptions
this method gets properties for specific
applet types. You will see that similar applets have identical getMyOptions
methods. The superclass getOptions() method always calls getMyOptions()
to get information specific to your applet.
drawMyStuff
This method is called after other applet
painting and before dwell labels. To add custom drawing to an applet, simply
override drawMyStuff(Graphics) to add your graphic information.
ChartAppShell extensions:
lineApp.java
perhaps the most basic subclass, lineApp
just
defines the initial chart to be a LineChart.
labelLineApp.java
similar to lineApp, this applet overrides
the init method to create a new LabelLineChart.
regressApp.java
creates a new RegressChart
by overriding the init method. Note that installing a Regress
class by using the setLine method in LineChart
would have the same effect.
disLineApp.java
adds a single line to lineApp.java to
install a new DiscontinuousLine
in the place of LineChart's
original Line class. This applet
also overrides data handling to account for data discontinuities.
DateApp.java
An abstract subclass of ChartAppShell,
this superclass installs a subclass of ParameterParser
that adds features for managing dates and times. This subclass, DateStreamReader,
also has specific subclasses for reading variant data formats, like those
in hiLoCloseApp and finComboApp. All date-oriented applets are subclasses
of DateApp.
dateAreaApp.java
stickApp.java
creates StickChart
applet, using the Date parsing methods in DateApp.
finComboChart
creates a combination chart that incorporates
several elements: HLOC, Stick, and Line. This sample just creates an instance
of FinComboChart, and
shows only one of many ways to combine various chart elements. FinComboChart
uses the file parsing methods found in FinComboDateReader,
an extension of DateStreamReader.
hlocApp.java
creates an instance of HLOCChart using
the Date parsing methods found in HiLoCloseDateReader, an extension of
DateStreamReader.
areaApp.java
creates an instance of AreaChart
using superclass ChartAppShell to parse HTML arguments.
barApp.java
creates an instance of HorizBarChart,
and adds bar options with the getMyOptions method
barLineApp.java
creates an instance of BarLineChart,
a combination chart with Bar andLine
components. This applet adds bar options with the getMyOptions method,
and also adds a few arguments for allocating datasets between bar and line
elements.
indBarApp.java
indColumnApp.java
creates an instance of IndColumnChart.
This is identical to BarChart,
but uses the Bar class method drawInd
to draw bars using individual Datum
attributes rather than Dataset
attributes.
stackBarApp.java
default BarCharts
arrange bars into clusters. This applet creates an instance of StackBarChart,
which arranges bars into stacks, rather than clusters. Each bar in a stack
represents 1 Dataset in the
Chart's dataset array.
stackColumn.java
creates an instance of StackColumnChart,
which arranges bars into stacks, rather than clusters.
pieApp.java
creates an instance of a PieChart.
PieCharts graphically represent a single Dataset. This applet also adds
support for a variety of Pie options by overriding the method getMyOptions.
speedoApp.java
creates a gauge-style SpeedoChart.
This applet overrides the method getMyOptions to add support for a variety
of SpeedoChart options.
hSpeedoApp is a special case SpeedoChart
that creates an instance of a HistorySpeedoChart. This is identical to
a SpeedoChart, but uses the subclass HistorySpeedo,
which adds support for a historicalValue property. In a dynamic environment,
this tracks the largest value registered on a Speedo, and displays that
value with a swept arc, or "watermark".
polarApp.java
creates an instance of a PolarChart.
PolarCharts graphically represent a multiple Datasets by arranging y-values
in a radar style plot around a set of axes.
Interactive
Applets
KavaChart's standard applet set also includes
a number of applets that manage user interactions. These are
subclasses of the applet classes listed above, but override event handling
to add interactive behavior.
hyperBar.class
adds a parameter
to link URLs to bars, and "drills down" to a target browser window by clicking
on an active link.
hyperColumn.class
adds URL links to
columns.
hyperPie.class
adds URL links to
PieCharts.
scrollingLine.class
adds a scrollbar
at the bottom of a line chart to scroll through windows of data.
The default is 10 windows, adjustable by parameter.
scrollingDateLine.class
adds a scrollbar
at the bottom of a date line chart to scroll through windows of data.
The default is 10 windows, adjustable by parameter.
spinningPie.class
adds the ability
to rotate a pie by clicking and dragging.
zoomLine.class
adds the ability
to zoom in on line chart data by clicking and dragging.
Creating New KavaChart
Applets
You can easily build custom applets using
either the KavaChart chart package or the KavaChart beans classes. By building
your own applets, you may be able to shrink the footprint by eliminating
parameter and data parsing you don't require for your situation. You can
also put charts into a customized context with other information or add
user interactivity as required. All charting applets install a chart, and
override the applet paint method to draw a chart. Here's a quick
sample:
import java.applet.*;
import java.awt.Graphics;
import javachart.chart.*;
public class simpleApp extends Applet {
ChartInterface chart;
public void init () {
double yvals[] = new double[5];
for(int i=0;i<5;i++)
yvals[i] = Math.random();
chart = new BarChart();
chart.addDataset("my data", yvals);
}
public void paint(Graphics g) {
chart.resize(this.getSize().width, this.getSize().height);
chart.paint(this, g);
}
}
Our simple applet installs a BarChart in init()
and then draws the chart in paint. Other than that, we're just generating
some random numbers to draw. You'll presumably want real data.
Notice that in the chart paint method,
we're passing the applet itself as an argument. This lets the chart take
care of issues like rotating text as required, drawing flicker-free images,
and so on.
Since all our charts are subclasses of
the abstract Chart superclass, we can make a quick modification to our
applet to make it a bit more flexible:
public class flexibleApp extends Applet {
Chart chart;
public void init(){
double yvals[] = new double[5];
for(int i=0;i<5;i++)
yvals[i] = Math.random();
try{
Class chartClass = Class.forName("javachart.chart." + getParameter("chartType"));
chart = (Chart)(chartClass.newInstance());
chart.addDataset("my data", yvals);
}
catch(Exception e){ /* do nothing... */ };
}
public void paint(Graphics g) {
chart.resize(this.getSize().width, this.getSize().height);
chart.paint(this, g);
}
}
Now we can load any sort of chart we want
by passing a "chartType" parameter to our applet, like this:
<applet code=flexibleApp width=500 height=300>
<param name=chartType value=LineChart>
</applet>
Adding a Chart
Bean to Your Applet
Adding a chart bean to your applet is even
easier. Since chart beans are graphical components themselves, you can
just add them directly to your applet like this:
public class beanApplet extends Applet {
public void init() {
setLayout(new java.awt.BorderLayout());
add(new BarChart(), "Center");
}
}
Adding a Data
Feed to Your Applet
Of course, you'd probably want a real data
feed as well, but that's a simple matter of adding any of the existing
beans in javachart.beans.data, or creating your own extension to SimpleDataFeed.
For our purposes, we'll just add a DataFeedSimulator to see what this applet
might look like:
public class beanApplet extends Applet {
public void init() {
setLayout(new java.awt.BorderLayout());
ChartBean chart = new BarChart();
SimpleDataFeed dataFeed = new DataFeedSimulator();
dataFeed.addDataFeedListener(chart);
dataFeed.update();
add(chart, "Center");
}
}
The chart automatically paints, data automatically
updates on a specified thread, and the entire applet took only a few lines
of code to create. Similar to the example above, we could also select the
chart type at runtime, since all the chart beans are subclasses of ChartBean.
We could also use javachart.beans.chart.ChartWriter to create a serialized
version of our chart, making all the modifications interactively through
the customizer GUI. This serialized data could be used to re-create our
chart instance. Our chart instance can then be attached to whatever data
source we define in the applet. See the Cookbook
Chapter for more information on reading serialized chart data.
[Index]
[Introduction] [Installation]
[Cookbook] [Package]
[Component] [Chart]
[Axis] [Utility]
[Servlet] [Appndx
A] [Appndx B] [API]