Topic: APLX Help : System Classes : The Chart and Series Objects : Axes, Coordinates and Scales
[ Previous | Next | Contents | Index | APL Home ]

Axes, Coordinates and Scales

Apart from Pie charts, all the different chart types plot a dependent variable (known as Y) against another variable (known as X). By convention, the X axis is along the horizontal, and the Y axis is along the vertical, except for Horizontal Bar and Stacked Horizontal Bar charts, where the two are reversed.

By default, the Chart Object will select the scale of the chart (i.e. the range from the minimum X and Y coordinates to the maximum X and Y coordinates) automatically. It will also automatically choose where to place tick marks and labels along the axes. There are two types of tick mark; major tick marks (which are by default labelled), and minor tick marks (which are not labelled). The major tick marks are slightly longer. The Chart object chooses the intervals between tick marks to give a reasonable number of ticks depending on the size of the chart, and will place the marks at intervals which mean that the labels are round numbers (multiples of 1, 2, 5 or 10 times integral powers of ten).

The Chart object will also choose the intercepts, i.e. the point where the axes cross each other. This will usually be 0 if 0 is within the scale, else the lowest X or Y point on the scale. This means that the Y axis is usually shown on the left of the chart, but you can change this by using an alternate Y scale (see below), and you can also cause the Y axis to be drawn on both sides of the chart using the style property.

For Bar and Stacked Bar charts (and the Horizontal versions of these), the bars are by default drawn centred on integers 1, 2, 3.. etc.

The Alternate Scale

As well as the main Y scale, you can also specify that an alternate Y scale is used for one or more of the series on the chart, by setting the usealtscale property of the Series object. The alternate Y scale is shown on the right side of the chart, and has its own scale, ticks, and intercept. This is useful if you are plotting two different types of quantity on the same chart, or if the ranges of numbers of two series are very different. For example, in this chart, the left axis refers to cigarette consumption, and the right scale to obesity:

[1]   ⍝ Sample line chart with two different scales
[2]   Health←'⎕' ⎕NEW 'Window' ⋄ Health.scale←5 ⋄ Health.size←450 600
[3]   Health.title←'Sample: Obesity and Tobacco'
[4]   Health.Chart.New 'Chart' ⋄ Health.Chart.align←¯1
[5]   Health.Chart.type←'line' ⋄←1
[6]   Health.Chart.title←'Tobacco Consumption and Obesity'
[7]   Health.Chart.subtitle←'United Kingdom'
[8]   ⎕IO←0
[9]   ⍝ Set up the data
[10]  obesity←1980 7 1991 14 1992 14 1993 15 1994 16 1995 16 1996 17
[11]  obesity←13 2⍴obesity,1997 18 1998 19 1999 20 2000 21 2001 22 2002 22
[12]  tobacco←1960 51.5 1970 49.5 1980 39 1990 30 1992 28
[13]  tobacco←10 2⍴tobacco,1994 27 1996 28 1998 27 2000 27 2001 27
[14]  Health.Chart.s1.New 'series'
[15]  Health.Chart.s1.marker←'⋄' ⋄ Health.Chart.s1.fillmarker←1
[16]  Health.Chart.s1.caption←'Tobacco consumption (left axis)'
[17]  Health.Chart.s1.values←tobacco
[18]  Health.Chart.s2.New 'series'
[19]  Health.Chart.s2.marker←'⋄' ⋄ Health.Chart.s2.fillmarker←1
[20]  Health.Chart.s2.caption←'Obesity (right axis)'
[21]  Health.Chart.s2.usealtscale 1
[22]  Health.Chart.s2.values←obesity
[23]  Health.Chart.yaxislabel←'% of population daily smokers'
[24]  Health.Chart.yaltaxislabel←'% of population with BMI>30 kg/m2'
[25]  Health.Chart.xmajorticks←1960 1970 1980 1990 2000
[26] ⍝
[27] ⍝ Wait until window is closed
[28]  0 0⍴⎕WE Health

Line [15] of this function causes the second series to be drawn using the alternate scale, which is unrelated to the main Y axis scale. The effect is as follows:

Specifying your own tick positions and intercepts

If you wish, you can choose your own positions for the tick marks along any of the axes. You specify the values where major tick marks should be drawn by writing a vector of values to the Chart properties xmajorticks, ymajorticks, or yaltmajorticks. (The previous chart shows an example of this on line [19].). Similarly, you can select where minor tick marks should be drawn by writing to the xminorticks, yminorticks, or yaltminorticks properties.

If you specify your own tick positions, the final scale chosen will normally be from the lowest tick mark you specify to the highest. However, the scale will be extended if any of the points in any enabled Series is outside this range, so that the scale can represent all points on all the series.

In addition, you can change where the axes cross by specifying the xintercept, xaltintercept, and yintercept properties.

Specifying your own tick labels

By default, the Chart object writes a label next to each major tick mark, showing the numeric value of the point on the axis. If you wish, you can specify your own labels using the properties xlabels, ylabels, or yaltlabels. You can write to these properties as a text matrix, carriage-return delimited text vector, or as a nested vector of character strings. However, except for bar charts and pie charts, your labels will be displayed only if you also specify the major tick positions along the same axis (this is because otherwise the chart object would not know where you want the labels).

There are two special cases. For Bar charts (including the stacked and horizontal variants), there is no need to specify the X tick positions, since the bars are always drawn at 1, 2, 3... For Pie charts, there are no tick positions as such, but the xlabels strings (if any) will be used to label each pie.

Specifying axis labels

The xaxislabel, yaxislabel and yaltaxislabel properties allow you to specify a label for the axis as a whole (such as '$ Millions' or 'Kg/m'). This is not the same as the tick labels, which label individual ticks along the axis.

Logarithmic Scales

Sometimes the range of data contained in a series is so large that a logarithmic scale is more appropriate. You can cause a logarithmic scale to be used for an axis by setting one of the xlogscale, ylogscale or yaltlogscale properties of the Chart to 1. (This works only if a logarithmic scale is valid, i.e. the values must all be greater than 0). For example, in the chart of the Microsoft financial results shown previously, the values for the early years do not show clearly because they are so tiny compared with the later values. A logarithmic scale shows the year-on-year growth in a more even fashion:


Note that, in this example, the minor ticks represent 2, 3, .. 9 times the power of ten shown at the previous major tick.

Topic: APLX Help : System Classes : The Chart and Series Objects : Axes, Coordinates and Scales
[ Previous | Next | Contents | Index | APL Home ]