2
votes

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.

1
Please elaborate on "not display correctly". Specify what you would like to see and what you actually see.Dan Bracuk
Looks at the two charts above. It's quite obvious the second one is displaying incorrectly. It should not have all those dates listed at the top like they are a series. Instead it should look just like the first chart, but with one items listed at the top (where the blacked out portion is in the first image).Brad
Can't you just set showlegend to false? I mean... is your problem the dozens of date legend items?Mark A Kruger
Yes, I've come up with a solution. First checking to see how many applications are in the query, then setting legend to yes/no based on that. If it's no, I display a chart title with the name of the single application.Brad

1 Answers

1
votes

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>