About the PopChart Embedder

One of the PopChart Server's best features is that the images it generates can be embedded into a web page using HTML—a technology so simple that pretty much any graphically based browser can display PopChart images. No special plug-ins or applets are required.

Of course, having just embedded a PopChart image in the previous chapter using JavaScript, a more savvy web programmer might dispute our claim to be based entirely on HTML. However, all that the JavaScript PopChart Embedder did was generate the appropriate HTML to embed your PopChart image.

For example, we could have generated the PopChart image from Example 4.7 using the following HTML:

Example 5.1 HTML Code for Embedding a PopChart Image

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" border="0" width="600" height="400" > 

<param name="MOVIE" value="http://localhost:2001/?@_FILEexamples/apfiles/bar.pcxml@_HEIGHT400@_WIDTH600@_PCSCRIPTtitle.setText(Hello%20World)@_FLASH"> 

<img width="600" height="400" src="http://localhost:2001/?@_FILEexamples/apfiles/bar.pcxml@_HEIGHT400@_WIDTH600@_PCSCRIPTtitle.setText(Hello%20World)@_GIF"> 

</object>

After sitting down for a minute or two and trying to decipher this code, most programmers will agree that the code from JavaScript PopChart Embedder is a lot more straightforward and manageable. In case you are not convinced, quickly glance through some of the example code in Chapter 11, "Getting PopChart Images with HTTP Requests," which teaches you how to embed PopChart images using straight HTML.

Writing and maintaining such code can be very tedious and confusing. That's why we created the PopChart Embedder to generate this code for you. All you have to do is create a PopChart Embedder object, set a few attributes, and then call the getEmbeddingHTML() method. The getEmbeddingHTML() method then "compiles" your PopChart and returns the code necessary to request an image of the PopChart from PopChart Server.

Note: It is not entirely accurate to say that the JavaScript Embedder translates the code from Example 4.7 to the HTML in Example 5.1. For more information, refer to "How Does it Work?".

PopChart Embedder on the Server-Side

While the JavaScript PopChart Embedder works on the client-side to generate embedding HTML, most web developers generate their web pages dynamically on the server-side, especially when they publish live data from a database. In these circumstances, it makes much more sense to use a server-side version of the PopChart Embedder.

The server-side version of PopChart Embedder is available in the following formats: Java, JavaBean, and COM (Component Object Model). It can be used in a variety of environments, including Java Server Pages, Active Server Pages, Java Servlets, and ColdFusion.

Note: The Java and JavaBean versions of PopChart Embedder are only available in PopChart Server Pro and PopChart Server Enterprise.

By providing you with a native interface for embedding PopChart images, the PopChart Embedder helps separate content from presentation. You don't have to worry about HTML code, because the PopChart Embedder does this for you. Beyond that, using the PopChart Embedder on the server-side provides additional flexibility, such as importing from a database and adding HTML Tables.

Example 5.9 illustrates how embedding images with a server-side version of the PopChart Embedder typically works.

This process can be broken down into the following steps:

1. The Web Application Server (or PopChart Embedder) retrieves data from the database.

2. Using the PopChart Embedder, the Web Application Server sends data and other instructions to PopChart Server.

3. PopChart Server stores the data and instructions and sends back the HTML necessary to embed a PopChart image. This HTML consists of an <object>, <embed>, or <img> tag whose URL source instructs the browser to get a specific reference (key) from PopChart Server.

4. The Web Application Server builds an HTML page that, integrating the HTML that PopChart Server returned, embeds the PopChart image.

5. The HTML page is served to the web client (browser).

6. Seeing the appropriate tag in the HTML page, the browser requests an image from PopChart Server.

7. PopChart Server uses the reference (key) from the browser's request to look up the stored data and instructions and create a PopChart image. This image is then returned to the browser.

8. The browser displays the PopChart image.