Active Server Pages

You can embed a PopChart image into an Active Server Page (ASP) using the Component Object Model (COM) version of the PopChart Embedder.

For the most part, the code that you will use for embedding a PopChart image into an Active Server Page is exactly the same as the code you created for the JavaScript embedder in Chapter 4. This section will explain the major differences. Example 5.5 at the end of this section shows you how the web page from Example 4.7 would look as an Active Server Page.

Note: This documentation assumes that if you want to embed a PopChart image in an Active Server Page, you already know how to use them. If this is not the case, you may wish to brush up on Active Server Pages before continuing.

Installing the Component

Important: If you have re-installed PopChart Server since version 4.0.3, please ignore this step. The PopChart Embedder COM Component has been installed automatically for you.

Before you can use the PopChart Embedder in an Active Server Page, you must first make sure that the PCEmbedder.dll file, located in the dev_tools/COM_embedder folder, is installed as a component service. If you do not know how to install a component to your component services, refer to "Installing the COM PopChart Embedder as a Component Services" on page 5-53.

After you have installed PopChart Embedder to your server's component services, you don't need to do anything else to use the PopChart Embedder in an ASP.

Delimiting the Code For Your PopChart Image

You delimit code for your PopChart image with <% and %> (open angle bracket-percent sign, percent sign-closing angle bracket), as in the following code segment:

<%

myPopChart.appearanceFile = "apfiles/line.pcxml"

myPopChart.loadPCXML("http://myserver.com/?graph1")

%>

Instantiating a PopChart Embedder Object

To instantiate a PopChart Embedder object, you should use the following line of code (this assumes that you want to name your object myPopChart).

set myPopChart = Server.CreateObject("PopChart.Embedder")

Setting the Server Information

As mentioned in "Setting the Server Information" in Chapter 4, non-JavaScript versions of PopChart Embedder require you to tell them the location of PopChart Server. You need to set two values: the address that the web client will use to access PopChart Server ( externalServerAddress), and the address that PopChart Embedder uses to access PopChart Server ( internalCommPortAddress).

These are not the same addresses. First of all, PopChart Embedder uses a different port to communicate with PopChart Server. This port is known as the comm port, and, unless you change it, is set to 2002. Second of all, if you are using a firewall or a redirector, PopChart Server's address will be different for the web client than for the PopChart Embedder.

For example, if you are running PopChart Server at 10.0.1.1, but your web clients request images from http://popchart.mycompany.com, you need to include the following lines of code in the code that generates your PopChart image:

myPopChart.externalServerAddress = "http://popchart.mycompany.com:2001"

myPopChart.internalCommPortAddress = "10.0.1.1:2002"

Setting the User Agent

When you use the JavaScript PopChart Embedder, it automatically tells PopChart Server what the web client's user agent is. However, server-side PopChart Embedders can only tell PopChart Server a client's user agent if you specifically pass this information on to PopChart Embedder using the userAgent attribute. This information is significant because if PopChart Server knows what browser a client is using, it can return optimized (i.e. shorter and without JavaScript) HTML for embedding the PopChart image.

Server-side PopChart Embedders can only tell PopChart Server a client's user agent if you specifically pass this information on to PopChart Embedder using the userAgent attribute. The following line of code shows how to do this with in an ASP

myPopChart.userAgent = Request.ServerVariables("HTTP_USER_AGENT")

It is not necessary to tell PopChart Embedder the client's user agent; however, you will not be able to take advantage of optimized HTML if you do not do this.

Miscellaneous Differences

In addition to the afore-mentioned differences, you should be aware of the following issues when you use Active Server Pages.

Number of Parameters not Optional

Due to limitations in the Component Object Model, we are unable to set default values for any parameters in the COM PopChart Embedder. Because of this, any methods which normally have optional parameters will require those parameters in the COM PopChart Embedder.

At this time, the only two methods this effects are loadData(String,String,String,String) and addHTMLTable(String,String).

For loadData(), if you don't need to set the last two parameters, set the third argument to "replace" and the fourth argument to an empty string (e.g loadData("graph","prices.csv","replace","")).

For addHTMLTable(), simply give your table a title, or set the last argument to an empty string addHTMLTable("graph","").

No Semi-colons at the End of Lines

Note: This applies to Active Server Pages, not to the COM PopChart Embedder in General.

Active Server Pages use VBScript, whose syntax requires that you do not have a semi-colon at the end of a line of code. Since other languages either require a semi-colon, or are indifferent, most of the example code in this documentation uses a semi-colon at the end of each line of code. You should be careful to remove any semi-colons from example code if you use it in an ASP.

For example, this line of code is invalid in an ASP:

myPopChart.appearanceFile="bar.pcxml";

This line of code is valid:

myPopChart.appearanceFile="bar.pcxml"

No parenthesis Around Functions that Do Not Return Values

Note: This applies to Active Server Pages, not to the COM PopChart Embedder in General.

VBScript syntax also requires any functions that do not return a value (void methods) to not have parentheses around the parameters.

For example, we show the addHTMLTable() syntax to be:

myPopChart.addHTMLTable("graph","title");

This is perfectly valid in every language except VBScript. So in ASPs, you would need to use the following syntax:

myPopChart.addHTMLTable "graph", "title"

For most ASP developers this will be a very obvious conversion process.

Writing the image to Your Web Page

When you are ready to actually write your embedding HTML to the web page, you will need to output the getEmbeddingHTML() method to the ASP. To do this, use the Response.Write command, as shown below.

Response.Write myPopChart.getEmbeddingHTML()

Complete Example Code

The following Active Server Page will produce exactly the same results as the page you created in Chapter 4.

Example 5.5 Embedding a PopChart Image in an Active Server Page

<html> 

<head> 

   <title>My First Embedded PopChart</title> 

</head> 

<body> 

<h1>This is a PopChart Image</h1> 

<hr> 

 

<!-- insert PopChart image here --> 

<% 

   set myPopChart = Server.CreateObject("PopChart.Embedder") 

   myPopChart.externalServerAddress="localhost:2001" 

   myPopChart.internalCommPortAddress = "localhost:2002" 

   myPopChart.appearanceFile = "examples/apfiles/bar.pcxml" 

   myPopChart.imageType = "FLASH" 

   myPopChart.fallback = "STRICT" 

   myPopChart.width = 600 

   myPopChart.height = 400 

   myPopChart.pcScript = "title.setText(Hello World)" 

myPopChart.userAgent = Request.ServerVariables("HTTP_USER_AGENT") 

   Response.Write myPopChart.getEmbeddingHTML() 

%> 

 

<hr> 

<p>If you see an image above, congratulations. You have successfully embedded your first PopChart image.</p> 

</body> 

</html>