Solved

displaying percentages in pie charts

Posted on 2008-06-23
12
864 Views
Last Modified: 2013-12-24
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

0
Comment
Question by:myabko
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
12 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 21862419
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

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21862434
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 >

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21862469
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] >
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 21862618
And the labels are displayed like 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" chartWidth="500" >
      <cfchartseries type="pie" dataLabelStyle="pattern" >
        <cfchartdata item="Orders To M: " value=#MerCount#>
        <cfchartdata item="Orders To DG: " value=#DCount#>
      </cfchartseries>
    </cfchart>

Open in new window

0
 

Author Comment

by:myabko
ID: 21864997
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?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21868286
Can you please state why you graded my solution with the grade B?
0
 

Author Comment

by:myabko
ID: 21869438
because it was slightly confusing in its four post format.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21870353
And you expect now support from me? I am now also "slightly confused" by your grading ;-)
0
 

Author Comment

by:myabko
ID: 21871730
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.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21871839
OK, you are on my B list. Cheerio.
0
 

Author Comment

by:myabko
ID: 21872055
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
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21872658
A simple Thank You for my valuable time would have been enough. Now you can keep it.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question