cfgraph type = "pie"

Use this form of the cfgraph tag to generate pie charts.

Syntax

<cfgraph type = "pie"
  query = "query name"
  valueColumn = "query column"
  itemColumn = "query column"

<!--- data drill down attributes --->
  URL = "URL string"
  URLColumn = "query column"

<!--- pie chart value display attributes --->
  showValueLabel = "yes", "no", or "rollover"
  valueLabelFont = "Arial", "Courier", or "Times"
  valueLabelSize = number of points
  valueLocation = "inside" or "outside"

  title = "title text"
  titleFont = "Arial", "Courier", or "Times"
  showLegend = "above", "below", "left", "right", or "none"
  legendFont = "Arial", "Courier", or "Times"

  fileFormat = "Flash", "gif" or "jpg"
  graphHeight = integer number of pixels
  graphWidth = integer number of pixels
  backgroundColor = "Web color"
  borderColor = "Web color"
  borderWidth = integer number of pixels
  depth = integer number of pixels
  colorList = "Web color list">
...
</cfgraph> 

Basic attributes

The following tables describe the cfgraph attributes by category.
Attribute
Description
type
Required. Type of chart to display. One of the following:
  • Bar
  • HorizontalBar
  • Line
  • Pie
query
Name of the query containing the data to graph. Required if you do not use cfgraphdata tags in the cfgraph tag body to specify the data values.
valueColumn
Query column that contains the data values.
Required if you do not use cfgraphdata tags in the cfgraph tag body to specify the data values.
itemColumn
Optional. Query column that contains the item label for the corresponding data point. The item labels appear in the chart legend.

Data drill-down attributes

You can use the following attributes to make your chart active by linking to a URL when the user clicks on a piece of pie.
Attribute
Description
URL
Optional. A URL to load when the user clicks any data point on the chart. You can use this column to specify a static string is part of all links on the chart, such as
http://www.mycompany.com/myapp/salary_info/chart_details/
Any data from the URLColumn attribute gets appended to this attribute's value to create the URL link. This attribute has an effect only if the graph is in Flash as the file format.
URLColumn
Optional. Query column containing URL information to load when the user clicks the corresponding data point. The data from this attribute gets appended to any URL attribute value to create the URL. This attribute has an effect only if the graph is in Flash file format.

Pie chart value display attributes

These attributes determine how the data point values are displayed on the graph and the values on the vertical axes.
Attribute
Description
showValueLabel
Optional. Specifies whether values are displayed for the data points. Valid values are:
  • yes (default)
  • no
  • rollover (only works with Flash file format)
valueLabelFont
Optional. The font used to display data values. Valid values are:
  • Arial (default)
  • Courier
  • Times
valueLabelSize
Optional. The size the value text, in points.
Default value: 12.
valueLocation
Optional. Where value labels are placed. Valid values are:
  • inside (default)
  • outside

Pie chart legend and title attributes

These attributes determine how the title and legend appear.
Attribute
Description
title
Optional. Title to display centered above the chart, or below the chart if the legend is above the chart. If unspecified, no title displays.
titleFont
Optional. The font used to display the title. Valid values are:
  • Arial (default)
  • Courier
  • Times
showLegend
Optional. The placement of the legend that identifies colors with the data labels. Valid values are:
  • above    Horizontal legend centered above the chart.
  • below    Horizontal legend centered below the chart.
  • left    (default) Vertical legend to the left of the chart.
  • right    Vertical legend to the right of the chart.
  • none    No legend
legendFont
Optional. The font used to display the legend. Valid values are:
  • Arial (default)
  • Courier
  • Times

Pie chart appearance attributes

These attributes determine the general appearance of the graph.
Attribute
Description
fileFormat
Optional. File type to be used for the output displayed in the browser. Must be one of the following:
  • Flash (default)
  • gif
  • jpg
graphHeight
Optional. Height of the graph, in pixels.
Default is 240.
graphWidth
Optional. Width of the graph, in pixels.
Default is 320.
backgroundColor
Optional. Color of the chart background. Can be any of the 256 standard web colors, in any valid HTML color format.
Default is white.
borderColor
Optional. The color used to draw borders and grid lines. Can be any of the 256 standard web colors, in any valid HTML color format.
Default is black.
borderWidth
Optional. Border thickness, in pixels. Setting this attribute to 0 removes the border.
Default is 1.
depth
Optional. Depth of 3D chart appearance, in pixels.
Default is 0, no 3D appearance.
colorList
Optional. Comma delimited list of colors to use for each data point. If there are more data points than colors in the list, the server cycles through the list. The value may be in any valid HTML color format.
Default is to use an internal list of colors.

Example

The following example analyzes the salary data in the CompanyInfo database and generates a pie chart that shows total salaries by department. The chart uses the default file format, Flash, which supports displaying the value labels as you roll over the pie slices, as specified by the showValueLabel attribute. The chart also uses a custom list of colors for the pie slices.

<!-- Get the raw data from the database. -->
<cfquery name="GetSalaries" datasource="CompanyInfo">
  SELECT Departments.Department_Name, 
    Employees.Department_ID, 
    Employees.Salary
  FROM Departments, Employees
  WHERE Departments.Department_ID = Employees.Department_ID
</cfquery>

<!--- Use a query of queries to generate a new query with --->
<!--- statistical data for each department. --->
<!--- AVG and SUM calculate statistics. --->
<!--- GROUP BY generates results for each department. --->
<cfquery dbtype = "query" name = "DataTable">
  SELECT Department_Name,
    AVG(Salary) AS AvgSal,
    SUM(Salary) AS MinSal
  FROM GetSalaries
  GROUP BY Department_Name
</cfquery>

<!--- Reformat the generated numbers to show only thousands --->
<cfloop index="i" from="1" to="#DataTable.RecordCount#">
  <cfset DataTable.SumSal[i]=Round(DataTable.SumSal[i]/1000)*1000>
  <cfset DataTable.AvgSal[i]=Round(DataTable.AvgSal[i]/1000)*1000>
</cfloop>

<html>
<head>
  <title>Employee Salary Analysis</title>
</head>
<body>

<h1>Employee Salary Analysis</h1> 

<!--- Pie graph, from Query of Queries --->
<cfgraph type="pie" 
  query="DataTable" 
  valueColumn="SumSal" 
  itemColumn="Department_Name" 
  showValueLabel="rollover" 
  title="Total Salaries by Department" 
  colorlist="##6666FF,##66FF66,##FF6666,##66AAAA">
</cfgraph>
<br><br>

</body>
</html>