Graphing Individual Data Points - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

Graphing Data
Reviewing the code
The following table describes the code and its function:
Code
<cfquery name="GetSalaries"
datasource="CompanyInfo">
Employee.Dept_ID
</cfquery>
<cfquery dbtype = "query" name =
"DeptSalaries">
</cfquery>
<cfloop index="i" from="1"
</cfloop>
<cfgraph type="bar"
query="DeptSalaries"
valueColumn="AvgByDept"
itemColumn="Dept_Name"
>
</cfgraph>

Graphing individual data points

When you graph individual data points you specify each data point by putting a
cfgraphdata
simple pie chart:
<cfgraph type="pie" title="Income by Department">
</cfgraph>
SELECT Departmt.Dept_Name,
Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID =
SELECT
Dept_Name,
AVG(Salary) AS AvgByDept
FROM GetSalaries
GROUP BY Dept_Name
to="#DeptSalaries.RecordCount#">
<cfset DeptSalaries.AvgByDept[i]=
Round(DeptSalaries.AvgByDept[i]
/1000)*1000>
tag in the
<cfgraphdata item="New Vehicle Sales" value=500000>
<cfgraphdata item="Used Vehicle Sales" value=250000>
<cfgraphdata item="Leasing" value=300000>
<cfgraphdata item="Service" value=400000>
tag body. For example, the following code creates a
cfgraph
Description
Query the CompanyInfo database to
get the Dept_Name and Salary for
each employee. Because the
Dept_Name is in the Departmt table
and the Salary is in the Employee
table, you need a table join in the
WHERE clause. The raw results of
this query could be used elsewhere
on the page.
Generate a new query from the
GetSalaries query. Use the AVG
aggregating function to get statistical
data on the employees. Use the
GROUP BY statement to ensure that
there is only one row for each
department.
Loop through all the rows in
DeptSalaries query and round the
salary data to the nearest thousand.
This loop uses the query variable
RecordCount to get the number of
rows and changes the contents of the
query object directly.
Create a bar graph using the data
from the AvgByDept column of the
DeptSalaries query. Label the bars
with the Department names.
65

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents