Heat Map Examples

Summary

This demo program illustrates how the JMSL Library can be used to develop Java™ applications that require data presented in a heat map graphic. There are three separate examples using different data and different visualization techniques. The data for this example come from a snapshot of the NASDAQ 100 on September 26, 2005, experimental results from a pharmaceutical company, and a roadside test conducted by the EPA in Colorado Springs.

Usage

The Finance, Biotech and Engineering tabs each have different interfaces to affect the heat map graph. For the Finance example, the contents may be arranged by Symbol or by Percent Change (ascending or descending) by using the JComboBox. The Biotech example has three different views of the same data set that can be selected using the JRadioButtons. Finally, the Engineering example has three different data sets and the ability to display a cross-section profile in a separate window.

Moving the mouse over any of the heatmaps will update summary information or the profile cross-section.

JMSL Library Math/Stat Classes

com.imsl.stat.Sort - this class is used in the Finance example to sort the data by Percent Change in either direction.

com.imsl.stat.Summary - extrema of the data values in the Engineering example are found using this class.

JMSL Library Charting Classes

com.imsl.chart.Heatmap - This class is the core class making up this set of examples. In each case, usage is very similar:

private void drawGraph() {
    Heatmap
heatmap = new Heatmap(axis, 0, xMax-1, 0, yMax-1, -12.0, 12.0, plotData, Colormap.RED);
    heatmap.getHeatmapLegend().setPaint(true);
    heatmap.getHeatmapLegend().setTextFormat("##");
    heatmap.getHeatmapLegend().setTitle("Value");
}

com.imsl.chart.Colormap - This interface is used to create custom colormaps for a heatmap. Consider the following colormap that runs from red through white to green used in the Finance example. The java.awt.Color(int rgb) constructor is used; refer to Sun's API for more details on this constructor.

private class RedGreenColormap implements com.imsl.chart.Colormap {
    int
[] c = new int[]
{16711680,16515072,16384000,16187392,16056320,15859712,15728640,15597568,15400960,15269888,15073280,14942208,14745600,14614528,14483456,14286848,14155776,13959168,13828096,13631488,13500416,13369344,13172736, 13041664,12845056,12713984,12582912,12386304,12255232,12058624,11927552,11730944,11599872,11468800,11272192,11141120,10944512,10813440,10616832,10485760,10354688,10158080,10027008,9830400,9699328,9568256, 9371648,9240576,9043968,8912896,8716288,8585216,8454144,8257536,8126464,7929856,7798784,7602176,7471104,7340032,7143424,7012352,6815744,6684672,6553600,6685443,6817543,7015179,7147279,7344915,7477015, 7609115,7806751,7938851,8136487,8268587,8466223,8598323,8730423,8928059,9060159,9257795,9389895,9587531,9719631,9851731,10049367,10181467,10379103,10511203,10643303,10840939,10973039,11170675,11302775, 11500411,11632511,11764611,11962247,12094347,12291983,12424083,12621719,12753819,12885919,13083555,13215655,13413291,13545391,13677491,13875127,14007227,14204863,14336963,14534599,14666699,14798799,14996435, 15128535,15326171,15458271,15655907,15788007,15920107,16117743,16249843,16447479,16579579,16777215,16514299,16251639,15988723,15726063,15463147,15200487,14937827,14674911,14412251,14149335,13886675,13623759, 13361099,13098439,12835523,12572863,12309947,12047287,11784371,11521711,11259051,10996135,10733475,10470559,10207899,9945239,9682323,9419663,9156747,8894087,8631171,8368511,8105851,7842935,7580275,7317359, 7054699,6791783,6529123,6266463,6003547,5740887,5477971,5215311,4952651,4689735,4427075,4164159,3901499,3638583,3375923,3113263,2850347,2587687,2324771,2062111,1799195,1536535,1273875,1010959,748299,485383, 222723,25600,26112,26624,27392,27904,28672,29184,29952,30464,31232,31744,32512,33024,33536,34304,34816,35584,36096,36864,37376,38144,38656,39424,39936,40704,41216,41728,42496,43008,43776,44288,45056,45568, 46336,46848,47616,48128,48896,49408,49920,50688,51200,51968,52480,53248,53760,54528,55040,55808,56320,57088,57600,58112,58880,59392,60160,60672,61440,61952,62720,63232,64000,64512,65280};
    public java.awt.Color color(double t) {
        int i = (int)(t*255);
        return
new java.awt.Color(c[i]);
    }
}

The class is then utilized in the Heatmap constructor by replacing a standard map like Colormap.RED above with new RedGreenColormap().

Java Code

Notice that the heat map in the Finance example has no axes -- no titles, no ticks, no labels. Turning off the axes is easily accomplished by setting their Paint attribute to false:

axis.getAxisX().setPaint(false);
axis.getAxisY().setPaint(false);

Link to Source Code

HeatmapMain.java This is the main class, and it extends JFrame. This small class instantiates a JTabbedPane and adds each of the JPanels below, which in turn implement MouseMotionListeners for their interface elements.
FPanel.java This class contains the charting and numerics for the finance example.
BPanel.java This class contains the charting and numerics for the biotech example.
EPanel.java This class contains the charting and numerics for the engineering example.

Running This Demo

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.