I recently had to create a bar chart in ColdFusion using a structure data type. To make it easy to display each bar's label I used the associative array notation for the key names when I created my structure. The associative array notation enables your structure keys to "contains spaces, numbers, or special characters." (Reference 1). I've forgotten in the past that this alternative way of specifying structure keys is available in ColdFusion so this blog entry will remind me (and maybe others) about the associative array notation for structures.
Below is a code example of a structure that uses associative array notation. I left out all the database work and query processing and in this example just hard coded the structure.
<cfset membersByAgeGroup = structNew() >
<cfset membersByAgeGroup["60 years plus"] = 450>
<cfset membersByAgeGroup["40 - 59 years"] = 1200>
<cfset membersByAgeGroup["39 years and younger"] = 800>
Note how the key values are specified inside quotation marks and inside [ ]. Also note that there is no period between the structure name and the key (NOT membersByAgeGroup.["60 years plus"] which I've done before by mistake).
Now I can use the membersByAgeGroup structure to create my chart and have my bar labels be the key values. In this case the key values are "60 years plus", "40 - 59 years", and "39 years and younger". Click here to see the chart.
<cfchart chartheight="400" chartwidth="600" yaxistitle="Number of Members" title="Age Breakdown of Members" fontsize="10" show3d="yes" gridlines="5" showmarkers="yes" showxgridlines="yes" >
<cfchartseries type="horizontalbar" seriescolor="##FF0000" >
<cfloop list="#ArrayToList( StructSort(membersByAgeGroup, "numeric", "desc") )#" index="key" >
<cfchartdata item="#key#" value="#membersByAgeGroup[key]#" >
See the related blog entry below for more information about using a structure to create a chart. Reference 2 above provides information about structure functions such as StructSort and reference 3 provides information about the ArrayToList function.