JMSL Chart Programmer’s Guide
Axis Label
The AxisLabel node controls the labeling of an axis. The drawing of this node is controlled by Text Attributes.
Scientific Notation
If the values along an axis are large, scientific notation is more readable than a decimal format with many zeros. In this example the y-axis is labeled with scientific notation where each number has exactly two fractional digits displayed. This format pattern is "0.00E0". See DecimalFormat for details on number formatting patterns.
Date Labels
If the TextFormat attribute for an axis is an instance of DateFormat, then the axis is scaled and labeled as a date/time axis, instead of as a real axis.
Date information passed to the Date constructor must be a double number representing the number of milliseconds since the standard base time known as “the epoch”, namely January 1, 1970, 00:00:00 GMT. This is used by the constructor for Date.
Skipping Weekends
An additional feature of Date axes is the ability to skip weekends. This feature is often needed for charting stock price data.
To skip weekends it is necessary to adjust the autoscaling for weekdays-only. This is done by setting the attribute SkipWeekends to true. It is also necessary to set a custom transformation, TransformDate, on the axis.
View code file
import com.imsl.chart.*;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
public class SampleWeekend extends JFrameChart {
public SampleWeekend() {
Chart chart = getChart();
AxisXY axis = new AxisXY(chart);
Axis1D axisX = axis.getAxisX();
axisX.getAxisLabel().setTextFormat(new SimpleDateFormat("EEE MM/d/yy"));
// Skip weekends
axisX.setCustomTransform(new TransformDate());
GregorianCalendar t[] = {
new GregorianCalendar(2001, GregorianCalendar.OCTOBER, 10),
new GregorianCalendar(2001, GregorianCalendar.OCTOBER, 11),
new GregorianCalendar(2001, GregorianCalendar.OCTOBER, 12),
new GregorianCalendar(2001, GregorianCalendar.OCTOBER, 15),
new GregorianCalendar(2001, GregorianCalendar.OCTOBER, 16)
double x[] = new double[5];
for (int k = 0; k < x.length; k++) x[k] = t[k].getTime().getTime();
double y[] = {4, 2, 3, 9, 2};
Data data = new Data(axis, x, y);
axis.setViewport(0.2, 0.9, 0.1, 0.7);
public static void main(String argv[]) {
new SampleWeekend().setVisible(true);
Skipping weekends is intended only for data sets where no weekend data exists. It will not give the expected results if the data set contains weekend data.
String Labels
Any array of strings can be used to label the tick marks using the setLabels(String[]) method. The setLabels(String[]) method sets the Number attribute to the number of strings.