Ask a Jedi: Moving the label of a pie chart to the right

Andy asks:

Dear Jedi. How can I get the legend to show up on the right of my pie chart. It seems perpetually stuck at the top. I'm using cf7 (and will upgrade to 8 in the next few months).

There is no direct way, but once again, the Chart Editor that ships with ColdFusion comes to the rescue. I loaded it up, selected a Pie chart, and edited the Legend property. I selected Right alignment, and took the generated XML. Now the XML I got had a few extra elements, but I stripped it down to this:

<?xml version="1.0" encoding="UTF-8"?> <pieChart> <legend placement="Right"/> </pieChart>

All together, the code then is:

<cfsavecontent variable="style"> <?xml version="1.0" encoding="UTF-8"?> <pieChart> <legend placement="Right"/> </pieChart> </cfsavecontent>

<cfchart format="flash" show3d="true" style="#style#"> <cfchartseries type="pie"> <cfchartdata item="Like Pacman" value="75"> <cfchartdata item="Not like Pacman" value="25"> </cfchartseries> </cfchart>

Here is a screen shot of the default pie chart followed by the modified one. As you can see, the colors change a bit too, but if you don't like the colors you can tweak that as well.

Archived Comments

Comment 1 by joel posted on 1/30/2008 at 1:53 AM

You can also, of course, save the xml as a separate file and reference it in the style attribute to apply the same styles to multiple charts.

Comment 2 by Raymond Camden posted on 1/30/2008 at 1:59 AM

Yep - and you could get fancy. You could create an XML block for left aligned - note the differences - and generate the XML on the fly to go back and forth.

Comment 3 by Joshua posted on 2/26/2008 at 12:04 AM

Hey Ray,

Where could one find this Chart Editor that you speak of?

Comment 4 by Raymond Camden posted on 2/26/2008 at 12:06 AM

Under your coldfusion folder, charting, webcharts.bat.

Comment 5 by Joshua posted on 2/26/2008 at 12:12 AM

Thanks I found it after reading the docs a little more carefully. :)

Comment 6 by jeff posted on 2/26/2008 at 3:40 AM

Is this a CF8 only thing? When I try to pass a string to the style attribute, I get an error: "The system cannot find the file specified".

Comment 7 by Raymond Camden posted on 2/26/2008 at 3:46 AM

Nope, CF7 added it. Don't forget the PDF reference manual shows the history of tags back to MX.