GraPL > GraPL COM server > Sample scripts > Multiple series > Secondary axes
 

Handling Multiple Data Series

Using a secondary Y-axis

Sometimes it is convenient to compare two related data series which have been measured in completely different units. The example shows the sales of hamburger buns by a local bakery, compared with the average daily temperature in the area.

Secondary axes
' Initialise the data
 Col_Date = Array(35625,35626,35627,35628,...
 Col_Buns = Array(0,0,0,193,192,193,195,200,200,...
 Col_Temp = Array(19,18,16.5,18.5,17,15.5,...
 
 grapl.New 0,0,432,324
 grapl.FrameStyle = "Wiped,Boxed"
 grapl.Margins    = array(60,48,36,36)
 grapl.Heading    = "Weekly Bun Sales and;Mean Daily Temperature"
 grapl.MissingValue = 0
 grapl.Versus       = Col_Date
 grapl.Style        = "Line"
 grapl.Key          = array("Bun Sales","Mean Temperature")
 grapl.KeyStyle     = "Boxed"
 grapl.XStyle       = "date"
 grapl.XTickmarks   = 7
 grapl.YCaption     = "Sales (arbitrary units)"
 grapl.Linegraph Col_Buns
 
 grapl.YCaption = "Temperature (deg C)"
 grapl.YSec 
 
 grapl.Linegraph Col_Temp
 Response.Write grapl.RenderVML

The first plot is a simple timeseries, but note that the x-values are ‘ordinal’ dates, based on elapsed days since 1st Jan 1900 (compatible with Excel and easily calculated from the Oracle Julian date). The XStyle is set to ‘date’ to get the labels shown correctly, and the XTick interval is set to 7 to get weekly tickmarks. The only other thing to note is that the MissingValue is set to zero (the default value is 2^15 or 32768) to prevent plotting of values which are zero (missing data).

The crucial lines in the script are:

 grapl.YCaption = "Temperature (deg C)"
 grapl.YSec

The original Y-caption has already been used by the first Linegraph, so now we are OK to change it and call the YSec command which is a partial reset – it leaves all the X-axis settings in place but resets the Y-axis so that the next plot will once again set up the axis range and tick-mark spacing. It also switches the Y-axis style to ‘right’ automatically. Now when the script continues with:

 grapl.Linegraph Col_Temp

The chart has a completely new Y-axis with its own scale, caption and labelling. When the chart is closed with the final call to RenderVML the key is generated as normal, including both series. The other thing to note is that the default cycles for line colours and line styles are continued for the secondary axis as it is part of the same overall chart. This is not true for the next example where two independent charts share the same plotting space.

Back to TopOn to next section

© Copyright Causeway Graphical Systems Ltd 2000-2007
Telephone: +44 (0)1439 788413