Misha asks:
At first I wasn't sure what she meant. I could easily see the values when I moused over the bars in a barchart. But after speaking with her I figured out that what she really wanted was to see the values without a mouseover. This would be especially useful on a printout. Turns out this is rather easy. You can use the dataLabelStyle attribute to specify a label for your data points. Valid values are none (default), value, rowLabel (kinda silly), columnLabel (ditto), pattern (a data pattern you can't modify, more on that in a bit). So as a concrete example, consider this chart:Hi Raymond, I would really appreciate you if you could help me with CFCHART (CF8). In CF5 in CFGRAPH it was possible to display the value by using showValueLabel attribute. I don't see anything in CF8. Is it possible to display the value from the ValueColumn attribute on the actual bar itself?
<cfchart format="flash" xaxistitle="respondents" yaxistitle="numbers">
<cfchartseries type="bar" serieslabel="result" seriescolor="##6633CC" datalabelstyle="value">
<cfchartdata item="result1" value="75">
<cfchartdata item="result2" value="80">
</cfchartseries>
</cfchart>
Which creates:

Almost right - the chart isn't quite tall enough. We can fix that by using scaleTo:
<cfchart format="flash" xaxistitle="respondents" yaxistitle="numbers" scaleTo="100">

That's better, but obviously we would have to make scaleTo a bit dynamic if we weren't sure of our value range. I mentioned 'pattern' above. What does that do?

That's cool, but you don't have control over what is there. It is kind of silly that the label is repeated, but that second line is really nice.
That got me digging into the chart editor. First I was curious about the data label placement. What if you didn't want to use scaleTo? In my digging I found that you can use an 'Extra Lines' attribute. If set to something above 0, like 1 for example (duh), the chart will always ensure there is an extra line. This handles ensuring the values fit ok. You can also switch to an inner display as well. Here is an example with extra lines turned on:
<cfsavecontent variable="style">
<?xml version="1.0" encoding="UTF-8"?>
<frameChart is3D="false">
<yAxis scaleMin="0">
<labelFormat pattern="#,##0.###"/>
<parseFormat pattern="#,##0.###"/>
</yAxis>
<legend allowSpan="true" equalCols="false" isVisible="false" showColumnLegend="false" halign="Right"
isMultiline="true">
<decoration style="None"/>
</legend>
<dataLabels style="Value" extraLines="1" autoControl="true"/>
</frameChart>
</cfsavecontent>
<cfchart format="flash" xaxistitle="respondents" yaxistitle="numbers" style="#style#">
<cfchartseries type="bar" serieslabel="result">
<cfchartdata item="result1" value="75">
<cfchartdata item="result2" value="80">
</cfchartseries>
</cfchart>
<p/>
Notice I also turned off the legend in the chart. This resulted in:

So - remember how I said that pattern was hard coded? Well with the chart editor you can muck with that. Consider this XML:
<dataLabels style="Pattern" placement="Inside" extraLines="1" autoControl="true">
<![CDATA[
$(value) [$(colPercent) of $(colTotal)]
]]>
</dataLabels>
I specified both the value, and the percent of total, and got rid of the newline there by default. Also note I moved the labels inside. I could get rid of extraLines now if I wanted to. This resulted in the following chart:

