ComponentOne WebChart 8.0 for ActiveX
HTML Tag Generation and Rendering the Chart to the Client

In WebChart ASP Pages, we discussed the method by which ComponentOne WebChart DTC generates the ASP script which creates and initializes the WebChart ASP run-time control. This section also mentions the GenerateTag routines found in the included files. Below is a copy and discussion of the routines in /WebChart8/include/vbs/2dgentag.inc. Please note that some of the lines have been wrapped to fit the page. Routines of similar function appear in:

/WebChart8/include/vbs/3dgentag.inc

/WebChart8/include/javas/2dgentag.inc

/WebChart8/include/javas/3dgentag.inc

Example Title
Copy Code
Function OlectraChart2D_AllocateTemporaryFile()
  Dim TFA

  If (IsEmpty(Session("TFA"))) Then
    ' Create a temporary file allocator.
    Set TFA = Server.CreateObject("C1Chart8.ASPTemporaryFileAllocator")
    TFA.VirtualDirectory = "/OCTemp/" & Hex(Session.SessionID) & Hex(Clng((Now() -10000) * 10000))
    TFA.CleanDirectory

    ' Store the temporary file allocator in the session object.
    Set Session("TFA") = TFA
  Else
    ' Re-use the existing temporary file allocator.
    Set TFA = Session("TFA")
  End If

  ' Allocate a temporary file.
  Set OlectraChart2D_AllocateTemporaryFile = TFA.Allocate()
End Function

The OlectraChart2D_AllocateTemporaryFile() is used to create an instance of the ASPTemporaryFileAllocator object. This object creates a directory for each session in the /OCTemp virtual directory, and places temporary files there for access by the client HTML. Note that after creating the object, the VirtualDirectory property is set to a unique value based upon the concatenation of the session id, and the time. After creation, the object is stored in the Session object. If the function is called multiple times from the same session, a new session object is not created.  Instead, the object stored in the Session object is used.

Finally, the routine calls the Allocate() method of the of the object, which provides a unique filename in the VirtualDirectory. This mechanism allows ComponentOne WebChart to create temporary files that can be referenced by the client. When the Session object destructs, it releases the ASPTemporaryFileAllocator object which also destructs. As it destructs, the ASPTemporaryFileAllocator object removes all the files and the directory associated with it. This prevents the build up of temporary files.

Special Notes:

The OlectraChart2D_GenerateTag_JPEG() subroutine is used to generate a JPEG rendering of the chart to be referenced by the client. The Chart object passed is the ComponentOne WebChart ASP run-time control. A call to OlectraChart2D_AllocateTemporaryFile() is made to obtain a unique filename. The allocator object Name property is then passed to the chart’s SaveImageAsJpeg() method.  The Name property is the full path to the allocated filename using the operating system file path rather than the ASP virtual path. This is necessary since the chart cannot understand the virtual path.

After rendering the chart image to a JPEG file in the /OCTemp directory, the Response.Write() method is used to generate HTML for the client to view the JPEG file. If it is necessary for a client side script to reference the image, the image id is set to the value of the anIdentifier argument passed in to the subroutine.

