cfchart and non-American locales

A poster on cf-talk today noticed an interesting issue. Even though she was trying to use the English (UK) locale (or as I call it, Dr. Who’s locale), her cfchart was not using Pound symbols for the values. I whipped up a quick example to verify this issue. Luckily, it’s easy to get around with - you guessed it - the chart style editor.

First, an example that demonstrates the bug.

<cfset setLocale("English (UK)")> <cfchart chartheight="500" chartwidth="500" title="Average Price Per" labelFormat="currency"> <cfchartseries type="bar"> <cfchartdata item="Apples" value="50.99"> <cfchartdata item="Bananas" value="40.12"> <cfchartdata item="Cherries" value="72.00"> <cfchartdata item="Donuts" value="61.21"> </cfchartseries> </cfchart>

This produces:

You can see both on the left hand side, and in the tool tip, the values are in American dollars. To fix this, I simply opened up the chart editor, clicked the Y-Axis section, and picked Format. I changed Style to currency and then turned off the click for system locale.

I took - and stripped down - the XML to get the following code:

<cfsavecontent variable="style"> <?xml version="1.0" encoding="UTF-8"?> <frameChart is3D="false"> <yAxis scaleMin="0"> <labelFormat style="Currency" pattern="#,##0.00"> <locale lang="en" country="GB" variant=""/> </labelFormat> <parseFormat pattern="#,##0.###"/> <groupStyle> <format pattern="#,##0.###"/> </groupStyle> </yAxis> </frameChart> </cfsavecontent> <cfchart chartheight="500" chartwidth="500" title="Average Price Per" labelFormat="currency" style="#style#"> <cfchartseries type="bar"> <cfchartdata item="Apples" value="50.99"> <cfchartdata item="Bananas" value="40.12"> <cfchartdata item="Cherries" value="72.00"> <cfchartdata item="Donuts" value="61.21"> </cfchartseries> </cfchart>

And here is the result:

Fixed! In case you're wondering about the other changes, when you use cfchart and don't specify an XML file, ColdFusion passes a set of values based on defaults and the arguments you used. When you specify an XML style yourself, those defaults go away. Sometimes this means a bit more work, but overall you get much more control over the final result.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments