View comments | RSS feed

Creating a chart

The ability to display data in a chart or graph can make data interpretation much easier. Rather than present a simple table of numeric data, you can display a bar, pie, line, or other applicable type of chart using colors, captions, and a two-dimensional or three-dimensional representation of your data.

The cfchart tag, along with the tags cfchartseries and cfchartdata, provide many different chart types. The attributes to these tags let you customize your chart appearance.

Chart types

You can create 11 types of charts in ColdFusion in two and three dimensions. The following figure shows a sample of each type of chart in two dimensions.

Note:   Horizontal bar charts are bar charts rotated 90 degrees. In two dimensions, bar and cylinder charts appear the same, as do cone and pyramid charts.

Two dimensional example of each type of ColdFusion chart

Creating a basic chart

To create a chart, you use the cfchart tag along with at least one cfchartseries tag. You can optionally include one or more cfchartdata tags within a cfchartseries tag. The following table describes these tags:
Tag
Description
cfchart
Specifies the container in which the chart appears. This container defines the height, width, background color, labels, fonts, and other characteristics of the chart.
You must include at least one cfchartseries tag within the cfchart tag.
cfchartseries
Specifies a database query that supplies the data to the chart and/or one or more cfchartdata tags specifying individual data points. Specifies the chart type, colors for the chart, and other optional attributes.
cfchartdata
Optionally specifies individual data point to the cfchartseries tag.

The following shows the basic code you use to create a chart:

<cfchart
  <!--- optional attributes to cfchart --->
  >

  <!--- one or more cfchartseries tags --->
  <cfchartseries
    type="type"
    <!--- optional attributes to cfchartseries --->
    />

  <cfchartseries
    type="type"
    <!--- optional attributes to cfchartseries --->
    >
      <!--- zero or more cfchartdata tags --->
      <cfchartdata
        value="number"
        <!--- optional attributes to cfchartdata --->
        >
  </cfchartseries>

</chart>

Often, you use these tags to chart the data stored in a ColdFusion query. If you have a query that contains average salary information by department, the following code displays a bar chart that shows the data in the query:

<cfchart
    xAxisTitle="Department"
    yAxisTitle="Salary Average"
  >
  <cfchartseries 
    type="bar" 
    query="DataTable" 
    valueColumn="AvgByDept" 
    itemColumn="Dept_Name"
    />
</cfchart>

In this example, the data from the query column AvgByDept supplies the data for the y-axis, and the query column Dept_Name provides the data for the x-axis.

The resulting chart looks like the following:

Example bar chart containing data from a query

ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


hardwood said on Dec 29, 2003 at 6:19 AM :
RE: <B>Note:</b> Horizontal bar charts are bar charts rotated 90 degrees. In two dimensions, bar and cylinder charts appear the same, as do cone and pyramid charts. - How to rotate the chart 90 degrees?: cfchart rotated="yes"
markireland said on Jun 17, 2004 at 10:03 PM :
Time Series data should scale to a sensible unit like day or month etc
No screen name said on Aug 5, 2004 at 12:01 AM :
Is there a way to change the colors of the bar in the "Bar" chart? This functionality was in CF5.0. I don't why Macromedia took away the functionality in CFMX.
No screen name said on Sep 24, 2004 at 12:38 PM :
To change the colors of the bars, or any other graph object for that matter, set the "seriescolor" attribute to the desired color in the <cfchartseries> tag. Remember to escape your # signs :)
rharvey_2 said on Feb 19, 2005 at 9:11 PM :
This is # 1: (it works)<br>
<cfchart format="flash" chartheight="50" >
<cfchartseries type = "horizontalbar" serieslabel="Strong=5 Good=4 avg=3 Fair=2 Weak=1" paintstyle="shade" >
<cfchartdata item= "Label_Label_Label" value = 4.5>
</cfchartseries>
</cfchart>

<br>This is # 2: (does not work with two spaces between words ... remove spaces and it will work)<br>
<cfchart format="flash" chartheight="50" >

<cfchartseries type = "horizontalbar" serieslabel="Strong=5 Good=4 Avg=3 Fair=2 Weak=1" paintstyle="shade" >
<cfchartdata item= "Label Label Label" value = 4.5>
</cfchartseries>
</cfchart>

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/graphing2.htm