Saving Charts to a Variable

In all the examples we’ve created so far, the cfchart tag has always been used to render the chart directly to the browser. Behind the scenes, cfchart is generating a SWF, JPG, or PNG file and sending the necessary HTML code to the browser to render the file. For example, if you run the code in Example 17-1 and do a “View Source” in your web browser, you’ll see that ColdFusion MX automatically generated the necessary HTML object and embed tags to display the SWF (Flash) version of the chart:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,2,0"
 ID=Images_100007_SWF name=Images_100007_SWF width=400 height=400>
  <param name=movie value="/CFIDE/GraphData.cfm?graphID=Images/100007.SWF">
  <param name=quality value=high>
  <param name=bgcolor value=#FFFFFF>
<embed src="/CFIDE/GraphData.cfm?graphID=Images/100007.SWF"
  quality=high bgcolor=#FFFFFF width=400 height=400 type="application/x-shockwave-flash"
  pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=
ShockwaveFlash">
</embed>
</object>

If you change the format attribute to JPG instead of Flash, execute the code, and view the source again, you’ll see that ColdFusion automatically generates an HTML img tag for the chart created by cfchart:

<img src="/CFIDE/GraphData.cfm?graphID=Images/100008.JPG" 
     id=Images_100008_JPG name=Images_100008_JPG usemap="#Images_100008_JPG_map"
     border=0>

By specifying ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.