CFchart issues

Hi,

I am using cfchart in cf8 to output a horizontal bar chart of customer towns but I have a few problems.

1) if I leave out the height then it defaults to about 200px which isn't ideal as this chart has about 100 rows so nothing is viewable.

2) if I set the height to manual it only displays every other bar title.

Any ideas??

Regards
Leigh
LmillardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

azadisaryevCommented:
the solution is to set the chart height dynamically based on number of rows returned by the query (or wherever the data is coming from).

the exact formula will depend on things like font and fontsize used in your chart and whether you display the chart legend or not. for a chart with Arial 12pt normal font and no legend, this one seems works fine:

chartheight="#(yourquery.recordcount*10+50)*2#"

experiment with different values instead of 10 and 50 if you use a different font and/or show a legend.

i have attached a code sample which uses dynamic chart height. the second chart in the code also uses a cystom stylesheet which makes it look a lot better than the default chart style. the main purpose of the custom stylesheet is to disable automatic hiding of overlapped axis labels and to ensure axis labels are displayed on single line.

just save the attached code as a .cfm page and run it in your browser.

Azadi
<!--- create a query to be used in the chart --->
<cfscript>
q = querynew('name,ttl', 'varchar,integer');
queryaddrow(q, 12);
for (i=1; i<13; i++){
	querysetcell(q, 'name', 'a really long long title ' & i, i);
	querysetcell(q, 'ttl', randrange(1, 10), i);
}
</cfscript>

<h2>a cfdump of our data (query):</h2>
<cfdump var="#q#">

<!--- chart with all defaults --->
<h2>chart with fixed height:</h2>
<cfchart format="flash" showlegend="no" showborder="no" chartwidth="480" chartheight="350" showxgridlines="yes" showygridlines="no">
	<cfchartseries type="horizontalbar"
		query="q" 
		valuecolumn="ttl" 
		itemcolumn="name"
		seriescolor="009fda"
		paintstyle="plain" />
</cfchart>


<!--- chart with dynamic height based on number of rows returned by query --->
<!---
create custom chart style xml and save as chartstyle variable.
isHideOverlapped="false" prevents hiding of overlapped labels;
isMultiline="false" makes labels display as one single line.
--->
<cfsavecontent variable="chartstyle">
<?xml version="1.0" encoding="UTF-8"?>
<frameChart autoAdjust="false" is3D="false">
	<frame xDepth="2" yDepth="2" outline="#000000" lightColor="white" stripColor="#CCCCCC"/>
	<xAxis>
		<labelStyle isHideOverlapped="false" orientation="Horizontal" isMultiline="false"/>
		<titleStyle font="Arial-16-bold" isMultiline="false"/>
	</xAxis>
	<yAxis scaleMin="0">
		<titleStyle font="Arial-16-bold"/>
		<labelStyle isHideOverlapped="false" orientation="Horizontal"/>
	</yAxis>
	<elements action="" shape="Area" drawOutline="false">
		<morph morph="grow"/>
	</elements>
</framechart>
</cfsavecontent>
<h2>chart with dynamic height and custom style to prevent label overlap and multiline labels:</h2>
<cfchart
	style="#chartstyle#"
	format="flash"
	font="Arial"
	fontbold="no"
	fontsize="12"
	showxgridlines="yes"
	showygridlines="no"
	chartwidth="480" 
	chartheight="#(q.recordcount*10+50)*2#"
	showlegend="no"
	showborder="no"> 
	<cfchartseries type="horizontalbar"
		query="q" 
		valuecolumn="ttl" 
		itemcolumn="name"
		seriescolor="009fda"
		paintstyle="plain" />
</cfchart>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LmillardAuthor Commented:
Quality repsonse. Thanks very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.