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.
<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>
<cfset setLocale("English (UK)")>
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.
Archived Comments
Is that chart editor in dreamweaver or CFbuilder?
The chart editor ships with ColdFusion.
For those that aren't familiar, webcharts.bat can found in the charting folder.
Thanks Steve. Yeah, that detail woulda been helpful. ;)
The cause of the currency hitch is the underlying JRE from which CF takes the locale setting, not from setlocale.
If you have control of your server you can make the locale change to the JRE.
Here is an example in CFadmin => Server Settings => Java and JVM
-server -Dsun.io.useCanonCaches=false -XX:MaxPermSize=128m -Dcoldfusion.rootDir={application.home}/../ -Dcoldfusion.libPath={application.home}/../lib -Duser.language=en -Duser.region=GB
To change the locale, just append the last two entries:-
-Duser.language=en -Duser.region=GB
With your language and locale. This will need a server reboot.
Just to add a little to Ray's post about using styles and xml.
Firstly, you can either have all of the cfchart attribues in styles, or none of them, you can't mix.
If you are using a xml file instead of cfsavecontent, the path to is is the same as if you were using a cfinclude.
For reference, here is a list of all of the JRE locales:-
http://download.oracle.com/...
Thanks for adding that Jenny!