5.5.1 AxisMapper

There can be many different data types which must be plotted: dates, numbers, lists, etc. For the charting package to work with different type coordinate systems, they have to be mapped to some universal coordinate system. Therefore, double values in range [0, 1] are used as the UCS coordinates throughout the entire charting package. 0 corresponds to the minimum value of the coordinate axis, while 1 corresponds to the maximum value.

AxisMapper interface is used to map coordinate values of some specific type to the [0, 1] range of double values. There are several predefined axis mapper classes:

Class Short Description
DateAxisMapperThis is analogue mapper, which maps date ranges.
DateListAxisMapperThis mapper holds date list. All dates are mapped sequentially and spaced equally.
LabelAxisMapperThis mapper maintains a sequence of keys (labels) and maps the same key instances according to their index (position) in the sequence.
MathAxisMapperThis mapper maps numbers (instances of Number class, such as Double, Integer, etc.). The exact minimum and maximum values have to be specified for the mapping to work correctly.
LogAxisMapper This mapper is used for logarithmic scaling. It allows axis to be subdivided logarithmically.
NullAxisMapper This mapper is Dummy Axis mapper, which just passes through all numeric values.
RadarMapper This mapper maps the polar values the polar point

Table 5.5.1.1 Axis Mappers

DateAxisMapper and DateListAxisMapper

These mappers are used for mapping dates. The main difference between them is that DateAxisMapper is analogue and holds a range of dates, and DateListAxisMapper maps a list of fixed number of dates.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//setting Calendar
Calendar c = Calendar.getInstance();
//setting dates
Date dates[] = new Date[20];
		int j = 1995;
		for (int i = 0; i < dates.length; i++)
		{
			c.clear();
			c.set(Calendar.YEAR, j);
			dates[i] = c.getTime();
			j += 5;
		}
//setting DateAxisMapper
DateAxisMapper mapper1 = new DateAxisMapper(dates[0],dates[19]);
//setting DateListAxisMapper
DateListAxisMapper mapper2 = new DateListAxisMapper(dates);
DateFormats

When using SimpleDateFormat, be sure to follow these regulations for the date format pattern:

Setting various date formats:

 
DateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss:SSS");

This code, would return:

2008.04.10 02:12:13:286

 
DateFormat df = new SimpleDateFormat("yy.MM.dd");

This code, would return:

08.04.10

 
DateFormat df = new SimpleDateFormat("HH:mm:ss");

This code, would return:

02:12:13

Note. If a PC is set to use one time zone but user wants the chart to display another, that other time zone has to be set for DateAxisMapper. This is done by using setTimeone(TimeZone zone) method. Time zone object can be created in several ways, e.g.:

 
TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
TimeZone zone = TimeZone.getTimeZone("GMT-8"); 
TimeZone zone = TimeZone.getTimeZone("UTC");

Setting TimeZone:

 
DateAxisMapper mapper = new DateAxisMapper(); //setting mapper
mapper.setTimeZone(TimeZone.getTimeZone("UTC")); //setting TimeZone