Domanda

Ho un paio di domande che tirano i dati per l'utilizzo in un grafico.

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

Il codice grafico è

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

questo mi dà il seguente grafico

alt text

Come faccio a ottenere i dati visualizzati in ordine per il totale degli elementi sovrapposti?

@ Ben

Questo mi ha sulla strada giusta, non ho in precedenza so QOQ potrebbe combinare 2 domande completamente diverse

<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> 
È stato utile?

Soluzione

Il modo più semplice sarebbe quella di utilizzare un 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>

Non ho testato questo, quindi potrebbe essere necessario modificarlo un po '.

Ora, si dovrebbe essere in grado di utilizzare le due colonne rinvii le colonne di dati per il grafico.

Altri suggerimenti

Forse aggiungere intermedia su base trimestrale con il filtraggio solo in base alla data? Qualcosa di simile (non può di prova, quindi potrebbe avere bisogno di alcune correzioni):

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

Dopo che l'aggiornamento esistente per includere le query selezionare da clusterCombinedReferrals e l'ordine da totalMsgCount al primo posto, cadere anche il filtraggio in base alla data in quanto già applicata.

Non credo che si può senza prima emettere le query ad una struttura e quindi l'ordinamento e l'emissione dei dati da quella con il tag cfchartdata all'interno di ogni cfchartseries.

Qualcosa di simile, forse. Ho fatto questo a livello locale e ha funzionato, ma poi ho provato a convertire il codice per lavorare con le vostre domande e nomi di colonna, quindi potrebbe non funzionare fuori una copia dritto e incollare. (Ma potrebbe!) Si presuppone inoltre che la lunghezza delle due query sarà sempre lo stesso. Se questo non è vero, potrebbe essere necessario il codice intorno a quello.

<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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top