coldfusioncfchartcfoutput

ColdFusion 9 CFCHART CFCHARTSERIES Issue


I'm displaying a chart with one or more line series. The data comes from a query and works correctly if there is more than on series on the chart. However, if only one series is returned it is not displaying correctly.

Here's the code used:

<cfchart format="flash" tipstyle="mouseover" showlegend="yes" xaxistitle="Date" yaxistitle="Hits" chartwidth="1200" chartheight="300">
    <cfoutput query="qryReport" group="APP_SYS_NR">
        <cfchartseries serieslabel="#qryReport.APP_NA#" type="line">
        <cfoutput>
            <cfchartdata item="#DateFormat(qryReport.CDR_DT, "mm/dd/yyyy")#" value="#qryReport.TOT_HIT_CNT#">               
        </cfoutput>
        </cfchartseries>
    </cfoutput>
</cfchart>

The blacked out area at the top of this chart lists the keys for what the two lines represent: Working Chart

In this chart (when there is only one APP_SYS_NR returned), instead of only having a single label, all the dates are turned into labels. Obviously not what I want: Broken Chart

Edit: I've traced this to the showlegend attribute of cfchart. According to Adobe, it's whether to display the legend if the chart contains more than one data series. I guess when it contains only one data series, it completely craps itself and does the data points in the legend. I tested on ColdFusion 9 and ColdFusion 10.


Solution

  • The solution here is to set showlegend to no when there is only a single series to display. Instead you should use a chart title in that instance. See the following modified code:

    <cfset VARIABLES.blnShowLegend = "no">
    <cfset VARIABLES.strChartTitle = "#qryReport.APP_NA#">
    <cfif ListLen(URL.lstApps) GT 1>
        <cfset VARIABLES.blnShowLegend = "yes">
        <cfset VARIABLES.strChartTitle = "">
    </cfif>
    <cfchart format="flash" title="#VARIABLES.strChartTitle#" tipstyle="mouseover" style="appstats" showlegend="#VARIABLES.blnShowLegend#" xaxistitle="Date" yaxistitle="Hits" chartwidth="1200" chartheight="300">
        <cfoutput query="qryReport" group="APP_SYS_NR">
            <cfchartseries serieslabel="#qryReport.APP_NA#" type="line">
            <cfoutput>
                <cfchartdata item="#DateFormat(qryReport.CDR_DT, "mm/dd/yyyy")#" value="#qryReport.TOT_HIT_CNT#">               
            </cfoutput>
            </cfchartseries>
        </cfoutput>
    </cfchart>