Adobe COLDFUSION 9 Manual page 993

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Working with Documents, Charts, and Reports
Code
<cfquery name="GetSalaries" datasource="cfdocexamples">
SELECT Departmt.Dept_Name, Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID = Employee.Dept_ID
</cfquery>
<cfquery dbtype = "query" name = "DeptSalaries">
SELECT
Dept_Name,
AVG(Salary) AS AvgByDept
FROM GetSalaries
GROUP BY Dept_Name
</cfquery>
<cfloop index="i" from="1" to="#DeptSalaries.RecordCount#">
<cfset
DeptSalaries.AvgByDept[i]=Round(DeptSalaries.AvgByDept[i]/1
000)*1000>
</cfloop>
<cfchart
xAxisTitle="Department"
yAxisTitle="Salary Average"
font="Arial"
gridlines=6
showXGridlines="yes"
showYGridlines="yes"
showborder="yes"
show3d="yes"
>
<cfchartseries
type="bar"
query="DeptSalaries"
valueColumn="AvgByDept"
itemColumn="Dept_Name"
seriesColor="olive"
paintStyle="plain"
/>
</cfchart>
You can also rewrite this example to use the
of using the loop, to round the salary data, as the following code shows:
<cfchartseries
type="bar"
seriesColor="olive"
paintStyle="plain">
<cfoutput query="deptSalaries">
<cfchartdata item="#dept_name#" value=#Round(AvgByDept/1000)*1000#>
</cfoutput>
</cfchartseries>
Combining a query and data points
To chart data from both query and individual data values, you specify the query name and related attributes in the
tag, and provide additional data points by using the
cfchartseries
ColdFusion displays the chart data specified by a
left on a bar chart. You can use the
and
cfoutput
cfchartdata
cfchartdata
attribute of the
sortXAxis
cfchart
Last updated 8/5/2010
Description
Query the cfdocexamples 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. You can
use the raw results of this query 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
only one row exists for each department.
Loop through all the rows in the DeptSalaries query and
round the salary data to the nearest thousand. This loop
uses the RecordCount query variable to get the number of
rows, and directly changes the contents of the query
object.
Create a bar chart using the data from the AvgByDept
column of the DeptSalaries query. Label the bars with the
department names.
tags within the
cfchartseries
tag.
cfchartdata
tag before the data from a query, for example, to the
tag to sort data alphabetically along the x axis.
988
tag, instead

Advertisement

Table of Contents
loading

Table of Contents