Displaying data from multiple queries in a single pie chart using cfchart tag

本小妞迷上赌 提交于 2019-12-02 11:43:10

(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>

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))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!