Ive never really worked much with the cfchart tag. Ive just never had much of a need for it. However, I recently had a requirement to draw a 3d bar chart where each series of data had to appear behind previous datasets. I knew Id seen ColdFusion do this in the past, but for the life of me I couldnt figure it out.
Heres the sample code I was trying to get working. This creates a chart of random data:
<cfchart show3d="yes" xoffset=".125" yoffset=".125"> <cfloop from="1" index="x" to="5"> <cfchartseries type="bar"> <cfchartdata item="Item 1" value="#randRange(1, 10)#"/> <cfchartdata item="Item 2" value="#randRange(1, 10)#"/> <cfchartdata item="Item 3" value="#randRange(1, 10)#"/> <cfchartdata item="Item 4" value="#randRange(1, 10)#"/> </cfchartseries> </cfloop> </cfchart>
This produced an image that looked like this:
However, I really wanted each chart series to appear behind the previous chart series. I googled and read and read and googled but didnt get anywhere. The cfchart tag has one attribute that effect this, seriesplacement. The seriesplacement has these four options, none of which seemed to work:
Cluster This didnt seem to make a difference.
Percent This appears to represent each row across the chart series as a percentage of the column. (Not what I wanted.)
Stacked This stacks each chart series on top of the other. (Also not what I wanted.)
Default Presumably, this is the default. So, if Cluster didnt make any difference in the chart then Cluster must be the default, right?
After a few hours of trying to figure this out I sent a question off to CF-Talk which was answered by Matt Walker. To quote him:
“Hilariously, in CF7, default is not the default!”
So, all I had to do was set the chartseries to default and it worked. Heres the code:
<cfchart seriesplacement="default" show3d="yes" xoffset=".125" yoffset=".125"> <cfloop from="1" index="x" to="5"> <cfchartseries type="bar"> <cfchartdata item="Item 1" value="#randRange(1, 10)#"/> <cfchartdata item="Item 2" value="#randRange(1, 10)#"/> <cfchartdata item="Item 3" value="#randRange(1, 10)#"/> <cfchartdata item="Item 4" value="#randRange(1, 10)#"/> </cfchartseries> </cfloop> </cfchart>
Heres the result:
Comments on: "When Default Is Not The Default" (1)
You should submit this to the ColdFusion cookbook. I think this will help people out with their graphing needs.
LikeLike