Overview

The JMSL chart package is designed to allow the creation of highly customizable charts using Java. A JMSL chart is created by assembling ChartNodes into a tree. This chart tree is then rendered to the screen or printer.

The following class is a simple example of the use of the JMSL chart package. The chart is displayed in a Swing JFrame. The code to create the chart is all in the constructor. The JMSL class JFrameChart extends the Swing class JFrame and creates a Chart object.

 

(Download Code)

 

import com.imsl.chart.*;

 

public class Intro1 extends JFrameChart {

   

    public Intro1() {

        Chart chart = getChart();

        AxisXY axis = new AxisXY(chart);

        double y[] = {4, 2, 3, 9};

        new Data(axis, y);

    }

   

    public static void main(String argv[]) {

        new Intro1().setVisible(true);

    }

}

 

 

The above example created and assembled three nodes into the following tree. The root Chart node is created by the JFrameChart class.

 

The general pattern of the ChartNode class, and classes derived from it, is to have constructors whose first argument is the parent ChartNode of the ChartNode being created. 

The root node of the tree is always a Chart object. It is usually constructed within JFrameChart or JPanelChart, which handles the repainting of the chart within Swing. If a Chart object is explicitly created, and used within a Swing GUI, then its paint(Graphics) method must be called from the container's paint(Graphics) or paintComponent(Graphics) method.

Chart nodes can contain attributes, such as FillColor and LineWidth. Attributes are inherited via the chart tree. For example, when a Data node is being painted, its LineWidth attribute determines the thickness of the line. If this attribute is set in the data node being drawn, that is the value used. If it is not set, then its parent node (an AxisXY node in the above example) is queried. If it is not set there, then its parent is queried. This continues until the root node is reached after which a default value is used. Note that this inheritance is not the same as Java class inheritance.

Attributes are set using setter methods, such as setLineWidth(double) and retrieved using getter methods, such as getLineWidth().



Visual Numerics - Developers of IMSL and PV-WAVE
http://www.vni.com/
PHONE: 713.784.3131
FAX:713.781.9260