CFCHART and the Case of the Disappearing Labels

A user reported an odd problem today. She was using Soundings, my ColdFusion survey application, and noticed something odd. She would do a report and the chart would be missing data! Here is an example:

This chart should have 9 items, even though some are blank, but we only see 5 labels. I did a quick google check and found out this was a known bug:

http://cfchart.blogspot.com/2005/06/charting-technote-addendum.html

Turns out that in earlier versions of CF, the labels were rotated, but a designer (darn designers!) decided that horizontal labels made more sense. I agree - but it would be nice if CF would automatically rotate them instead of just dropped them.

So I decided to make a quick XML file. From the URL above I saw that I needed to use this XML:

<xAxis>
<labelStyle isHideOverlapped="true" orientation="Horizontal"/>
<titleStyle font="Arial-12-bold" isMultiline="false"/>
</xAxis>

I didn't want to modify the core style files since that wouldn't be a solution for Soundings. According to the docs, you can use either an XML file or a string to specify style information. However, now matter what I did I couldn't get it to work. So I switched to an XML file using just the code above. This still didn't work. However, now I figured it was because I wasn't specifying a "full" style.

Now I was worried. I really did not want to specify 100 styles just to tweak one small little thing. I loaded up the WebCharts style editor. (Everyone knows about that, right? More info can be found here.) First - while this is a cool tool, I had trouble finding a "simple" bar chart. I made my best guess and took a look the XML. Turns out - the file was very simple. Even better, I was able to figure out why my XML above was missing. I changed it to this:

<?xml version="1.0" encoding="UTF-8"?>
<frameChart>
<xAxis>
<labelStyle isHideOverlapped="false" orientation="Vertical"/>
<titleStyle font="Arial-12-bold" isMultiline="false"/>
</xAxis>
</frameChart>

And that alone was enough to fix the problem. Here is the chart as it appears now:

As you can see, I lost the black borders and text, but to be honest it doesn't really bug me much.

Comments

Ray,

If you use the Chart utility tool that is buried in CF you can do tons of things with charts.

Open CFusionMX7\lib\wc50.jar and create the chart you want. This utility lets you take "full" advantage of the Web Charts license. Unfortunately some of the chart types are not available. The utility will even write the xml code for you.

I did my own chart at http://www.clinfrastructure.com/clineng/index.cfm
# Posted By Steve | 2/10/06 7:01 PM
Hey Steve, I thought it was obvious - I _did_ use the tool. :) That's how I fixed my xml.
# Posted By Raymond Camden | 2/10/06 7:18 PM
I got an error, it says Cannot locate gallery files in C:\CFusionMX7\lib\gallery ... I checked and I don't have that folder in either of my installations. Do you guys? Can I get it from somewhere?
# Posted By noname | 2/11/06 11:48 AM
This all just goes to show you how handy Moderate to Advanced information on creating Charts and Reports would be. I'm still trying to claw my way out of a wet paper bag. Such wonderful and powerful features, so little info.
# Posted By Michael White | 2/11/06 11:57 AM
True ...

Just out of curiosity, have you gotten webcharts to work? I created a blank direcotry called gallery and it got rid of the error, but now I go in and I can't load any charts ... hmmm ... help?
# Posted By noname | 2/11/06 12:03 PM
Okay, I figured it out ... I ran the .bat from \CFusionMX7\charting\webcharts.bat ... 1 word: WOW
# Posted By noname | 2/11/06 12:10 PM
Ray,

Sorry I missed the obvious, but most people don't even know the utility exists much less where to find it. What other poorly documented features are buried in CF7? Maybe the cookbook could have a category called EasterEggs...:)
# Posted By Steve | 2/11/06 2:01 PM
Yeah Ray, I just found the charting utility recently, and tried it out, but I dont have a clue how to use it... It generates the xml, but how do you use that in your cf apps... Could you do a blog entry or cookbook article?
# Posted By Ryan Guill | 2/13/06 8:09 AM
It may be the kind of thing that is a bit too detailed for the cookbook, but I'll consider it. As for using it - you just save the file (foo.xml), and in your cfchart, do style="foo.xml" (assuming it is in the same folder). If you download Soundings, you can see this in action. If you save the XML file with the built-in chart styles, you can use style="foo", but I wouldn't recommend that.
# Posted By Raymond Camden | 2/13/06 8:15 AM
ahh, I see...

Thanks!
# Posted By Ryan Guill | 2/13/06 8:22 AM
Is there a way I can give a developer access to the charting stuff without giving them access to the server? Or installing CF on their workstation?
# Posted By Tom Forrest | 2/28/06 6:55 AM
I'm thinking you could install a developer edition. If you wanted to make sure they don't actually run CFM pages, you could disable the cf services.
# Posted By Raymond Camden | 2/28/06 7:08 AM
Thanks Ray.

I went on a test run. Grabbed wc50.jar and the gallery folder, put them together in a folder on a workstation and just did java -jar wc50.jar and it seems to work just fine (even with Java 1.5!).
# Posted By Tom Forrest | 2/28/06 7:11 AM