JavaScript

The JavaScript PopChart Embedder is new to PopChart Server 4.0. It provides you with a convenient interface for embedding PopChart images directly into your web page, without the use of a web application server.

All you have to do is load the PopChart Embedder library via a <script> tag in your document header, and then place your PopChart Embedder code inside of a <script> tag wherever you want your PopChart image.

Because Chapter 4 is based entirely on the JavaScript PopChart Embedder, we will not repeat embedding instructions in this section. You should read Chapter 4 to learn how to embed PopChart images with the JavaScript PopChart Embedder.

JavaScript Embedder limitations

Because of the nature of JavaScript, the JavaScript embedder is somewhat limited. For the most part, it is provided to help you learn how to use PopChart Server more quickly. It should not be used in a production environment.

Limitations when using the JavaScript PopChart Embedder include:

Additionally, the JavaScript PopChart Embedder has not been tested as extensively as the other PopChart Embedders.

How Does it Work?

For most users, the answer to this question is that it doesn't matter. However, since the JavaScript embedder works somewhat differently than the server-side PopChart Embedders, more advanced users may find it helpful to know exactly what is going on.

When you import the JavaScript embedder library using the <script> tag, you are essentially telling the web browser to ask PopChart Server for a JavaScript file. PopChart Server sees the request for jsEmbedder and internally loads a JavaScript file (PopChart Server has to process the file before returning it to the client).

Note: This file is about 20K in size. It is cacheable, so the browser will only need to download it the first time it displays a PopChart image.

The file that PopChart Server loads depends on what edition you are running. For the standard edition of PopChart Server, this file is the lib/gifonly.js file. For PopChart Server Enterprise and PopChart Server Pro, this file is lib/fallback.js. PopChart Server makes a couple of macro substitution to the &host;, &bVersion;, &bVersion;, and &bVersion; entities (if they exist), and then serves the resulting file to the web browser.

Note: More adventurous users can even try customizing these files for their own needs. One possible customization is to substitute &host; with PopChart Server's server address, and then serve the embedder directly from your web server. This way, the only file that actually has to know the location of PopChart Server is your JavaScript embedder. You will need to restart PopChart Server, though, after customizing this file.

The web browser, which will wait to process any further JavaScript commands until it receives the JavaScript file, processes the file as soon as it is returned. The web browser will then proceed to process other segments of JavaScript.

When you call the getEmbeddingHTML() method, PopChart Server will "compile" your PopChart image into another <script> tag. This tag is in the form:

<script language="JavaScript1.2" src="http://server_address/?@_JSserver_commands">
</script>

The web browser will write this to the document and continue processing any JavaScript statements it sees until it reaches a </script> tag. Then, it will process the <script> tag that getEmbeddingHTML() returned. This tag again requests a JavaScript file from PopChart Server. This time, PopChart Server will see the @_JS server command and recognize that it should return a JavaScript file that will write the HTML appropriate for embedding the PopChart image.

After this file is returned to the web browser, the web browser processes it, resulting in an <object>, <embed>, or <img> tag being written to the web page. From here on out, the process is very much like the process for server-side PopChart Embedders, beginning with Step 6.