Dynamic Chart Aspect Ratio

Summary

This demo illustrates how one can dynamically modify a chart's aspect ratio based on its data. The Sun Spots ARMA demonstration is used as a base. Research has found that visual perception of angular separation between line segments of a plot is maximized when the aspect ratio of the plot makes the average of the slopes of these line segments equal to 45 degrees [1, Sec4.7]. If we change the aspect ratio of the plot for the SunSpots demo accordingly, we are immediately confronted with an important aspect of the data that is obfuscated in the original: the rate of increase in sun spot occurrences is larger than the rate of decrease in sun spot occurrences, in any given sun spot cycle that is marked by a large increase in sun spot activity. Moreover, if the cycle begins with only a small increase in sun spot activity, then the decrease of activity is actually roughly symmetric with the increase.

Usage

Click the "Correct Aspect Ratio" button to dynamically resize and reposition the chart with an aspect ratio that fits the criteria discussed above. After correction, click "Reset Aspect Ratio" to return to the default size and position.

JMSL Library Charting Classes

This application utilizes the com.imsl.chart.Data object to generate a basic line chart. The data values are displayed as a result of methods setDataType(Data.DATA_TYPE_LINE | Data.DATA_TYPE_MARKER) and setMarkerType(Data.MARKER_TYPE_FILLED_CIRCLE). Several other methods, associated with this class, are used to further customize the chart.

Java Code

Modifying the aspect ratio is an iterative process. Consult the modifyAR() method of SunSpotAspect.java for the details of the code.

Link to Source Code

SunSpotAspect.java This is the main class for this demo. It extends JFrameChart to include a JButton as well as an ActionListener and a MouseMotionListener. The mouseMoved() method reports data coordinates in the chart.

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.

 


[1] William S. Cleveland. The Elements of Graphing Data. AT&T Bell Laboratories, Murray Hill, NJ, 1994.