Coldfusion cfchart 堆叠顺序

发布于 2024-09-26 06:27:31 字数 2436 浏览 1 评论 0原文

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

<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 可以结合 2 个完全不同的查询

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

I have a couple of queries which pull data for use in a graph.

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

The graph code is

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

this gives me the following graph

alt text

How do I get the data displayed sorted by the total of the stacked elements?

@ Ben

That got me on the right track, I didnt previously know QOQ could combine 2 completely different queries

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟织青萝梦 2024-10-03 06:27:31

最简单的方法是使用 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 列作为图表的数据列。

The simplest way would be to use a 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>

I've not tested this, so you may need to tweak it a little.

Now, you should be able to use the two Referrals columns as the data columns for the graph.

秉烛思 2024-10-03 06:27:31

也许添加中间 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 排序,删除已应用的按日期过滤。

Maybe add intermediate QoQ with filtering only by date? Something like this (can not test, so it may need some fixes):

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

After that update your existing queries to include select from clusterCombinedReferrals and order by totalMsgCount at first place, also drop the filtering by date as it already applied.

又怨 2024-10-03 06:27:31

我认为如果不首先将查询输出到结构,然后对其进行排序并使用每个 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>

I don't think you can without first outputting the queries to a structure and then sorting it and outputting the data from that with the cfchartdata tag inside each cfchartseries.

Something like this, maybe. I did this locally and it worked, but then I tried to convert the code to work with your queries and column names, so it might not work off a straight copy and paste. (But it might!) It also assumes that the length of the two queries will always be the same. If that isn't true, you might need to code around that.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文