Adding Percentages To A Chart Created With ColdFusion

My boss wanted me to add percentages to a chart I built using ColdFusion. I researched the CF cfchart and cfchartseries tags in the CF documentation online to see if there was some way to get CF to do this for me. I didn't find any attributes that did that. So I spent a couple of hours adding code to do the math for me and display the percentages as part of each bars label. Later I learned I wasted my time!

Then my boss wanted me to create a pie chart that was using gray scales with patterns instead of colors. Again, I researched the CF chart tags to see how to do that. I found an attribute for the cfchartseries tag called "datalabelstyle" which has a description that reads "Specifies the way in which the color is applied to the item in the series:" Thinking this might be the attribute I need, I keep reading the description and find out that this inappropriately named and described attribute is actually the one I needed to get percentages to appear next to each bar (or pie slice) on my chart. One of the values for this attribute is pattern. Pattern will cause the chart to display "combination of column label, value, and aggregate information, such as columnLabel value for the percentage of total graph; for example, Sales 55,000 20% of 277,000" for each bar or pie slice.

Sure enough, after I added datalabelstyle = "pattern" to my cfchartseries tags the percentages appeared. I initially passed this attribute by when looking for the solution to getting percentages to appear because of the first part of the attribute's description: "Specifies the way in which the color is applied to the item in the series:" If the documentation had been better written, I could have saved myself a couple of hours of work.

Yes, I've posted a comment to the documentation.

Reference: CFMX 7 CFML Reference, cfchartseries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Thank you so much for posting this finding.

I have been looking for this solution for such a long time and I couldn't believe it wasn't easy to implement.

This is great info. This will make my charts much easier to read.

Keep up the good work!
# Posted By Rosana Levesque | 5/28/07 9:25 AM
I have been looking for this solution for such a long time
# Posted By ayd?nlatma | 12/8/07 5:31 AM
thanks for the post
# Posted By Lazer Kesim | 1/25/08 11:07 AM
Thank God I found this post! How did people code before google?!?! Thanks for posting!
# Posted By Nexon Louis | 2/6/08 10:00 AM
Bruce a year and a half later and this post is still useful. One question, anyway to strip down the info that datalabelstyle attribute presents? I was just doing a pie chart and the info is just mashed up for the smaller slices.

Any help is greatly appreciated.

# Posted By Alfio Raymond | 10/14/08 11:01 AM
BlogCFC was created by Raymond Camden. This blog is running version Contact Blog Owner