CFCHART with dates
I am having a problem with getting dates to line up in the appropriate order in a CFCHART from 3 different queries. In other words, August dates might come before July dates on the chart. Ideally I would like to have these 3 queries as one query because the records I am accessing are all in the same table. That can be battle for another day once I resolve this issue. Hints would be helpful on the query dilemma.
Just a little background:
- MSSQL database
- ColdFusion 9
- Each record has 3 bit datatype fields and a timestamp datatype field.
What I am trying to do is loop over the selected records and count each bit that is 'true'. Here is what I have.
<!--- Get record bit 1 --->
<cfquery ="Datasource" name="record1q" cachedwithin="#CreateTimeSpan(0, 0, 10, 0)#">
SELECT Month(myDate) AS DateMonth, Day(myDate) AS recordDate,
Year(myDate) AS DateYear, COUNT(record1bit) AS record1bitCount
FROM myTable
WHERE record1bit = 'true'
GROUP BY Month(myDate), Day(myDate), Year(myDate), record1bit
</cfquery>
<!--- Get record bit 2 --->
<cfquery ="Datasource" name="record2q">
SELECT Month(myDate) AS DateMonth, Day(myDate) AS recordDate,
Year(myDate) AS DateYear, COUNT(record2bit) AS record2bitCount
FROM myTable
WHERE record2bit = 'true'
GROUP BY Month(myDate), Day(myDate), Year(myDate), record2bit
</cfquery>
<!--- Get record bit 3 --->
<cfquery ="Datasource" name="record3q">
SELECT Month(myDate) AS DateMonth, Day(myDate) AS recordDate,
Year(myDate) AS DateYear, COUNT(record3bit) AS record2bitCount,
record3bit
FROM myTable
WHERE record3bit = 'true'
GROUP BY Month(myDate), Day(myDate), Year(myDate), record2bit, record3bit
</cfquery>
<!--- Reformat the generated numbers. --->
<cfloop index = "i" from = "1" to = "#record1q.RecordCount#">
<cfset record1q.record1bitCount = record1q.record1bitCount>
<cfset record1q.recordDate = record1q.DateMonth & "/" & record1q.recordDate & "/" & record1q.DateYear>
</cfloop>
<!--- Reformat the generated numbers. --->
<cfloop index = "i" from = "1" to = "#record2q.RecordCount#">
<cfset record2q.record2bitCount = record2q.record2bitCount>
<cfset record2q.recordDate = record2q.DateMonth & "/" & record2q.recordDate & "/" & record2q.DateYear>
</cfloop>
<!--- Reformat the generated numbers. --->
<cfloop index = "i" from = "1" to = "#record3q.RecordCount#">
<cfset record3q.record2bitCount = record3q.record2bitCount>
<cfset record3q.recordDate = record3q.DateMonth & "/" & record3q.recordDate & "/" & record3q.DateYear>
</cfloop>
<cfchart showlegend="yes"
format="flash"
backgroundColor="white"
xAxisTitle="Date"
yAxisTitle="Activity"
font="Arial"
gridlines=6
showXGridlines="yes"
showYGridlines="yes"
showborder="yes"
show3d="yes"
chartwidth="500" title="Total Views and Shares"
>
<cfchartseries
type="bar"
query="record1q"
valueColumn="record1bitCount"
itemColumn="recordDate"
seriesColor="gray"
paintStyle="plain"
seriesLabel="record1bit">
</cfchartseries>
<cfchartseries
type="bar"
query="record2q"
valueColumn="record2bitCount"
itemColumn="recordDate"
seriescolor="FF9900"
paintStyle="plain"
seriesLabel="record2bit">
</cfchartseries>
<cfchartseries
type="bar"
query="record3q"
valueColumn="record2bitCount"
itemColumn="recordDate"
seriescolor="000099"
paintStyle="plain"
seriesLabel="record3qbit Viewed">
</cfchartseries>
</cfchart>
I know it is a little sloppy but it is a good start. Any help will be appreciated.
