I'm using cfchart/cfchartseries and I have several groups of data that relate to each other so I want to display the groups in one chart. I find that the count of data points for each group apparently has to be the same? If not cfchart just pads the shorter groups with bars from the longest:
<cfset ra=[[30,20,40],[50,10,90,40,70,30],[88,72,64,81]]>
<cfset lstColors="">
<cfset ra1Cnt=0>
<cfloop array="#ra#" index="idx1">
<cfset ra1Cnt=ra1Cnt+1>
<cfif ra1Cnt eq 1><cfset raColor=["44","99"]>
<cfelseif ra1Cnt eq 2><cfset raColor=["88","66"]>
<cfelseif ra1Cnt eq 3><cfset raColor=["BB","33"]>
</cfif>
<cfloop array="#idx1#" index="idx2"><cfset lstColors=listAppend(lstColors, "###formatBaseN(255*(100-idx2)/100, 16)##raColor[1]##raColor[2]#")></cfloop>
<cfset lstColors=listAppend(lstColors, "##FFFFFF")>
</cfloop>
<cfchart format="png"
backgroundcolor ="##eeeeee"
chartheight="270"
chartwidth="450"
labelformat="number"
scaleto="100"
xoffset=".020"
yoffset=".020"
>
<cfloop from="1" to="6" index="ix">
<cfchartseries serieslabel="#chr(ix+75)#" type="bar" colorlist="#lstColors#">
<cfloop from="1" to="#arraylen(ra)#" index="iy"><cfif arraylen(ra[iy]) gte ix>
<cfchartdata item="#chr(iy+65)#" value="#ra[iy][ix]#">
</cfif></cfloop>
</cfchartseries>
</cfloop>
</cfchart>
I would expect the <cfif><cfif>
to keep the chart from displaying bars in the first (I want only 3) and third groups (only 4), but NO! the 40, 70 and 30 get tacked on so that all groups have 6 bars.
OK, I got really vexed by this and kept picking at it, came up with the following but I don't like it - the labeling is not what I want:
<cfchartseries type="bar" colorlist="#lstColors#">
<cfset ra1Cnt=0>
<cfloop array="#ra#" index="idx1">
<cfif ra1Cnt><cfchartdata item=" " value="0"></cfif>
<cfset ra1Cnt=ra1Cnt+1>
<cfset ra2Cnt=0>
<cfloop array="#idx1#" index="idx2">
<cfset ra2Cnt=ra2Cnt+1>
<cfchartdata item="#chr(ra1Cnt+65)# #chr(ra2Cnt+75)#" value="#idx2#">
</cfloop>
</cfloop>
</cfchartseries>