0

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. chart showing 6 bars in all 3 groups

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>

enter image description here

gordon
  • 1,152
  • 1
  • 12
  • 18
  • Truthfully what I really want to do is loop through `ra` and display the values of the 3 interior arrays as 3 grouped bars but it seems cfchart will only take the 1st element of each group, then the 2nd element of each group, and so on. If I process each of ra's 3 interior arrays as individual charts I get what I want - a chart with a set of 3 bars, a chart with 6 bars and a chart of 4 bars. – gordon Jun 27 '16 at 18:39
  • Moderators - I'd like to add tags cfchartseries and cfchart-grouping but they don't exist and I don't have 1500 point to create them. Does this post look like it merits your creating and adding these tags to the post for me? Thank you in advance – gordon Jun 27 '16 at 18:45
  • cfchart is counterintuitive - this does not work, gives 6 groups of 3 bars ` ` – gordon Jun 27 '16 at 18:56
  • OK, what I ended up doing was pre-building an independent array with all the `[ [item1, value1],[item2, value2],...,[itemN, valueN] ]`. CfChart was still trying to fix what wasn't broken when it detected patterns in the items so I had to add a counter looping through the final array and prefix the displayed item with the counter. OMG ChChart is such a freakin overwrought add-in. – gordon Jun 29 '16 at 16:53

0 Answers0