Coldfusion cfchart堆叠顺序

时间:2010-10-03 20:27:53

标签: coldfusion stacked cfchart

我有几个查询可以提取数据以供图表使用。

<cfquery name='clusterPrivateReferrals'  dbtype="query">
SELECT organisationName, count(messageID)*1000/listSize as msgCount
FROM clusterReferrals
WHERE datecreated>#refRateStartDate#
AND refTypeID=3
GROUP BY organisationName, listSize
</cfquery>

<cfquery name='clusterNHSReferrals'  dbtype="query">
SELECT organisationName, count(messageID)*1000/listSize as msgCount
FROM clusterReferrals
WHERE datecreated>#refRateStartDate#
AND refTypeID<>3
GROUP BY organisationName, listSize
</cfquery>

图表代码是

<cfchart format="flash" title="Cluster referrals per 1000 patients from #dateformat(refRateStartDate, 'dd-mmm-yy')#" chartWidth="470" chartHeight="380" fontSize="12" style="chart.xml" seriesPlacement = "stacked" showLegend = "yes">
    <cfchartseries type="bar" seriescolor="##FFD800" seriesLabel="Private" query="clusterPrivateReferrals" valueColumn="msgCount" ItemColumn="organisationName">
    </cfchartseries>
    <cfchartseries type="bar" seriescolor="##F47D30" seriesLabel="NHS" query="clusterNHSReferrals" valueColumn="msgCount" ItemColumn="organisationName">
    </cfchartseries>
</cfchart>

这给了我以下图表

alt text

如何显示按堆叠元素总数排序的数据?

@ Ben

这让我走上正轨,我之前并不知道QOQ可以合并两个完全不同的查询

<cfquery name='clusterPrivateReferrals'  dbtype="query">
SELECT organisationName, count(messageID)*1000/listSize as privateRate
FROM allReferrals
WHERE datecreated>#refRateStartDate#
AND refTypeID=3
GROUP BY organisationName, listSize
</cfquery>

<cfquery name='clusterNHSReferrals'  dbtype="query">
SELECT organisationName, count(messageID)*1000/listSize as nhsRate
FROM allReferrals
WHERE datecreated>#refRateStartDate#
AND refTypeID<>3
GROUP BY organisationName, listSize
</cfquery>

<cfquery name="stackOrder" dbtype="query">
    select clusterPrivateReferrals.privateRate,
        clusterNHSReferrals.nhsRate,
        clusterPrivateReferrals.organisationName,
        (clusterPrivateReferrals.privateRate + clusterNHSReferrals.nhsRate) as totalRate
    from clusterPrivateReferrals, clusterNHSReferrals
    WHERE clusterNHSReferrals.organisationName = clusterPrivateReferrals.organisationName
    order by totalRate desc
</cfquery> 

3 个答案:

答案 0 :(得分:2)

最简单的方法是使用QofQ:

<cfquery name="stackOrder" dbtype="query">
    select clusterPrivateReferrals.msgCount as privateReferrals,
        clusterNHSReferrals.msgCount as NHSReferrals,
        clusterPrivateReferrals.organizationName
    from clusterPrivateReferrals
    join clusterNHSReferrals on clusterNHSReferrals.organizationName = clusterPrivateReferrals.organizationName
    order by (privateReferrals+privateReferrals) desc
</cfquery>

我没有对此进行测试,因此您可能需要对其进行一些调整。

现在,您应该可以使用两个Referrals列作为图表的数据列。

答案 1 :(得分:0)

也许添加中间QoQ只按日期过滤?像这样的东西(不能测试,所以它可能需要一些修复):

<cfquery name='clusterCombinedReferrals'  dbtype="query">
SELECT organisationName, messageID, listSize, count(messageID)*1000/listSize as totalMsgCount
FROM clusterReferrals
WHERE datecreated>#refRateStartDate#
GROUP BY organisationName, listSize
</cfquery>

更新您现有的查询以包括从clusterCombinedReferrals中选择并在第一时间按totalMsgCount排序时,也会按照已应用的日期删除过滤。

答案 2 :(得分:0)

我认为如果没有先将查询输出到结构中然后对其进行排序并使用每个cfchartseries中的cfchartdata标记输出数据,我认为你无法做到。

也许这样的事情。我在本地做了这个并且它有效,但后来我尝试将代码转换为使用您的查询和列名,因此它可能无法直接复制和粘贴。 (但它可能!)它还假设两个查询的长度始终相同。如果不是这样,您可能需要围绕它进行编码。

<cfset data = {}>

<cfloop from="1" to="#clusterPrivateReferrals.recordCount#" index="x">

  <cfset structInsert(data, clusterPrivateReferrals["organisationName"][x], {})>

  <cfset data['#clusterPrivateReferrals["organisationName"][x]#'].private = clusterPrivateReferrals["msgCount"][x]>

  <cfset data['#clusterNHSReferrals["organisationName"][x]#'].nhs = clusterPrivateReferrals["msgCount"][x]>

  <cfset data['#clusterPrivateReferrals["organisationName"][x]#'].total = data['#clusterNHSReferrals["organisationName"][x]#'].private + data['#clusterNHSReferrals["organisationName"][x]#'].nhs>

</cfloop>

<cfset sorted = structSort(data, "numeric", "desc", "total")>

<cfchart format="flash" title="data" chartWidth="470" chartHeight="380" fontSize="12" seriesPlacement = "stacked" showLegend = "yes">

    <cfchartseries type="bar" seriescolor="##FFD800" seriesLabel="Private">
        <cfloop from="1" to="#arrayLen(datas)#" index="x">
            <cfchartdata item="#sorted[x]#" value="#data['#sorted[x]#'].private#">
        </cfloop>
    </cfchartseries>

    <cfchartseries type="bar" seriescolor="##F47D30" seriesLabel="NHS">
        <cfloop from="1" to="#arrayLen(datas)#" index="x">
            <cfchartdata item="#sorted[x]#" value="#data['#sorted[x]#'].nhs#">
        </cfloop>
    </cfchartseries>

</cfchart>