GraPL > GraPL COM server > Sample scripts > Middle East Oil > Adding a piechart
 

Worked Example – Middle East Oil

Superimposing the piechart

We now need to drop a new chart frame roughly in the middle of the existing area, and set up the piechart inside it. After a little experimentation, a reasonable layout seems to be:

' Initialise the data
 Col_Region = Array("Rest of;the world","Middle;East")
 Col_Percentage = Array(69.5,30.5)
' Blocking out the Piechart
 grapl.New 220,60,380,220
 grapl.FrameStyle = "boxed,wiped"
 grapl.Margins    = array(12,12,12,20)
 grapl.Colours  = "#37757B,#A7322C"
 grapl.XLabels = Col_Region
 grapl.Pie Col_Percentage
 
 Response.Write grapl.RenderVML
Oilchart with pie

I have intentionally left the frame ‘boxed’ here as it makes it easier to see where it is. Note that the margins have been greatly reduced and the ‘Xlabels’ property has been used to set the spider tags on the pie. Note that you can use semi-colons in almost all the text elements in GraPL to force line-breaks.

Finishing off

It only remains to set the correct font on the pie labels, and remove the unwanted frame. Here is the finished chart again, and the complete script which generates it:

Oilchart with pie
' Initialise the data
 Col_Country  = Array("Syria","Qatar","Oman", ... ,"Saudi Arabia")
 Col_Barrels  = Array(560,715,910,2025,2505,2580,2550,8595)
 Col_Region   = Array("Rest of;the world","Middle;East")
 Col_Percentage = Array(69.5,30.5)
 
' The completed composite chart
 grapl.New 0,0,432,324
 grapl.FrameStyle = "Wiped"
 grapl.Margins    = array(42,36,80,36)
 grapl.Colours  = "#A7322C"
 grapl.Patterns = "Solid"
 grapl.Style         = "Forcezero,Horizontal,Values,Redraw"
 grapl.YStyle        = "Gridlines,Notick,Between,Labmid"
 grapl.XStyle        = "NoAxis"
 grapl.Gap           = 0.3
 grapl.Axes          = "Black,Invisible,1"
 grapl.YLabels       = Col_Country
 grapl.LabelFont     = "AR,11,Black"
 grapl.ValueFont     = "ARB,12,Black"
 grapl.ValueFormat   = "#,##0"
 grapl.ValueStyle    = "Inside,Transparent"
 grapl.Heading       = "Middle East Oil Production"
 grapl.HeadingFont   = "ARB,18,Black"
 grapl.HeadingStyle  = "Left"
 grapl.Subhead       = "Production, 1000s of Barrels/day"
 grapl.SubheadFont   = "AR,12,Black"
 grapl.Footnote      = "Source BP (1999 figures)"
 grapl.FootnoteStyle = "Right,Ruled"
 grapl.FootnoteFont  = "AR,12,Black"
 grapl.Barchart Col_Barrels
 
 grapl.New 220,60,380,220
 grapl.FrameStyle = "wiped"
 grapl.Margins    = array(12,12,12,20)
 grapl.Colours  = "#37757B,#A7322C"
 grapl.Heading     = "Total world production"
 grapl.HeadingFont = "ARB,12,Black"
 grapl.XLabels     = Col_Region
 grapl.LabelFont   = "AR,9,Black"
 grapl.Pie Col_Percentage
 
 Response.Write grapl.RenderVML

Summary

This should give you a good feel for the way you construct a complex chart stage by stage. GraPL is effectively a ‘state machine’ so you set up all the properties you need before you call the plotting method which uses them. Once a property is set, it stays set until you call grapl.New which clears everything back to the default values. You can keep on adding data series to existing axes, or completely new charts, until you are ready to return the completed design to the output stream.

Fully-working copies of all the intermediate stages (and the final chart) are included in the samples directory of your GraPL.NET installation.

On to next topicBack to Top

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