Copy link to clipboard
Copied
Is there a way to format data values in CFCHART?
All my values in database are stored as 99.9 See below). These are percentages that I need to display on a bar chart. Everything works fine except when displaying 76.0, it shows as 76. All other values that have a number besides zero after the decimal point show up fine except for zero. I want the numbers to be consistent. I am already using custom XML file for formatting but unable to display the "zero" after the decimal point.
Let's assume, StartYear = 2007 and EndYear = 2008, and the data in Influencer_Data table looks like this:
ID Poll_Year Company Influence_ID Pulse Goal
96 2008 XYZ 842 59.6 59.6
97 2008 XYZ 839 80.8 80.8
98 2008 XYZ 838 86.9 86.9
99 2008 XYZ 841 67.1 67.1
100 2008 XYZ 840 66.3 66.3
101 2008 XYZ 470 54.5 54.5
102 2007 XYZ 842 56.5 56.5
103 2007 XYZ 839 81.5 81.5
104 2007 XYZ 838 85.5 85.5
105 2007 XYZ 841 71.2 71.2
106 2007 XYZ 840 76.0 76.0
107 2007 XYZ 470 54.2 54.2
108 2008 XYZ 843 82.6 82.6
And the data in influencers table looks like this:
Influencer_ID Influencer_Type
470 Regulators
838 Financial Community
839 Community Leaders
840 Media
841 Government
842 Advocates
843 Mexico
<cfloop index="i" from="#StartYear#" to="#EndYear#" step="1"> <CFQUERY NAME="GetInfluenceData#i#" DATASOURCE="#RMIDSN#"> Select ID.*, I.Influencer_Type From Influencer_Data ID INNER JOIN Influencers I ON ID.Influencer_ID = I.Influencer_ID Where ID.Poll_Year = <cfqueryparam value="#i#" cfsqltype="CF_SQL_INTEGER"> AND ID.Company = 'XYZ' Order By I.Influencer_Type </CFQUERY> </cfloop> The custom XML file (TLRIS.xml) looks like this: ?xml version="1.0" encoding="UTF-8"?> <frameChart isInterpolated="false"> <frame xDepth="4" yDepth="5" outline="black" isVGridVisible="true"/> <xAxis> <labelFormat pattern="#0.0"/> </xAxis> <yAxis> <labelFormat pattern="#0.0"/> <labelStyle orientation="Horizontal"/> </yAxis> <dataLabels style="Value" font="Arial-12" isMultiline="true"> <![CDATA[ $(value) ]]> </dataLabels> <legend allowSpan="true" equalCols="false" isMultiline="true"/> <elements drawOutline="false"> <morph morph="Grow"/> </elements> <popup decoration="Round"/> <paint palette="Fiesta" paint="Plain" isVertical="true" min="47" max="83"/> <insets right="5"/> </frameChart> And the code for the graph is below: <cfoutput> <cfchart format="#ChartType#" chartheight="300" chartwidth="750" scalefrom="0" scaleto="100" foregroundcolor="##000000" databackgroundcolor="##ffffff" font="Arial" fontsize="10" labelformat="number" style="TLRIS.xml" show3d="yes" showlegend="yes" tipstyle="mouseOver" tipbgcolor="##FFFF00"> <cfloop index="i" from="#StartYear#" to="#EndYear#" step="1"> <cfset LoopCount = LoopCount + 1> <cfset WhichColor = ListGetAt(colorlist, LoopCount)> <cfchartseries type="bar" serieslabel="#i#" seriescolor="#WhichColor#" datalabelstyle="pattern"> <cfloop query="GetInfluenceData#i#"> <cfchartdata item="#Influencer_Type#" value="#Pulse#"> </cfloop> </cfchartseries> </cfloop> </cfchart> </cfoutput> |
Copy link to clipboard
Copied
In your xml file, try using a "pattern" for the yAxis label, and tweak the zeroes in the mask.
<yAxis ...>
<labelFormat style="Pattern" pattern="#,##0.0#"/>
...
</yAxis>
Copy link to clipboard
Copied
I have already done that with no success.
I am beginning to believe this may be a bug.
Even if you try something as simple as the following, the decimal points that have zeroes don't show
<cfchart style="beige">
<cfchartseries type="pie">
<cfchartdata item="New car sales" value="50.0">
<cfchartdata item="Used car sales" value="55.0">
<cfchartdata item="Leasing" value="56.5">
<cfchartdata item="Service" value="76.2">
</cfchartseries>
</cfchart>
Copy link to clipboard
Copied
mohadi wrote:
I have already done that with no success.
I am beginning to believe this may be a bug.
Even if you try something as simple as the following, the decimal points that have zeroes don't show
<cfchart style="beige">
<cfchartseries type="pie">
<cfchartdata item="New car sales" value="50.0">
<cfchartdata item="Used car sales" value="55.0">
<cfchartdata item="Leasing" value="56.5">
<cfchartdata item="Service" value="76.2">
</cfchartseries>
</cfchart>
Well that is the wrong kind of chart and it is not using the xml style. But it works perfectly with a bar chart, using a custom style. The values display exactly as you have them above.
<cfchart style="myPatternStyle.xml">
<cfchartseries type="bar">
<cfchartdata item="New car sales" value="50.0">
<cfchartdata item="Used car sales" value="55.0">
<cfchartdata item="Leasing" value="56.5">
<cfchartdata item="Service" value="76.2">
</cfchartseries>
</cfchart>
<!--- snippet from xml styles --->
.... other xml ....
<yAxis scaleMin="0">
<titleStyle font="Arial-12-bold"/>
<dateTimeStyle majorUnit="Year" minorUnit="Month"/>
<labelFormat style="Pattern" pattern="#,##0.0#######"/>
</yAxis>
.... other xml ....