VB ELF Web Data Service & Web Graphics

Because VB ELF is an OLE server component, it can easily be called by VB Script using the CreateObject function of the Server object. This means it's a snap to add English Language-to- SQL translations to any ASP-enabled Web page. (See our Configurations page for licensing requirements.)

Previous versions of VB ELF did not support graphics over the Web; however, we've filled that gap with this release. Rather than build Web graphs right into VB ELF itself, we've taken a different approach, one we think serves our customers better. Instead, we support but do not require the use of the Graphics Server (5.1) engine from Pinnacle Webworkz. VB ELF ships with the standard Pinnacle-BPS graphs that were included as part of Visual Basic, from VB 4 forward to VB 6. This is a wonderful graphing tool, and while not as flashy as the MS Chart component (also included), we think it makes for more illuminating charts in most situations. But neither of these graph products support server-side Web graphics.

For that, you need to use Graphics Server 5.1. While we're currently negotiating an OEM redistribution license with Pinnacle, adding the price of GS5.1 to our package would not make sense for those users who don't plan on Web graphics. Instead, we've worked out a way to support the GS component, without including it. A new translation response style (value=9) instructs VB ELF to translate the English question into a graph descriptor string. This is passed back to the caller (such as an ASP page running on the server) which can then use the descriptor to format a local copy of the GS graph object. VB ELF never actually references the graph object itself; it only provides the information necessary to format it properly as the answer to the given question.

The really nice part about this design is that we don't take all the fun of working with these graphs away from you. The graph descriptor will help you create a basic graph in a standard style. You can also preselect graph type (eg pie or bar) and graph style (horizontal, etc.) prior to making the the translation request; this is done simply by passing up a partially formatted descriptor to begin with.

But the Pinnacle graph object is a rich and varied component, and we don't try to get between you and all the expressive power that this tool can provide. Since you control the local copy of the GS graph, you can use any and all of the other formatting features. For instance, you can ensure that all your Web graphs have a common look, tailored to your company's requirements, by passing the graph through an additional formatter which handles exact details of tilt, rotation, alignment, axis plotting etc. VB ELF does only the basic job, and leaves the rest of the options up to you.



Specifics of Graph Descriptor use

We've kept this extremely simple because we know that many first-timers are getting their feet wet with VBScript programming.

The GraphDescriptor string returned by VB ELF consists of a series of tag/value pairs, or data elements, separated by semi-colons. A typical GraphDescriptor (like this one created in answer to the question How many employees are in each city?) could look like:
NumPoints;11;NumSets;1;1;1;1;1;1;4;1;1;2;1;1; Labels;;Auburn;Bellevue;Haguenau;Kent;Kirkland;London; Redmond;Schiltigheim;Seattle;Strasbourg;Tacoma;GraphType;4;GraphStyle;0;

To simplify parsing out the tags, each one is expected to have a following value; so for instance, the Labels tag, which doesn't require any additional value (we know there will be as many labels as NumPoints) is represented by "Labels;;". The tag/value pairs are not assumed to be in any order except that a) NumPoints must precede Labels and b) NumPoints must also precede NumSets. As soon as the NumSets value is read, the convention will be to immediately parse NumPoints * NumSets data elements from the string.

In the above example, we first read that there are 11 points in the graph, (NumPoints;11;) and that there is one row (NumSets;1). At this point we can expect the following 11 elements in the string to be the (11*1) data points to graph (1;1;1;1;1;4;1;1;2;1;1;). Next we read another tag/value pair (Labels;;) We'll then read the next NumPoints elements out of the string, interpreting them as labels for the axis (Auburn; Bellevue; Haguenau; Kent; Kirkland; London; Redmond; Schiltigheim; Seattle; Strasbourg; Tacoma). Continuing to read tag/value pairs until the end of the GraphDescriptor, we next find information on the graph type (GraphType;4;) and graph style (GraphStyle;0;). The values returned correspond to the style numbers used by Graphics Server 5.1. Of course, you could remap them to the styles used by any other graphics engine, or throw this information away and use whatever styles you like to draw the graph, since you (the ASP client) have control of the graph -- VB ELF never sees it at all!

Although this example does not use it, there's one additional tag, "Legends;;" which will be returned for graphs that have more than a single row. The immediately following N data items will be considered as text strings for use by the Legend property of the graph object, where N equals NumSets.

Here's a simple loop that will parse out tag/value pairs and values, and assign them into a Session variable which holds a Graphics Server graph object.

While (Len(gData)>0)
   result = GetPair(gData,descriptor,assignval)

   If descriptor="NumPoints" then
      Session("Graph1").NumPoints = assignval
   ElseIf descriptor="NumSets" then
      Session("Graph1").NumSets = assignval
      for j = 1 to Session("Graph1").NumPoints * Session("Graph1").NumSets
         R = j Mod Session("Graph1").NumSets
         C = (j + (Session("Graph1").NumSets-1)) \ Session("Graph1").NumSets
         Session("Graph1").ThisSet = R
         result = GetPoint(gData,assignval)
         Session("Graph1").Data(C) = assignval
      next
   ElseIf descriptor="Labels" then
      Session("Graph1").ThisSet = 1
      for C = 1 to Session("Graph1").NumPoints
         result = GetPoint(gData,assignval)
         Session("Graph1").Label(C) = assignval
      next
   ElseIf descriptor="Legends" then
      Session("Graph1").ThisSet = 1
      for R = 1 to Session("Graph1").NumSets
         result = GetPoint(gData,assignval)
         Session("Graph1").Legend(R) = assignval
      next
   ElseIf descriptor="GraphType" then
      Session("Graph1").GraphType = assignval
   ElseIf descriptor="GraphStyle" then
      Session("Graph1").GraphStyle = assignval
   End if
Wend

Function GetPair(text,descriptor,assignval)
Dim p, q
   i = 1
   p = InStr(i,text,";")
   if p > 0 then
      descriptor = Mid(text,i,p-1)
      i = p+1
      text = Mid(text,i)
      i = 1
      q = InStr(i,text,";")
      if q > 0 then
         assignval = Mid(text,i,q-1)
         i = q+1
         text = Mid(text,i)
      end if
   else
      text = ""
   end if
End Function

Function GetPoint(text,assignval)
Dim p, q
   i = 1
   p = InStr(i,text,";")
   if p > 0 then
      assignval = Mid(text,i,p-i)
      i = p+1
      text = Mid(text,i)
   else
      text = ""
   end if
End Function

To actually draw the graph into a Web page, you'd execute the DrawGraph() method of the graph object, receiving the file name back.

Session("MyFile") = Session("Graph1").DrawGraph()

Then you'd use an <img src ... > statement to display it, either hard-coding the width and height values, or as in the following example, reading them from Session variables which you've set earlier.

<img src="<% = Session("MyFile")%>.JPG" Width ="<% = Session("MyWidth")%>" Height ="<% = Session("MyHeight")%>" >




Last Updated: August, 2009