JMSL Chart Programmer’s Guide
Contour Chart
A Contour chart shows level curves of a two-dimensional function.
Example
The JFrameChart class is used to create a frame containing a Chart node. A Contour node is then created as a child of the Chart node. The Contour node constructor creates ContourLevel nodes as its children. The number of ContourLevel nodes created is equal to the number of contour levels plue one, here equal to 4. After the ContourLevel nodes are created they are retrieved from the object pie and customized by setting attributes.
View code file
 
import com.imsl.chart.*;
import java.awt.Color;
 
public class SampleContour extends JFrameChart {
public SampleContour() {
Chart chart = getChart();
AxisXY axis = new AxisXY(chart);
double xGrid[] = {0, .2, .4, .6, .8, 1.0};
double yGrid[] = {0, .1, .2, .3, .4, .5, .6, .7, 1.};
double zData[][] = new double[xGrid.length][yGrid.length];
for (int i = 0; i < xGrid.length; i++) {
for (int j = 0; j < yGrid.length; j++) {
double x = xGrid[i];
double y = yGrid[j];
zData[i][j] = Math.exp(-x)*Math.cos(x-y);
}
}
double level[] = {.4, .6, .8};
Contour contour = new Contour(axis, xGrid, yGrid, zData, level);
contour.getContourLegend().setPaint(true);
contour.getContourLevel(0).setFillColor(Color.blue);
contour.getContourLevel(1).setFillColor(Color.yellow);
contour.getContourLevel(2).setFillColor(Color.green);
contour.getContourLevel(3).setFillColor(Color.red);
contour.getContourLevel(0).setLineColor("darkblue");
contour.getContourLevel(1).setLineColor(Color.orange);
contour.getContourLevel(2).setLineColor("darkgreen");
contour.getContourLevel(3).setLineColor("darkred");
}
public static void main(String argv[]) {
new SampleContour().setVisible(true);
}
}
The FillColor and LineColor attributes are set in each level. This determines the color of the fill area for the level and the color of the level curves. Since the default value of FillColor is black, it is generally recommended that FillColor be set in each level.
Each level corresponds to the area less than or equal to the contour level value and greater than the previous level, if any. So in this example, since the 0-th level value is 0.4, the area where the function is less than 0.4 is filled with blue (the level-0 fill color) and the level curve equal to 0.4 is drawn with dark blue, the level-0 line color.