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 cfchartseries tag, and provide additional data points using the cfchartdata tag.

ColdFusion displays the chart data specified by a cfchartdata tag before the data from a query; for example, to the left on a bar chart. You can use the sortXAxis attribute of the cfchart tag to sort data alphabetically along the x-axis.

One use of combining queries and data points is to provide data that is missing from the database; for example, to provide the data for one department if the data for that department is missing. The example in the following procedure adds data for the Facilities and Documentation departments to the salary data obtained from the query shown in the previous section:

To chart a query and individual data points:

  1. Open the chartdata.cfm file in your editor.
  2. Edit the cfchart tag so that it appears as follows:
    <cfchart chartwidth="600">
    	<cfchartseries 
    		type="bar"
    		query="DeptSalaries"
    		itemColumn ="Dept_Name" 
    		valueColumn="AvgByDept"
    		>
    		<cfchartdata item="Facilities" value="35000">
    		<cfchartdata item="Documentation" value="45000">
    	</cfchartseries>
    </cfchart>
    
  3. Save the page as chartqueryanddata.cfm in the myapps directory under the web root directory. For example, the directory path in Windows might be C:\Inetpub\wwwroot\myapps.
  4. Return to your browser and enter the following URL to view the chartqueryanddata.cfm page:

    http://localhost/myapps/chartqueryanddata.cfm


View comments in LiveDocs