coldfusioncoldfusion-9coldfusion-8cfchart

ColdFusion CFchart and feedback form


I am creating a feedback form system where users can fill in feedback forms and admin users will be able to run reports against the answers. I am trying to use cfchart to display the results in an easy to read manner for the administrators.

Here is my code:


<cfquery name="getFeedbackresults" datasource="#application.dsn#">
        SELECT  ff.feedbackFormId
           ,ff.feedbackFormName
           ,ff.feedbackFormDescription
           ,ff.activeFrom
           ,ff.activeTo
           ,ff.feedbackCountry
           ,ffq.question
           ,ffa.answer
           ,ffq.feedbackQuestionTypeId
           ,count(answer) AS distinctAnswer
      FROM  feedbackForm ff
           ,feedbackFormQuestion ffq
           ,feedbackFormInstance ffi
           ,feedbackFormAnswer ffa
     WHERE ff.feedbackFormId = ffq.feedbackFormId
       AND ff.feedbackFormId = ffi.feedbackFormId 
       AND ffi.feedbackFormInstanceId = ffa.feedbackFormInstanceId
       AND ffa.feedbackQuestionId = ffq.feedbackQuestionId
       AND ffq.feedbackQuestionTypeId not in (2,3)
  GROUP BY ff.feedbackFormId, ff.feedbackFormName, ff.feedbackFormDescription, ff.feedbackCountry, ffq.question, ff.activeFrom, ffq.feedbackQuestionTypeId, ff.activeTo, ffa.answer
  ORDER BY question

</cfquery>

<cfoutput>
    <h2>#getFeedbackresults.feedbackFormName# Results</h2>
        <h3>Description:
            <p>#getFeedbackresults.feedbackFormDescription#</p>
            <ul>
                <li><strong>Active From: </strong>#getFeedbackresults.activeFrom#</li>
                <li><strong>Active To: </strong>#getFeedbackresults.activeTo#</li>
                <li><strong>Country: </strong>#getFeedbackresults.feedbackCountry#</li>
            </ul>
</cfoutput>

<cfdump var="#getFeedbackresults#">

<cfchart format="flash" xaxistitle="Questions" yaxistitle="Answers" show3d="yes" chartheight="400" chartwidth="400"> 
    <cfoutput query="getFeedbackresults" group="answer">
        <cfchartseries type="bar" serieslabel="#answer#">
            <cfchartdata item="#question#" value="#distinctAnswer#"> 
        </cfchartseries>
    </cfoutput>
</cfchart>

The problem I am having is that the chart is displaying each list of answers in every series. I tried to upload an image but as I am a new user I'm not allowed. If anyone would like the image I can send it to them.

Any help would be greatfully appreciated.


Solution

  • You need to sort your query by the answer column if that's what you're going to group by. Your current ORDER BY is "question". Once you're sorting the same value that you're using for the group attribute on your cfoutput, you should be good to go.