Example Title
Copy Code
Sub OlectraChart2D_GenerateTag_PNG(aChart, anIdentifier)
  ' Generate an HTML tag for a PNG image.
  Dim TF
  Set TF = OlectraChart2D_AllocateTemporaryFile()
  aChart.SaveImageAsPng TF.Name & ".PNG", True
  Response.Write("<IMG SRC=""" & TF.VirtualName & ".PNG"" ID=""" + anIdentifier + """ NAME=""" + anIdentifier + """>")
End Sub

The OlectraChart2D_GenerateTag_PNG() subroutine is used to generate a PNG rendering of the chart to be referenced by the client. The mechanism is identical to the one used by the OlectraChart2D_GenerateTag_JPEG routine described above.

Example Title
Copy Code
Sub OlectraChart2D_GenerateTag_Control(aChart, anIdentifier)
  ' Generate an HTML tag for an ActiveX control.
  Dim TF
  Set TF = OlectraChart2D_AllocateTemporaryFile()
  aChart.Save TF.Name & ".OC2"
  ' Invoke the License Manager to register the control
  Response.Write("<OBJECT CLASSID=""clsid:5220cb21-c88d-11cf-b347-00aa00a28331"">" & Chr(10))
  Response.Write("<PARAM NAME=""LPKPath"" value=""/WebChart8/CABs/olch2x8.lpk""> " & Chr(10))
  Response.Write("</OBJECT>" & Chr(10))
  Response.Write(Chr(10))
  ' Insert the chart and load the OC2 data file
  Response.Write("<object ID=""" & anIdentifier & """ ")
  Response.Write("WIDTH=""" & aChart.Width & """ HEIGHT=""" & aChart.Height & """ " & Chr(10))
  Response.Write("CLASSID=""CLSID:C819C5BF-6FBE-49AE-A60D-B57065E3101E"" " &
     Chr(10))
  Response.Write("CODEBASE=""/WebChart8/CABs/olch2x8.cab"">" & Chr(10))
  Response.Write("<PARAM NAME=""DataPath"" ")
  Response.Write("VALUE=""http://" & Request.ServerVariables("SERVER_NAME") & TF.VirtualName & ".OC2"">" & Chr(10))
  Response.Write("</object>" & Chr(10))
End Sub

The OlectraChart2D_GenerateTag_Control() subroutine is used to generate a WebChart data file to be referenced by the client. The mechanism is identical to the one used by the OlectraChart2D_GenerateTag_JPEG routine described above, but instead of generating an image file such as a JPEG, this routine uses the chart’s Save method to create a chart data file (properties and data) in the /OCTemp virtual directory.

Following the creation of a temporary OC2 file, the subroutine uses the Response.Write() method to create HTML which creates a client side LPK object, the client side ComponentOne Chart 8.0 2D object, and sets the DataPath property of the client side chart to the URL of the temporary OC2 file created. Thus a client side ComponentOne Chart 8.0 2D object is instantiated by the client browser and the data loaded from the temporary file.

Use of the OlectraChart2D_GenerateTag_Control() subroutine allows fully interactive charts on the client.

Example Title
Copy Code
Sub OlectraChart2D_GenerateTag_Image(aChart, anIdentifier)
  ' Virtually all browsers now handle PNG files.  So if an image
  ' is requested, use PNG as the quality is so much better.
  '
 
  ' Generate the appropriate HTML image tag based on the browser's capabilities.
  'Dim BC
  'Set BC = Server.CreateObject("MSWC.BrowserType")
  'If (BC.PNG = True) Then
    OlectraChart2D_GenerateTag_PNG aChart, anIdentifier
  'Else
  '  OlectraChart2D_GenerateTag_JPEG aChart, anIdentifier
  'End If
End Sub

In the previous WebChart version, the OlectraChart2D_GenerateTag_Image() routine created the Browser object, interrogated it for the client browser capabilities and responded by rendering the most appropriate image file. However, since virtually all browsers are now capable of rendering a PNG file, and PNG files are superior to JPEG files is virtually all respects, this routine now calls OlectraChart2D_GenerateTag_PNG() in all cases. If the original behavior is desired, you can remove the comments from the appropriate coded lines. However, please note that each browser listed in the Browscap.ini file installed by IIS / PWS must be adjusted to indicate PNG=True. By default, the Browscap.ini does not indicate PNG capability.

Example Title
Copy Code
Sub OlectraChart2D_GenerateTag(aChart, anIdentifier)
  ' Generate the appropriate HTML tag based on the browser's capabilities.
  Dim BC
  Set BC = Server.CreateObject("MSWC.BrowserType")
  If (BC.ActiveXControls = True) Then
    OlectraChart2D_GenerateTag_Control aChart, anIdentifier
  ElseIf (BC.PNG = True) Then
    OlectraChart2D_GenerateTag_PNG aChart, anIdentifier
  Else
    OlectraChart2D_GenerateTag_JPEG aChart, anIdentifier
  End If
End Sub

The OlectraChart2D_GenerateTag() subroutine also interrogates the client side browser capability. If the browser supports ActiveX Controls, then a client side control is created, otherwise a PNG or JPEG files is rendered. This is the default GenerateTag routine called by the ComponentOne WebChart DTC. For reasons discussed about in the description of OlectraChart2D_GenerateTag_Image(), it might be desirable to modify this routine to eliminate the JPEG option.

While the routines in 2DGENTAG.INC listed above are supplied with ComponentOne WebChart 8.0, they represent only one way of using the WebChart ASP run-time controls. While the DTC will call the OlectraChart2D_GenerateTag() subroutine by default, others can be called – others that you create. An explanation of why you might want to manipulate the WebChart ASP run-time control yourself, in a different way, is given in Runtime Only ASP Pages.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback