Skip to main content
Inspiring
November 28, 2012
Question

Chart more than one query field.

  • November 28, 2012
  • 1 reply
  • 821 views

Hello I am creating a chart that will display two bar for each item colum. I can get one (the t3 bar) to display ok but I do not understand how to layout the second set of bars for the graph.  Thank you

Here is what i got so far.

<!---master query--->

<cfquery name="master" datasource="cfpMeasure">

   select Region,SUM(t1) as T1,SUM(t1unpaved) as T1Unpaved,
SUM(t2) as T2,SUM(t2unpaved) as T2Unpaved,
SUM(t3) as T3,SUM(t3unpaved) as T3Unpaved,
SUM(t4) as T4, SUM(t4Unpaved) as T4Unpaved,
SUM(t5) as T5, SUM(T5Unpaved) as T5Unpaved
from dbo.vp_MilesByTRC

group by Region

   </cfquery>

<!---Queries of Queries--->

    

<cfquery name="ps" dbtype="query">
select Region,SUM(t3) as T3,SUM(t1unpaved) as T3Unpaved FROM MASTER
where region ='PS'
group by region
</cfquery>

<cfquery name="ne" dbtype="query">
select Region,SUM(t3) as T3,SUM(t1unpaved) as T3Unpaved FROM MASTER
where region ='NE'
group by region
</cfquery>


<cfquery name="Sw" dbtype="query">
select Region,SUM(t3) as T3,SUM(t1unpaved) as T3Unpaved FROM MASTER
where region ='SW'
group by region
</cfquery>


<cfquery name="SE" dbtype="query">
select Region,SUM(t3) as T3,SUM(t1unpaved) as T3Unpaved FROM MASTER
where region ='SE'
group by region
</cfquery>

<!---Chart--->  The chart displays one bar (t3)

                                        How do I get the t3unpaved bar to display next to the t3 bar for each region. ?

<cfchart fontsize="14" fontbold="yes" format="jpg" chartheight="275" chartwidth="335" scalefrom="0" showborder="yes" xaxistitle="T3" yaxistitle="Miles" title="T3 Truck Route Miles by Region" showlegend="yes" scaleto="100" seriesplacement="cluster">

<cfchartseries type="bar" query="nw" itemcolumn="Region" valuecolumn="t3"  serieslabel="NW " seriescolor="000099" markerstyle="circle" />
                   
                    <cfchartseries type="bar" query="ps" itemcolumn="Region" valuecolumn="t3"  serieslabel="PS " seriescolor="993333" markerstyle="circle" />
                    <cfchartseries type="bar" query="ne" itemcolumn="Region" valuecolumn="t3"  serieslabel="NE " seriescolor="FF0000" markerstyle="circle" />
                    <cfchartseries type="bar" query="sw" itemcolumn="Region" valuecolumn="t3"  serieslabel="SW " seriescolor="517488" markerstyle="circle" />
                    <cfchartseries type="bar" query="se" itemcolumn="Region" valuecolumn="t3"  serieslabel="SE " seriescolor="FF9966" markerstyle="circle" />

                  </cfchart>

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
December 2, 2012

You should get a chart with clusters of 5 bars. I wonder why you expect just 2 bars for each item.

To recreate your example, I went to the Adobe documentation and copied their examples. I added attributes borrowed from your example. I successfully got clusters of 4 bars, no sweat. My test code follows. You, too, can run it directly, as the datasource cfdocexamples comes with ColdFusion.

<cfquery name="GetSalaryDetails" datasource="cfdocexamples">

    SELECT Departmt.Dept_Name,

        Employee.FirstName,

        Employee.LastName,

        Employee.StartDate,

        Employee.Salary,

        Employee.Contract

    FROM Departmt, Employee

    WHERE  Departmt.Dept_ID = Employee.Dept_ID

    ORDER BY Employee.LastName, Employee.Firstname

</cfquery>

<cfquery dbtype = "query" name = "aggregates">

    SELECT Dept_Name,

    AVG(Salary) AS avgSal,

    SUM(Salary) AS sumSal

    FROM GetSalaryDetails

    GROUP BY Dept_Name

</cfquery>

<cfchart

        backgroundColor="white"

        xAxisTitle="Department"

        yAxisTitle="Salary Average"

        font="Arial"

        gridlines=6

        showXGridlines="yes"

        showYGridlines="yes"

        showborder="yes"

        seriesPlacement="cluster"

    >

        <cfchartseries

        type="bar"

        query="aggregates"

        valueColumn="avgSal"

        itemColumn="Dept_Name"

        paintStyle="plain"

        seriesLabel="Dept. Average Salaries"

         seriescolor="993333" markerstyle="circle">

        

    <cfchartseries

        type="bar"

        query="aggregates"

        valueColumn="avgSal"

        itemColumn="Dept_Name"

        paintStyle="plain"

        seriesLabel="Dept. Average Salaries"

         seriescolor="FF0000" markerstyle="circle">

<cfchartseries

        type="bar"

        query="aggregates"

        valueColumn="avgSal"

        itemColumn="Dept_Name"

        paintStyle="plain"

        seriesLabel="Dept. Average Salaries"

         seriescolor="517488" markerstyle="circle">

    <cfchartseries

        type="bar"

        query="aggregates"

        valueColumn="avgSal"

        itemColumn="Dept_Name"

        paintStyle="plain"

        seriesLabel="Dept. Average Salaries"

        seriescolor="FF9966" markerstyle="circle">

</cfchart>