ColdFusion application servers can use either the Java PopChart Embedder or the COM PopChart Embedder. In both cases, the code looks almost exactly alike, and is very similar to the code you created for the JavaScript embedder in Chapter 4. This section will explain the major differences. Example 5.9 and Example 5.10 at the end of this section show you how the web page from Example 4.7 would look as a ColdFusion Page.
Important: ColdFusion MX currently does not allow access to the component object model. This is apparantly a bug in ColdFusion MX. Because of it, the COM version of the PopChart Embedder will not work with ColdFusion MX. You should use the Java version instead.
Note: This documentation assumes that if you want to embed a PopChart image in an ColdFusion Page, you already know how to use ColdFusion. If this is not the case, you may wish to brush up on ColdFusion before continuing.
The instructions for installing the PopChart Embedder differ according to which version you use.
Just as you have to put the PopChartEmbedder.jar file, located in the dev_tools/java_embedder folder, in the classpath of a Java Application Server, you also need to put it in the classpath for ColdFusion. If you do not know how to add a Jar file to your ColdFusion's classpath, refer to "Including the PopChartEmbedder.jar File in Your Classpath" on page 5-46.
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 a ColdFusion 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.
To instantiate a PopChart Embedder object on ColdFusion, you should use the <cfobject> tag. You should set the name attribute of this tag to the name of your PopChart Embedder object (e.g. myPopChart) and the action attribute to Create.
The values of the other attributes of this tag will depend upon the version of PopChart Embedder that you use.
Set the type attribute to Java and the class attribute to com.corda.pcis.PopChartEmbedder.
<cfobject type="Java" action="Create" name="myPopChart" class="com.corda.pcis.PopChartEmbedder">
Set the type attribute to COM and the class attribute to PopChart.Embedder.
<cfobject type="COM" action="Create" name="myPopChart" Class="PopChart.Embedder">
Note: You do not need to close the cfobject tag (i.e. do not use a </cfobject> tag).
Except for instantiating the PopChart Embedder object and writing the embedding HTML to the web page, all PopChart Embedder code should go inside of a <cfscript> tag, as in the following code segment:
myPopChart.appearanceFile = "apfiles/line.pcxml";
myPopChart.loadPCXML("http://myserver.com/?graph1");
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";
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 in a ColdFusion page.
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.
Although almost all of the code looks the same in ColdFusion for the Java and COM versions of PopChart Embedder, remember that code that uses the Java PopChart Embedder will act like Java code, while code that uses the COM PopChart Embedder will act like COM code.
This means that if you use PopChart Embedder methods that act differently in the Java and COM versions (e.g. setDBQuery()), you need to be sure to use the correct syntax. If you add additional code, be sure that it conforms to the syntax of the language you have chosen. Also, please consult "Miscellaneous Differences" in Chapter 5 for additional information about using the COM PopChart Embedder.
When you are ready to actually write your embedding HTML to the ColdFusion page, you will need to output the getEmbeddingHTML() method. To do this, use the <cfoutput> tag, as shown below. Be sure to put pound signs before and after the myPopChart.getEmbeddingHTML() statement.
#myPopChart.getEmbeddingHTML()#
The following ColdFusion page uses the Java PopChart Embedder to produce exactly the same results as the page you created in Chapter 4.
Example 5.9 Embedding a PopChart Image with ColdFusion (Java)
<title>My First Embedded PopChart</title>
<h1>This is a PopChart Image</h1>
<!-- insert PopChart image here -->
<cfobject TYPE="Java" ACTION="Create" CLASS="com.corda.pcis.PopChartEmbedder" NAME="myPopChart">
myPopChart.externalServerAddress="localhost:2001";
myPopChart.internalCommPortAddress = "localhost:2002";
myPopChart.appearanceFile = "examples/apfiles/bar.pcxml";
myPopChart.imageType = "FLASH";
myPopChart.fallback = "STRICT";
myPopChart.pcScript = "title.setText(Hello World)";
myPopChart.userAgent = CGI.HTTP_USER_AGENT;
#myPopChart.getEmbeddingHTML()#
<p>If you see an image above, congratulations. You have successfully embedded your first PopChart image.</p>
This last ColdFusion Page uses the COM PopChart Embedder to produce the same results.
Example 5.10 Embedding a PopChart Image with ColdFusion (COM)
<title>My First Embedded PopChart</title>
<h1>This is a PopChart Image</h1>
<!-- insert PopChart image here -->
<cfobject type="COM" action="Create" name="myPopChart" Class="PopChart.Embedder">
myPopChart.externalServerAddress="localhost:2001";
myPopChart.internalCommPortAddress = "localhost:2002";
myPopChart.appearanceFile = "examples/apfiles/bar.pcxml";
myPopChart.imageType = "FLASH";
myPopChart.fallback = "STRICT";
myPopChart.pcScript = "title.setText(Hello World)";
myPopChart.userAgent = CGI.HTTP_USER_AGENT;
#myPopChart.getEmbeddingHTML()#
<p>If you see an image above, congratulations. You have successfully embedded your first PopChart image.</p>