Handling Multiple Data Series
Two charts sharing one heading and key
The final example shows two charts which are completely independent, but come under a common heading and share one key. Of course either of these charts could plot more than one data series, or could have a secondary Y-axis GraPL will continue to accumulate the relevant details into your key until you explicitly flush it with a call to grapl.WriteKey.
' Initialise the data
Data_1 = Array(10,10,13,18,13,16,17,15,16,20,21,26)
Data_2 = Array("P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12")
Data_3 = Array(4,3,11,8,6,4,6,5,5,9,11,3)
The script begins by setting up the outer chart area (shaded in a 20% green to give a background wash fill to the entire chart) and then runs a Null chart which simply flushes out the heading. Then it creates each miniature chart in its own frame (within the bounding box of the initial area), finally it resets back to the outer frame to position the key.
grapl.New 0,0,432,324
grapl.FrameStyle = "Wiped,Boxed"
grapl.FrameAttribs = "Green,2,1.2"
grapl.Margins = array(42,48,36,18)
grapl.Heading = ";Testbed for;Intercept;Axes"
grapl.HeadingStyle = "Left"
grapl.Null
grapl.New 4,4,240,180
grapl.FrameStyle = "Wiped,Boxed"
grapl.Margins = array(12,12,12,12)
grapl.Style = "Lines,Markers"
grapl.LabelStyle = "Opaque"
grapl.XTickmarks = array(1,1)
grapl.YTickmarks = array(1,1)
grapl.XStyle = "Grid"
grapl.YStyle = "Grid"
grapl.XIntercept = 5
grapl.YIntercept = 15
grapl.Linegraph Data_1
grapl.NoteStyle = "Opaque"
grapl.Note "Y-int = 15;X-int = 5",6,12
grapl.New 200,140,424,316
grapl.FrameStyle = "Wiped,Boxed"
grapl.Margins = array(12,24,24,12)
grapl.Heading = " X-Axis Intercept; with labels set to 'Stay'"
grapl.HeadingStyle = "Left"
grapl.HeadingFont = "AR,11,Navy"
grapl.Style = "Redraw"
grapl.XStyle = "Notick,Stay"
grapl.XLabels = Data_2
grapl.YTickmarks = array(2,1)
grapl.YIntercept = 6
grapl.YRange = array(0,16)
grapl.Barchart Data_3
' Share common key
grapl.New 0,0,432,324
grapl.Key = array("First","Second")
grapl.KeyStyle = "Vertical,Boxed"
grapl.WriteKey 76,28
Response.Write grapl.RenderVML
This script illustrates a few more useful properties which have been helpful in customising the charts.
grapl.XTickmarks = array(1,1)
grapl.YTickmarks = array(1,1)
These lines set both the axes on the first chart to have major tickmarks one unit apart, with one minor tick between each. The LabelStyle is set to Opaque to get the labels to blank out the gridlines (set by the Grid style on both axes). The lines:
grapl.XIntercept = 5
grapl.YIntercept = 15
... force the axes to cross where we want them to. The XIntercept property sets a target point for the Y-axis and the Y-Intercept sets a similar target point for the X-axis. The second chart sets up a Y-intercept in a similar way to control where the X-axis is drawn. The final tweak to the second chart is the setting:
grapl.XStyle = "Notick,Stay"
By default, axis tickmarks and labels follow the axis, which in this case would result in a clash with the data (the bars would obscure several of the labels) so the tickmarks are turned off and the labels are made to stay where they were. Finally, the key text is set up and the key is drawn with:
grapl.New 0,0,432,324
grapl.Key = array("First","Second")
grapl.KeyStyle = "Vertical,Boxed"
grapl.WriteKey 76,28
Keys are positioned relative to chart axes when the chart is in a completely initialised state (or the first chart drawn was a piechart) the chart area has notional axes of 0-100 in both directions. These have been used here to position the key about 75% of the way across and 25% of the way up the chart area.
Summary
GraPL can generate composite charts with what is effectively a four-level hierarchy:
- A Chart (level zero and always present) may have one or more
- Frames each of which may have one or more
- Y-Axes each of which may have one or more
- Data series to be plotted.
The common case is just a Chart with one or more Data series, but the examples in this tutorial show how the various levels can be used in combination to give complete control over the final graphic.
|