Pretty cool! But I'd probably want to change that font color. Anyway, I hope this is useful!
Archived Comments
WOW, Raymond you always give us, a nice stuff.
Thank you
While not directly related to this issue, I just made a post on how to fix the default CFCHART tooltip behavior if you're generating static images:
http://blog.pengoworks.com/...
There are some issues with the default mouse handlers--the main issue is that tooltips can run out of the viewport.
YOu helped more today. Thanks Unnam
Hi Ray,
I have a cfchart issue I wanted to run by you. Taking the chart you have on this page, let's say I wanted to have 2 or more bars above the result1 label on the xaxis.
Sorry - not quite sure I get what you mean. You want two rows of bars?
Your chart above has two labels across the x axis "result1" and "result2". Each label has one bar above it. Instead of one bar per label, I'd like to have two bars with different colors above the label "result1".
Just add another series:
<cfchart format="flash" xaxistitle="respondents" yaxistitle="numbers" style="#style#">
<cfchartseries type="bar" serieslabel="result">
<cfchartdata item="result1" value="75">
<cfchartdata item="result2" value="80">
</cfchartseries>
<cfchartseries type="bar" serieslabel="moon">
<cfchartdata item="result1" value="15">
<cfchartdata item="result2" value="20">
</cfchartseries>
</cfchart>
Has anyone been able to place a datalabel value at the top of a stacked bar chart? The minute I use seriesplacement="stacked" in my CFCHART tag it seems to screw up the placement of the value label.
Have you tried it in the Chart Editor?
Hello, Raymond!
I'm trying to use the datalabelstyle pattern in a pie chart, but it's a mess! All labels are on top of the other, so I can't read anything. Do you know how can I fix it?
Thanks
If you could create a one page demo I could run, I'd take a stab at trying to fix it.
I've get the answer in another post! Thanks for the help!
If anyone is interested..
http://www.raymondcamden.co...
Great Post
Now I'm having another problem with a cfchart... It's a bar chart created with data from a query.
I'm having trouble to define the thickness of bars and the distance between them. When I have lots of bars, they stay close to each other, but when I have just a few, they are really apart.
That's the xml:
<cfsavecontent variable="style">
<?xml version="1.0" encoding="UTF-8"?>
<frameChart>
<frame xDepth="6" yDepth="6" outline="#333333" lightColor="white"
leftAxisPlacement="Front" rightAxisPlacement="Front"/>
<elements shapeSize="40" place="stacked"/>
<xAxis scaleMin="0">
<labelStyle isHideOverlapped="true" orientation="vertical"/>
<titleStyle font="Verdana-14-bold" isMultiline="true"/>
</xAxis>
<yAxis scaleMin="0">
<titleStyle font="Verdana-14-bold"/>
</yAxis>
<topYAxis>
<titleStyle font="Arial-12-bold"/>
</topYAxis>
<dataLabels foreground="black"/>
<popup background="#C8FFFFFF" foreground="#333333"/>
<paint paint="Plain"/>
<insets left="5" top="5" right="5" bottom="5"/>
</frameChart>
</cfsavecontent>
That's my chart:
<cfchart scalefrom = "0"
scaleto = "100"
format = "jpg"
chartHeight = "500"
chartWidth = "800"
font = "arial"
fontSize = "10"
showBorder = "no"
labelFormat = "number"
tipStyle = "mouseOver"
backGroundColor = "##f9f9f9"
show3D = "no"
title = "Chart"
name = "my_chart"
showlegend = "yes"
xaxistitle = "x"
yaxistitle = "y"
style = #style#>
<cfchartseries
type="bar"
colorlist="#variables.color#"
dataLabelStyle="value">
<cfloop query="q_data">
<cfchartdata item="#desc#" value="#qty#">
</cfloop>
</cfchartseries>
</cfchart>
How would one go about charting the data in percentages but displaying the inside chart labels in counts?
As far as I know you can't do this - the "tokens" in the labels are based on values. You can't pass in arbitrary data.
Thanks so much for posting this Raymond! You helped me to better define the pattern style to meet the needs of a client.
Glad this was useful for you! :)
I have a combo chart (line and bar) but only want the data values on my bar series to be displayed. How do I do that? I've tried using <elements shape="Bar">
<series index="1" shape="Prism">
<morph morph="Grow"/>
<dataLabel style="Value"/>
</series>
</elements>
in my xml file, but I get an error. Invalid attribute: style
Do you know why this would be if i pulled it out of WebCharts? I'm using CF Version 8
Can you show me how you used cfchart? Just that line.