Skip to main content
Known Participant
March 16, 2017
Question

cfchart output by month

  • March 16, 2017
  • 2 replies
  • 745 views

I'm using CF10.

I want to output a count of events by the month they happened each.

Each month will always have at least 1 event, so I'm not worried about months with 0.

This is showing me the 12 months in order, but adding them up.

The query is retrieving records back through the last 3 years.

Where did I go wrong?

I want to show the months in order for the last three years.

<cfquery Name="OccOpenChart" datasource="#APPLICATION.DSN#">

SELECT

  COUNT(OccurrenceNumber) As OccTotal,

    year(DateofReport) as OccYear,

    month(DateofReport) as Occmonth

  FROM OccurrenceDateTracking

  WHERE Year(DateofReport) > #thisyear#

  GROUP BY year(DateofReport), month(DateofReport)

</cfquery>

<cfchart

  format="png"

  chartwidth="750"

  chartheight="500"

  showlegend="yes"

  xaxistitle="Year of Report"

  yaxistitle="Occurrence Count"

  show3d="no"

  tipstyle="none"

  fontsize="12">

      <cfchartseries

  type="bar"

  query="OccOpenChart"

  dataLabelStyle="value"

  itemcolumn="Occmonth"

  valuecolumn="OccTotal"

  serieslabel="Total" />

    This topic has been closed for replies.

    2 replies

    EddieLotter
    Inspiring
    March 17, 2017

    bloodbanker  wrote

    I want to show the months in order for the last three years.

    By this do you mean that you want to see the three Januaries first, then the three Februaries etc.?

    If so, then you need to switch the expressions in your Group By clause.

    Cheers

    Eddie

    Known Participant
    March 17, 2017

    Sorry.

    Let's say it was the last three calendar years.

    I want to display jan - december of 2015  followed by jan-dec 2016 followed by jan - mar 2017.

    EddieLotter
    Inspiring
    March 17, 2017

    In that case try switching the expressions in your Group By clause and see if you get what you want. If not, try adding an Order By clause. Some database engines will allow an Order By clause that has a different column order from the Group By clause.

    Cheers

    Eddie

    EddieLotter
    Inspiring
    March 17, 2017

    Do the following and post the result:

    <cfdump var="#OccOpenChart#">

    Cheers

    Eddie

    Known Participant
    March 17, 2017

    EddieLotter  wrote

    Do the following and post the result:

    <cfdump var="#OccOpenChart#">

    Cheers

    Eddie

    query
    RESULTSET
    query
    OCCMONTHOCCTOTALOCCYEAR
    11352015
    21532016
    31422017
    42282015
    52372016
    62432017
    73232015
    83372016
    93182017
    104282015
    114462016
    125342015
    135702016
    146322015
    156532016
    167292015
    177462016
    188362015
    198512016
    209402015
    219302016
    2210342015
    2310432016
    2411402015
    2511442016
    2612342015
    2712442016
    CACHEDfalse
    EXECUTIONTIME15
    SQLSELECT COUNT(OccurrenceNumber) As OccTotal, year(DateofReport) as OccYear, month(DateofReport) as Occmonth FROM OccurrenceDateTracking WHERE Year(DateofReport) > 2014 GROUP BY year(DateofReport), month(DateofReport)

    Here's a screenshot of the page