Home / Support / Swiff Chart Generator / Creating Charts using CFEXECUTE - ColdFusion
Knowledge Base

SAMPLE: Creating Charts using CFEXECUTE - ColdFusion

The information in this article applies to:

  • Swiff Chart Generator 2

Description

You can dynamically create a chart with Swiff Chart Generator in ColdFusion by simply calling the CFEXECUTE tag in your ColdFusion code. The CFEXECUTE tag enables you to launch any application from the command line with specific options. Creating a chart using CFEXECUTE simply consists in running the Swiff Chart Generator command line with the required options (data, style etc.) within the ColdFusion code and display the generated Flash movie or image in the page using standard HTML tags.

Swiff Chart Generator can be invoked from the command line with specific input parameters by running the executable file named swfchart.exe. This file is located in the installation directory of Swiff Chart Generator (usually C:\Program Files\GlobFX Technologies\Swiff Chart Generator\ for Windows Systems and /usr/local/SwiffChart/ for UNIX Systems).

Windows syntax:

C:\Program Files\GlobFX Technologies\Swiff Chart Generator> swfchart.exe [options] [data_filename|-]

UNIX syntax:

/usr/local/SwiffChart$ swfchart [options] [data_filename|-]

For the complete list of command line options, refer to Swiff Chart Generator documentation Reference > Command Line Reference > Command Line Options.

Note: The command line options specified in the CFEXECUTE tag must not contain special characters that are interpreted by the system such as white spaces or ";" on Unix systems. To insert such special characters, you must replace them by there corresponding ASCII code. For example, white spaces must be replaced by %20, ";" must be replaced by %3B etc.

Code Sample for Windows

This example illustrates how to create a simple bar chart using the ColdFusion tag CFEXECUTE on a Windows system.

<CFHEADER NAME= "Expires" VALUE="#Now()#">

<CFSCRIPT> 
  dirpath = GetDirectoryFromPath( GetBaseTemplatePath() );

  // Specify the output filename of the generated chart
  output_filename= "the_chart.swf";
  pathname= dirpath & output_filename;

  // Specify the chart style
  args= "/STYLE bar/SanFrancisco ";
  
  // Specify the categories
  args= args & "/CATEGORIES Q1;Q2;Q3;Q4 ";

  // Specify 2 series (each series must be separated by a \n character)
  args= args & "/DATA 12;11;6;9\n23;12;8;11 ";

  // Specify the series names "Sales 2001" and "Sales 2002"
  args= args & "/SERIES-TITLES Sales%202001;Sales%202002 ";
  
  // Specify the chart title and subtitle
  args= args & "/TITLE Financial%20Results /SUBTITLE (Values%20in%20M$%20-%20Year%20to%20year%20results) ";
  
  // Specify the width and height of the generated chart
  args= args & "/WIDTH 400 /HEIGHT 300 ";

  // Specify that chart is not looping
  args= args & "/LOOPING False ";

  // Specify the output filename
  args= args & "/O " & pathname;
</CFSCRIPT> 

<CFEXECUTE NAME="C:\Program Files\GlobFX Technologies\Swiff Chart Generator\swfchart.exe"
           ARGUMENTS=#args#
           TIMEOUT="1">
</CFEXECUTE>
 
<H2>The Bar Chart</H2>
<br>
<OBJECT width=400 height=300 
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0">
<CFOUTPUT>  
  <PARAM name=movie value="#output_filename#">
  <PARAM name=quality value=high>
  <PARAM name=scale value=ExactFit>
</CFOUTPUT>
</OBJECT>

Code Sample for Unix

This example illustrates how to create a simple bar chart using the ColdFusion tag CFEXECUTE on a Unix system.

<CFHEADER NAME= "Expires" VALUE="#Now()#">

<CFSCRIPT> 
  dirpath = GetDirectoryFromPath( GetBaseTemplatePath() );

  // Specify the output filename of the generated chart
  output_filename= "the_chart.swf";
  pathname= dirpath & output_filename;

  // Specify the data delimiter
  // For ease of use, we choose "," as the data delimiter instead of the traditionnal ";" 
  // since ";" is interpreted by the system.
  args= "--delimiters , ";

  // Specify the chart style
  args= args & "--style bar/SanFrancisco ";

  // Specify the categories
  args= args & "--categories Q1,Q2,Q3,Q4 ";

  // Specify 2 series (each series must be separated by a \n character)
  args= args & "--data 12,11,6,9\n23,12,8,11 ";

  // Specify the series names "Sales 2001" and "Sales 2002"
  args= args & "--series-titles Sales%202001,Sales%202002 ";
  
  // Specify the chart title and subtitle
  args= args & "--title Financial%20Results --subtitle (Values%20in%20M$%20-%20Year%20to%20year%20results) ";
  
  // Specify the width and height of the generated chart
  args= args & "--width 400 --height 300 ";

  // Specify that chart is not looping
  args= args & "--looping False ";

  // Specify the output filename
  args= args & "-o " & pathname;
</CFSCRIPT> 

<CFEXECUTE NAME="/usr/local/SwiffChart/swfchart"
           ARGUMENTS=#args#
           TIMEOUT="1">
</CFEXECUTE>
 
<H2>The Bar Chart</H2>
<br>
<OBJECT width=400 height=300 
        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0">
<CFOUTPUT>  
  <PARAM name=movie value="#output_filename#">
  <PARAM name=quality value=high>
  <PARAM name=scale value=ExactFit>
</CFOUTPUT>
</OBJECT>

Keywords:ColdFusion CFEXECUTE

Swiff Chart Generator