Worked Example Middle East Oil
A regular exercise for the GraPL.NET developers is to read through the morning papers looking for interesting chart designs, and making sure the product can cope. The original of this chart appeared in the Guardian newspaper in late 2000, and posed some interesting challenges:
Basically it is a horizontal bargraph, but some of the design details are quite subtle. Also there is the challenge of overlaying a simple piechart at the correct spot on the main chart. We will build up the ASP script to generate the completed chart in easy stages, making sure that at every stage we have a fully functional chart to look at in the browser.
The simplest thing that could possibly work
The first stage is to enter the data for the various countries, create a GraPL server and make a default barchart. Here is a minimal ASP script to create the chart and render the result as VML to the browser:
<html>
<%@ LANGUAGE=VBScript
ENABLESESSIONSTATE=False%>
<%
Set grapl = Server.CreateObject("grapl.engine") ' Connect
Response.Write grapl.VMLHeader ' Generate the VML Header
%>
<head><title>GraPL.NET - Oil1</title></head>
<body>
<%
' Initialise the data
Col_Barrels = Array(560,715,910,2025,2505,2580,2550,8595)
' First stage in making the Oil chart
grapl.New 0,0,432,324
grapl.FrameStyle = "Wiped"
grapl.Barchart Col_Barrels
Response.Write grapl.RenderVML
%>
</body></html>
The result is very plain, but at least we know that the engine is running! Here is what it looks like in the browser as VML:
To explain the entries in the script ....
Set grapl = Server.CreateObject("grapl.engine") ' Connect
Response.Write grapl.VMLHeader ' Generate the VML Header
Having created our server object (which is conventionally called grapl in all the examples) we must first ensure that the page has the VML namespace correctly declared. grapl.VMLHeader simply returns the necessary text.
' Initialise the data
Col_Barrels = Array(560,715,910,2025,2505,2580,2550,8595)
All the plotting methods offered by GraPL take variants. In this case we will be passing a simple array of integers.
' First stage in making the Oil chart
grapl.New 0,0,432,324
grapl.FrameStyle = "Wiped"
grapl.Barchart Col_Barrels
The first line declares that the entire chart requires a rectangle 432 points wide by 324 points high actually this is the default shape and we could have omitted this line entirely! The origin of the chart is the lower left-hand corner (all co-ordinates in GraPL use the cartesian system, with the origin at the lower left) this is the common case but later on we will see why you sometimes need to change it. We then tell GraPL to wipe the entire frame (it will fall through to the background colour in the browser otherwise) and then we draw the data using the Barchart command.
Response.Write grapl.RenderVML
The final line in the script ends the chart-creation process and returns the description of the entire chart as a set of VML tags. This is written into the output stream as text, and the rest of the page can be finished off as normal.
Now lets turn it around!
From now on, only the changes will be shown. This declares an additional array to hold the country names, adjusts the chart margins to make some room on the left, and draws a horizontal chart with the country names as labels:
' Initialise the data
Col_Country = Array("Syria","Qatar",...,"Saudi Arabia")
Col_Barrels = Array(560,715,910,2025,2505,2580,2550,8595)
' Switch to a horizontal bar and adjust margins
grapl.New 0,0,432,324
grapl.FrameStyle = "Wiped"
grapl.Margins = array(42,36,80,36)
grapl.Style = "Forcezero,Horizontal,Redraw"
grapl.YLabels = Col_Country
grapl.Barchart Col_Barrels
Response.Write grapl.RenderVML
It is beginning to take shape now ...
... but we need to do some serious design work on the typefaces, as well as add the values as labels on the bars.
|