Link to home
Start Free TrialLog in
Avatar of myabko
myabkoFlag for Canada

asked on

displaying percentages in pie charts

Hi Experts,

I'm trying to create a chart which counts two seperate entries on the same database table, and then outputs the values as a pie chart. I'm a total noob when it comes to coldfusion, although I did manage to get the following to some something similar to what i'd want (see code below).

A few things though:
1) the cfsets within the cfoutput seems like a messy hack to me, is there a better way to approach getting those values from the database?
2) I would like to get the value from count, as well as the percentage comparing the two values. is this possible?

Thanks,

Mike

<cfquery name="MCount" datasource="reporting_db" >
    SELECT Count(*) as Mer from printer_orderwhere Printer_Number_FK = 2;
    </cfquery>
    <cfoutput query="MCount"> <cfset Mercount = Mer></cfoutput>
    
    <cfquery name="DGCount" datasource="reporting_db" >
    SELECT Count(*) as DG from printer_order where Printer_Number_FK = 1;
    </cfquery>
    <cfoutput query="DGCount"> <cfset DCount = DG></cfoutput>
 
    <cfchart show3d="Yes">
      <cfchartseries type="pie">
        <cfchartdata item="Orders To M" value=#MerCount#>
        <cfchartdata item="Orders To DG" value=#DCount#>
        </cfchartseries>
        </cfchart>

Open in new window

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Check this:
<cfquery name="MCount" datasource="reporting_db" >
    SELECT Count(*) as MerCount from printer_orderwhere Printer_Number_FK = 2;
</cfquery>
<cfquery name="DGCount" datasource="reporting_db" >
    SELECT Count(*) as DCount from printer_order where Printer_Number_FK = 1;
</cfquery>
<cfchart show3d="Yes">
  <cfchartseries type="pie">
    <cfchartdata item="Orders To M" value=#MerCount#>
    <cfchartdata item="Orders To DG" value=#DCount#>
  </cfchartseries>
</cfchart>

Open in new window

Only for demo how to reference cfquery items without cfoutput:

<cfquery name="MCount" datasource="reporting_db" >
    SELECT Count(*) as Mer from printer_orderwhere Printer_Number_FK = 2;
</cfquery>
<cfset Mercount = MCount.Mer >

One more note.
Because the result set is a set of records you can access your single row also by index:
<cfquery name="MCount" datasource="reporting_db" >
    SELECT Count(*) as Mer from printer_orderwhere Printer_Number_FK = 2;
</cfquery>
<cfset Mercount = MCount.Mer[1] >
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of myabko

ASKER

One more thing, is it possible to not include one of the values from the graph into the list of values for the pattern style label?

For example I have a bar chart which has three values within the series:
1) total
2) MerTotal
3) DGTotal

i would like to have total display 100% while the other two display as a percentage of total, or at least not have total used within the calculation for the other two values, as it's throwing off their percentages. Is this possible?
Can you please state why you graded my solution with the grade B?
Avatar of myabko

ASKER

because it was slightly confusing in its four post format.
And you expect now support from me? I am now also "slightly confused" by your grading ;-)
Avatar of myabko

ASKER

I don't expect anything from  you. Experts exchange is supposed to be a community, you know technical people helping other technical people.

If you're in it just for points and grades so be it.
OK, you are on my B list. Cheerio.
Avatar of myabko

ASKER

I suppose you put everyone who gives you a B rating on this B list of yours?

I'd hate to see how you'd react to a solution judged less than satisfactory
A simple Thank You for my valuable time would have been enough. Now you can keep it.