User Guide
76 Chapter 5 Graphing Data
6 Return to your browser and enter the following URL to view graphdata.cfm:
http://127.0.0.1/myapps/graphdata.cfm
Reviewing the code
The following table describes the highlighted code and its function:
Code Description
Employee.StartDate,
Add the employee start date to the data
in the GetSalaries query.
<cfloop index="i" from="1"
to="#GetSalaries.RecordCount#">
<cfset GetSalaries.StartDate[i]=
NumberFormat(DatePart("yyyy",
GetSalaries.StartDate[i]) ,9999)>
</cfloop>
Use a cfloop to extract the year of hire
from each employee’s hire data and
convert the result to a four-digit number.
<cfquery dbtype = "query" name =
"HireSalaries">
SELECT
StartDate,
AVG(Salary) AS AvgByStart
FROM GetSalaries
GROUP BY StartDate
</cfquery>
Create a second query from the
GetSalaries query. This query contains
the average salary for each start year.
<cfloop index="i" from="1"
to="#HireSalaries.RecordCount#">
<cfset HireSalaries.AvgByStart[i]
=Round(HireSalaries.AvgByStart[i]
/1000)*1000>
</cfloop>
Round the salaries to the nearest
thousand.
<cfgraph type="line"
query="HireSalaries"
valueColumn="AvgByStart"
itemColumn="StartDate"
Create a line graph using the
HireSalaries query. Graph the average
salaries against the start date.
title="Average Salaries by
Date of Hire"
Title the graph.
fileFormat="Flash"
Send the graph to the user as a Flash
file.
GraphWidth=400
Limit the graph width to 400 pixels.
Generator automatically resizes the
graph’s height to maintain the aspect
ratio.
BackgroundColor="##FFFF00"
Depth=5
lineColor="teal"
Display a 3D graph in teal against a
yellow background.
fill="yes"
Fill the region below the graph to create
an area graph.