Reputation: 1585
Please consider the following code, right now I have the following code in my .cfm
page inside the <body>
tag:
DataSource = xx.xx.x.xx
Name of the database = sgemail
Name of the relevant column = event_vc
Basically I have calculated the percentage of the open connections in the following queries.
<cfquery datasource = "xx.xx.x.xx" name="qSen">
SELECT (select count(*)
FROM sgemail) AS TOTAL_CONNECTIONS,
(SELECT count(*)
FROM sgemail
WHERE event_vc = "open") AS OPEN_CONNECTIONS,
(ROUND((SELECT OPEN_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "% OPEN" ;
</cfquery>
<cfquery datasource = "xx.xx.x.xx" name="qSen">
SELECT (select count(*) from sgemail) AS TOTAL_CONNECTIONS,
(SELECT count(*) from sgemail where event_vc = "BOUNCE") AS BOUNCE_CONNECTIONS,
(ROUND((SELECT BOUNCE_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "% BOUNCE" ;
</cfquery>
Basically "% OPEN"
and `"% BOUNCE" are used to display the percentage of connections open and bounce from the database.
I have included the following <cfchart>
tag below the above <cfquery>
tag as follows:
<cfchart
format="png"
scalefrom="0"
scaleto="1200000"
pieslicestyle="solid">
<cfchartseries
type="pie"
serieslabel="Website Traffic 2006"
seriescolor="blue"
query = "qSengrid"
valuecolumn="% OPEN"
itemcolumn=""
>
</cfchartseries>
</cfchart>
My Questions:
1) The thing is that the above chart is displaying only one circle with yellow color. I want to display the information retrieved by both the queries in one chart. For example
the value I'm getting for %OPEN
is 30 and value I'm getting for %Bounce
is 20. I have other queries as well which return different values which makes the whole pie chart
to 100 but I have included only two cfqueries for the sake of simplicity for this question. Please let me know how to proceed further.
2) Also, when I commented out the second query (where I'm getting % Bounce
value), I can see the value of %OPEN
next to the circle of the pie-chart. However, when I run both
the queries with only one <cfchart>
mentioned above (with valuecolumn = %OPEN
) I can't see any value written next to the circle.
Please answer my above questions and let me know if there are any questions I can answer.
Upvotes: 0
Views: 906
Reputation: 28873
(From the comments)
By using reusing the same query name, you are most likely overwriting the previous results. In addition, that is not how <cfchartseries query="...">
works. It accepts a single query, which means all of the values must be contained in the same query.
If you must use separate queries, give each query a unique name and a use separate <cfchartdata>
tag for each value:
<cfchart format="png">
<cfchartseries type="pie">
<cfchartdata item="% Open" value="#qTotalOpen.TotalNumber#">
<cfchartdata item="% Bounce" value="#qTotalBounced.TotalNumber#">
... other values ...
</cfchartseries>
</cfchart>
Upvotes: 2
Reputation: 26353
I don't know ColdFusion, but it looks like the issue is getting the % Open
and % Bounce
values into the same result set. Based on your markup examples, I think your result needs to look something like this (I made up the column names):
theitem thevalue
--------- --------
% OPEN 40
% BOUNCE 23
Then your markup in <cfcchart>
would go something like this:
<cfchartseries
type="pie"
serieslabel="Website Traffic 2006"
seriescolor="blue"
query = "qSengrid"
valuecolumn="thevalue"
itemcolumn="theitem"
>
If that's the case (and remember I'm guessing here because nobody else has posted an answer yet), then the accompanying query would look like this:
SELECT
CONCAT('% ', UPPER(sgemail.event_vc)) AS theitem,
COUNT(*) / tots.totconn AS thevalue
FROM
sgemail,
(SELECT COUNT(*) AS totconn
FROM sgemail
WHERE event_vc IN ('open', 'bounce')) tots
WHERE tots.totconn <> 0
AND sgemail.event_vc IN ('open', 'bounce')
GROUP BY CONCAT('% ', UPPER(sgemail.event_vc))
The query is a bit involved because it's calculating percentages for a subset of event_vc
values, plus it's guarding against a divide by zero error. If the chart can take straight counts and convert them to percentages, the query for "counts only" is a lot simpler:
SELECT
CONCAT('% ', UPPER(sgemail.event_vc)) AS theitem,
COUNT(*) / tots.totconn AS thevalue
FROM sgemail
WHERE sgemail.event_vc IN ('open', 'bounce')
GROUP BY CONCAT('% ', UPPER(sgemail.event_vc))
Upvotes: 1