limit x axis for cfchart

1k views Asked by At

I would like to limit the x-axis of my chart that is created by cfchart. I see the attribute scaleFrom and scaleTo that limit the y-axis, but I see nothing that limits the x-axis.

Also, I saw a similar question here: ColdFusion Chart x-axis label limits but neither of the answers were appropriate. ScaleMin and ScaleMax do not exists as far as I can tell and the other answer is more complicated than what I'd like to do.

1

There are 1 answers

0
Leigh On

The scaleMin and scaleMax attributes Saul mentioned are only available when using a custom style. Note, using type "scale" means your xAxis values must be numeric. If you want to use strings, you will probably need to use Ben's approach instead.

Here is a quick example that creates a chart with 24 points on the xAxis. Even though the query only contains the first six (6) points.

<!--- bare bones style --->
<cfsavecontent variable="style">
<?xml version="1.0" encoding="UTF-8"?>
<frameChart is3D="false" isInterpolated="true">
    <frame xDepth="3" yDepth="1" />
    <xAxis type="Scale" scaleMin="0" scaleMax="24" labelCount="25" isBucketed="false" />
</frameChart>
</cfsavecontent>


<!--- sample query --->
<cfset qry = queryNew("")>
<cfset queryAddColumn(qry, "xValue", listToArray("1,2,3,4,5,6"))>
<cfset queryAddColumn(qry, "yValue", listToArray("30,15,22,14,45,5"))>

<!--- chart code --->
<cfchart format="jpg" style="#style#" width="600">
    <cfchartseries type="line" 
        markerstyle="circle"
        query="qry"
        itemColumn="xValue"
        valueColumn="yValue" /> 
</cfchart>