User Guide

Table Of Contents
736 Chapter 31: Creating Charts and Graphs
Charting individual data points
When you chart individual data points, you specify each data point by inserting a
cfchartdata
tag in the
cfchartseries tag body. For example, the following code creates a simple pie chart:
<cfchart>
<cfchartseries type="pie">
<cfchartdata item="New Vehicle Sales" value=500000>
<cfchartdata item="Used Vehicle Sales" value=250000>
<cfchartdata item="Leasing" value=300000>
<cfchartdata item="Service" value=400000>
</cfchartseries>
</cfchart>
This pie chart displays four types of revenue for a car dealership. Each cfchartdata tag specifies
a department’s income and a description for the legend.
Note: If two data points have the same item name, ColdFusion creates a graph of the value for the
last one specified within the
cfchart tag.
The cfchartdata tag lets you specify the following information about a data point:
Charting a query
Each bar, dot, line, or slice of a chart represents data from one row/column coordinate in your
result set. A related group of data is called a chart series.
Because each bar, dot, line, or slice represents the intersection of two axes, you must craft the
query result set such that the row and column values have meaning when displayed in a chart.
This often requires that you aggregate data in the query. You typically aggregate data in a query
using one of the following:
Specify a SQL aggregate function (SUM, AVG, MAX, and so on) using a GROUP BY clause
in the SELECT statement.
Use a Query of Queries.
Retrieve data from a view, instead of a table.
When you chart a query, you specify the query name using the
query attribute of the
cfchartseries tag. For example, the code for a simple bar chart might be as follows:
<cfchart
xAxisTitle="Department"
yAxisTitle="Salary Average"
>
<cfchartseries
type="bar"
query="DataTable"
Attribute Description
value The data value to be charted. This attribute is required.
item (Optional) The description for this data point. The item appears on the horizontal axis of
bar and line charts, on the vertical axis of horizontalbar charts, and in the legend of pie
charts.