This demo illustrates the ability to use the JMSL Library to easily create Java applications that allow visual data interaction and live statistical analysis. Upon selection of the points, a window displays statistics for both the set of chosen points and the set of points not chosen.
Use the mouse to select a subset of the points displayed on the chart. The selector can be placed into either a "Rectangle" or a "Polygon" mode, as indicated by the selector button.
com.imsl.stat.Covariances
- Specification
of the VARIANCE_COVARIANCE_MATRIX
integer constant as the argument
for method compute()
results in a calculation and display of the
variance-covariance matrix for the selected data: double
covar[][]
= co.compute(Covariances.VARIANCE_COVARIANCE_MATRIX);
com.imsl.stat.NormTwoSample
- Various statistics
for mean and variance inferences are calculated using NormTwoSample()
method: reportValue(ps,
"T default", nts.getTTestDF());
com.imsl.math.PrintMatrixFormat
- A PrintMatrixFormat
method is used to set the numerical format for the upper triangular variance-covariance matrix output:
pmf.setNumberFormat(nf);
com.imsl.math.PrintMatrix
- After defining the PrintMatrix
object as an upper triangular matrix (pm.setMatrixType(PrintMatrix.UPPER_TRIANGULAR)
) an nRow by nColumn matrix with specified format for HTML is output: pm.printHTML(pmf, covar, 2, 2);
This application utilizes two com.imsl.chart.Data
objects to generate a scatter chart. The selected data are assigned to one object while the unselected data belongs to another. Each object is assigned a unique symbol and color using the methods: dataSelected.setMarkerColor("blue");
dataSelected.setMarkerType(Data.MARKER_TYPE_FILLED_CIRCLE); dataNotSelected.setMarkerColor("red");
dataNotSelected.setMarkerType(Data.MARKER_TYPE_HOLLOW_SQUARE);
The selection of points in this demo is accomplished
by identifying data that fall within the area of a rectangle or polygon of n
sides.
Identification of the appropriate polygon occurs when the left mouse button is pressed until it is released. A Selector
inner class (or SelectorPolygon
subclass) contain the methods for updating the display and adding points to the polygon (if this is selected).
Rectangle
void start(MouseEvent mouseEvent) {
xA = xB = mouseEvent.getX();
yA = yB = mouseEvent.getY();
}
protected void updateShape(MouseEvent mouseEvent) {
xB = mouseEvent.getX();
yB = mouseEvent.getY();
}
Polygon
void start(MouseEvent mouseEvent) {
super.start(mouseEvent);
polygon = new Polygon();
polygon.addPoint(xA, yA);
}
protected void updateShape(MouseEvent mouseEvent) {
polygon.addPoint(mouseEvent.getX(), mouseEvent.getY());
}
Once the mouse button is released, an appropriate implementation
of the Shape
interface and method contains()
is called
to identify the data within the specified area:
private void select(Shape shape) {
...
for (int k = 0; k < x.length; k++) {
axis.mapUserToDevice(x[k], y[k], dev);
if (shape != null && shape.contains(dev[0], dev[1])) {
xSelected[iSelected] = x[k];
ySelected[iSelected++] = y[k];
} else {
xNotSelected[iNotSelected] = x[k];
yNotSelected[iNotSelected++] = y[k];
}
}
...
}
Pick.java | This is the main class for this demo. It extends JFrameChart to include two JButtons and implements MouseListener. Instantiation of this class also results in the creation of both a Selector and SelectorPolygon object. These objects contain all of the methods that are necessary to render the objects and identify data within the object's area. |
Two alternatives are available to run this demo:
1) Use the source code in your development environment as any other Java code. More information is available in the How To.
2) An executable jar file containing all of the demos
referenced in this guide is included in the jmsl/lib directory. On
Windows, you may double-click the file to run it if files with a ".jar"
extension are properly registered with javaw.exe. Alternatively,
for both Windows and UNIX environments, the jar file may be executed from the
command line using java -jar gallery.jar
.
As list of buttons, one for each demo, is created. Demos can be subsetted as they relate to specific areas (Math, Stat, Finance, Charting) by choosing the appropriate selection on the JComboBox. To run the Additional Demos, select Quick Start in the JComboBox.