Coldfusion cfchart積層序
-
27-09-2019 - |
質問
私はカップルでの問合せに引きでの使用のためにデータをグラフにすることが出来ます。
<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>
それは私に以下のグラフ
どうやっていけばいいですか?データの表示順にソートの合計の積み重ねかね。
@Ben
とっと軌道にのビーチに位置した前四半期かがみ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>
解決
最も簡単な方法は、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>
私はこれをテストしていないので、少し調整する必要があるかもしれません。
これで、グラフのデータ列として2つの紹介列を使用できるはずです。
他のヒント
たぶん、日付でのみフィルタリングを使用して中間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
そもそも、既に適用されている日付ごとにフィルタリングをドロップします。
とは思わないできずに出力するクエリを構成してソートでの出力をデータからのcfchartdataタグ内の各cfchartseries.
のようなことも参考になり嬉しいです。かったこの地域で、そうなコードで変換する作業にお問い合わせやカラム名ですが動作しない可能性がありoff直にコピー-ペーストです。もう!) でもこの長さは二つのクエリは常に同じでなければならない。そのちょっと違うんですがコードす。
<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>
所属していません StackOverflow