Swiff Chart Generator is implemented as COM object and offers a variety of methods for managing and creating charts in Flash. Since ColdFusion supports COM objects, running Swiff Chart Generator within ColdFusion is very simple.
To insert Swiff Chart Generator in a ColdFusion page you must either use the CFOBJECT tag or call the CreateObject function. By using one of these two methods, you will create an instance of the Swiff Chart Generator COM object and have full access to its API (Refer to Swiff Chart Generator documentation for complete description of the API).
Swiff Chart Generator is the efficient solution for generating charts in Macromedia ColdFusion™:
· Highly optimized generation
· Robust and reliable server component
· Professional-looking charts and graphs
How does Swiff Chart Generator work within ColdFusion?
Two pages are required to dynamically generate a chart.
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="400" HEIGHT="300"> <PARAM NAME=movie VALUE="gen_chart.cfm">: <OBJECT/>
A simple ColdFusion Example
The following example illustrates how simple it is to dynamically generate charts in Flash in ColdFusion. As mentioned in the previous paragraph, the example involves 2 files and an additional Swiff Chart style file (.scs):
To install and run the example, simply download and copy these 3 files on your Web site in the same directory.
ColdFusion file: gen_chart.cfm
<CFSETTING ENABLECFOUTPUTONLY="Yes" SHOWDEBUGOUTPUT="No"> <CFOBJECT TYPE="COM" NAME="chart" CLASS="SwiffChartObject.ChartObj.1" ACTION="CREATE"> <!--- Define seperators rules ---> <CFSET sep= ";"> <CFSET ignoremultseparators= true> <CFSET chart.SetSeparators(sep, ignoremultseparators)> <!--- Set the heading for the graph ---> <CFSET chart.SetTitle("My Chart")> <!--- Create the categories ---> <CFSET myCategories= "Q1" & sep & "Q2" & sep & "Q3"> <CFSET chart.SetCategoriesFromString(myCategories)> <!--- Create a string for each series ---> <CFSET series1= "1.2" & sep & "3.5" & sep & "11.3"> <CFSET series2= "2.3" & sep & "4.5" & sep & "9.3"> <CFSET series3= "3.2" & sep & "5.5" & sep & "14.3"> <!--- Fill the chart with the series ---> <CFSET chart.AddSeries()> <CFSET chart.SetSeriesCaption(0, "First Series")> <CFSET chart.SetSeriesValuesFromString(0, series1)> <CFSET chart.AddSeries()> <CFSET chart.SetSeriesCaption(1, "Second Series")> <CFSET chart.SetSeriesValuesFromString(1, series2)> <CFSET chart.AddSeries()> <CFSET chart.SetSeriesCaption(2, "Third Series")> <CFSET chart.SetSeriesValuesFromString(2, series3)> <!--- Define path to style document ---> <CFSET dirpath = GetDirectoryFromPath( GetBaseTemplatePath() )> <CFSET style = dirpath & "chart_style.scs"> <CFSET chart.LoadStyle( style )> <!--- Set the dimensions of the movie ---> <CFSET chart.SetWidth( 400 )> <CFSET chart.SetHeight( 300 )> <CFSET account_id = "100"> <CFSET filename= dirpath & "graph" & dateformat(now(), "DDMMYY") & "_" & timeformat(now(), "HHMMSS") & "_" & account_id & ".swf"> <CFSET chart.ExportAsFile(filename)> <CFCONTENT TYPE="application/x-shockwave-flash" FILE="#filename#">
HTML file: chart.html
<HTML> <HEAD> <TITLE>Swiff Chart Generator - ColdFusion Sample</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/\ cabs/flash/swflash.cab#version=6,0,29,0" WIDTH="400" HEIGHT="300"> <PARAM NAME=movie VALUE="gen_chart.cfm"> <PARAM NAME=quality VALUE=high> <EMBED SRC="gen_chart.cfm" QUALITY=high PLUGINSPAGE="http://www.macromedia.com/shockwave/\ download/index.cgi?P1_Prod_Version=ShockwaveFlash" TYPE="application/x-shockwave-flash" WIDTH="400" HEIGHT="300"> </EMBED> </OBJECT> </BODY> </HTML>
What you will obtain