NetCharts® Applets and Cold Fusion
NetCharts Applets can be used in combination with Macromedia's Cold Fusion Markup Language (CFML) technology to dynamically produce chart-enabled HTML pages.
This example uses CFML to extract data from an ODBC data source called regionalsales, populate variables with the data, and build an HTML page that contains a NetCharts Applets applet that uses this data.
Configuring the ODBC data source
Running the example
Examining the CFML code
The complete CFML source code
Download the PDF of the source code
When run, the example will generate a page containing the following barchart applet.

Configuring the ODBC Data Source
This example extracts data from a small Access database called regionalsales.mdb. This sample database is provided as part of the NetCharts Applets distribution and can be be registered as a System DSN called regionalsales as follows:
- Launch the Control Panel.
- Select Data Sources (ODBC).
- Select the System DSN tab.
- Add a "Microsoft Access Driver (*.mdb)" data source
- Name the data source regionalsales.
- Select the regionalsales.mdb file. Its default location is
c:\program files\visual mining\netcharts4.5\Netcharts\examples\dataimport.
Running the Example
The example CFML script can be configured and run using the following steps:
- Make sure that regionalsales.mdb is available as a System DSN (see above).
- Copy the getSalesDataChart.cfm file to any subdirectory under the Cold Fusion-enabled webserver. For instance, with IIS or PWS, it could be in the \wwwroot directory or any subdirectory under \wwwroot.
- Make a copy of the NetCharts 4.x \classes directory under \wwwroot, or make a \classes virtual directory that points to the \classes directory under the NetCharts Applets 4.x installation. The default installation directory for NetCharts Applets 4.x is
c:\program files\visual mining\netcharts 4.x\netcharts\. - Start a web browser and load the CFM page. For example, if the CFM page was installed in the wwwroot/examples directory, the URL would look like http://localhost/examples/getSalesDataChart.cfm
When you load the page, you should see some a page the regional sales chart shown above.
Examining the Code
This ASP script performs the following steps to create chart enabled web page.
- Define the variables
- Connect to the database and pass in the SQL statement
- Open the database and extract the data
- Temporarily pass the data into holding arrays
- Populate the variables with the data from the arrays
- Instantiate the applet and pass the variables in through the NFParamScript parameter.
The first section of code defines several variables. These variables are used to connect to the ODBC datasource, pass in the SQL statement that defines the data we want to extract, and hold this data for passing to the NetCharts Applets applet:
<!--- Create CFML variables to hold values to be passed to the NetCharts Applets Applet. --->
<cfparam name=DataSet1 default=#URLEncodedFormat("15,20,25,15")#>
<cfparam name=DataSet1 default=#URLEncodedFormat("15,20,25,15")#>
<cfparam name=DataSet1 default=#URLEncodedFormat("15,20,25,15")#>
<cfparam name=DataSet1 default=#URLEncodedFormat("15,20,25,15")#>
<cfparam name=BarLabels default=#URLEncodedFormat("Jan,Feb,Mar,Apr")#><!--- Create arrays to temporarily hold data from database --->
<cfset ds1 = ArrayNew(1)>
<cfset ds2 = ArrayNew(1)>
<cfset ds3 = ArrayNew(1)>
<cfset ds4 = ArrayNew(1)>
<cfset labels = ArrayNew(1)>
The next section of code opens a connection to the database, and prepares and executes the SQL statement. . It then copies the RecordSet data into the temporary holding arrays.
<!--- Query regionalsales data source for sales info.
Remember to add the regionalsales.mdb Access database
as a System DSN.
--->
<cfquery name="sales" datasource="regionalsales">
SELECT region, quarter1, quarter2, quarter3, quarter4 FROM Sales
</cfquery><!--- Loop through the RecordSets and populate the arrays with the data --->
<cfloop query="sales">
<cfset ds1[CurrentRow]=sales.quarter1[CurrentRow]>
<cfset ds2[CurrentRow]=sales.quarter2[CurrentRow]>
<cfset ds3[CurrentRow]=sales.quarter3[CurrentRow]>
<cfset ds4[CurrentRow]=sales.quarter4[CurrentRow]>
<cfset labels[CurrentRow]=sales.region[CurrentRow]>
</cfloop>
Next, data is extracted from the ResultSet and stored in strings. These strings contain the data in a comma-separated format, which NetCharts Applets can understand. Ultimately, the data will look something like "5,10,15,20".
<!--- Use cfscript to transfer the array data over to the variables
to be used in the NetCharts Applet's NFParamScript
--->
<cfscript>
DataSet1 = arraytolist(ds1,",");
DataSet2 = arraytolist(ds2,",");
DataSet3 = arraytolist(ds3,",");
DataSet4 = arraytolist(ds4,",");
BarLabels = arraytolist(labels,",");
</cfscript>
The applet tag can now be constructed. NetCharts Applets uses an applet parameter called NFParamScript to pass in chart definition strings. A simple name=value format is used to construct complete chart definitions that can be processed by the NetCharts Applets applet.
Note: The "code=" attribute of the applet is pointing to the netcharts45.apps.* package. This is done to avoid any classpath conflicts that may occur on the system running NetCharts Applets. If, for instance, an older version of NetCharts Applets is installed on the system, and the CLASSPATH environment variable is pointing to that package, then a conflict could occur that might keep this example from running. By pointing specifically to the netcharts45.apps.* package, no conflict will occur. Note that a change will need to be made to the "code=" attribute in all of the applet tags with every major new version upgrade of NetCharts Applets. (NetCharts Applets 5.0, 6.0, etc.)
If this potential classpath conflict is not a concern, then set "code=netcharts.apps.*". This will allow the applets to run across multiple versions of NetCharts Applets, without any changes.
<applet name=Quarterly Sales
code=netcharts4.apps.NFBarchartApp
codebase=/classes
archive=netcharts4.jar
width=600 height=400>
<param name=NFParamScript value='
#Populate the chart with all of the static template information;
ChartName = "Basic Grouped Barchart";
DebugSet = ALL;
ChartWidth = 600;
ChartHeight = 400;
Background = (white,NONE,3,null,TILE,black);
...
The key CDL parameters for this chart are DataSet1, DataSet2, DataSet3, DataSet4, and BarLabels. These parameters are assigned variables for their values.
#Now populate the chart with the dynamic data extracted from the database via Cold Fusion;
<cfoutput>
DataSet1 = #DataSet1#;
DataSet2 = #DataSet2#;
DataSet3 = #DataSet3#;
DataSet4 = #DataSet4#;
BarLabels = #BarLabels#;
</cfoutput>
When this CFML page runs, it will substitute the values for the variables DataSet1-4 and BarLabels creating a complete chart definition.
![]()



