Drawing a Pie Chart

HI,
does Java has any class for most common forms of graphs.. like
pie chart, bar chart etc...
thanx in advance

does Java has any class for most common forms of
graphs.. like
pie chart, bar chart etc...JFreeChart is a popular Open Source library for generating these types of charts. You can find out more about JFreeChart at:
http://www.object-refinery.com/jfreechart/index.html
Regards,
Dave Gilbert
JFreeChart Project Leader

Similar Messages

  • Drawing pie chart in applet

    Hi,
    The following is an applet I've written as an assignment in school. The applet runs well on appletviewer (here I mean drawing the pie chart). But when I run it on my browser, the pie chart is not drawn. Hope you can help me. Thanks in advance.
    import java.applet.*;import java.text.*;import java.awt.*;import java.awt.event.*;import java.awt.Graphics;public class x2 extends Applet implements ActionListener {               private Button draw,reset;        private TextField thigh,tmedium,tlow,tno;     private Label banner,l1, l2, l3, l4;     double rhigh,rmedium,rlow,rno;     double high, medium, low, no, total, high2=0, medium2=0, low2=0, no2=0,low3, no3;     String something="";          public void paint(Graphics g){     setBackground(Color.white);               if(something=="in"){     try {               rhigh=Double.parseDouble(thigh.getText());     rmedium=Double.parseDouble(tmedium.getText());     rlow=Double.parseDouble(tlow.getText());     rno=Double.parseDouble(tno.getText());     } catch (NumberFormatException nfe) {     }     total=rhigh+rmedium+rlow+rno; high=(rhigh/total)*100; medium=(rmedium/total)*100; low=(rlow/total)*100; no=(rno/total)*100; high2=high*360/100;     medium2=medium*360/100;     low2=low*360/100;     no2=no*360/100;          low3=high2+medium2;     no3=low3+low2;               g.setColor(Color.red);     g.fillArc(100,100,200,200,0,(int)high2);     g.setColor(Color.blue);     g.fillArc(100,100,200,200,(int)high2,(int)medium2);     g.setColor(Color.green);     g.fillArc(100,100,200,200,(int)low3,(int)low2);     g.setColor(Color.pink);     g.fillArc(100,100,200,200,(int)no3,(int)no2);     }     }          public void init(){          draw=new Button("Draw pie chart");     reset=new Button("Reset");     thigh=new TextField("",10);     tmedium=new TextField("",10);     tlow=new TextField("",10);     tno=new TextField("",10);     l1=new Label("High Risk  :$");     l2=new Label("Medium Risk:$");     l3=new Label("Low Risk   :$");     l4=new Label("No Risk    :$");     banner=new Label("Welcome");           add(banner);           add(l1);     add(thigh);          add(l2);     add(tmedium);     add(l3);     add(tlow);     add(l4);     add(tno);                         add(draw);     add(reset);                   draw.setActionCommand("Draw");     draw.addActionListener(this);        reset.setActionCommand("Reset");     reset.addActionListener(this);     }          public void actionPerformed(ActionEvent e){          if(e.getActionCommand() == "Draw") {               something="in";               repaint();                    } else if(e.getActionCommand()== "Reset") {               something="";               thigh.setText("");               tmedium.setText("");               tlow.setText("");               tno.setText("");               repaint();          }     }}

    <code>
    import java.applet.*;
    import java.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    public class x2 extends Applet implements ActionListener {
         private Button draw, reset;
         private TextField thigh, tmedium, tlow, tno;
         private Label banner, l1, l2, l3, l4;
         double rhigh,rmedium,rlow,rno;
         double high, medium, low, no, total, high2=0, medium2=0, low2=0, no2=0,low3, no3;
         String something="";
         public void paint(Graphics g) {
              setBackground(Color.white);
              if(something=="in"){
                   try {
                        rhigh=Double.parseDouble(thigh.getText());
                        rmedium=Double.parseDouble(tmedium.getText());
                        rlow=Double.parseDouble(tlow.getText());
                        rno=Double.parseDouble(tno.getText());
                   catch (NumberFormatException nfe) { }
                   total=rhigh+rmedium+rlow+rno; high=(rhigh/total)*100;
                   medium=(rmedium/total)*100;
                   low=(rlow/total)*100;
                   no=(rno/total)*100;
                   high2=high*360/100;
                   medium2=medium*360/100;
                   low2=low*360/100;
                   no2=no*360/100;
                   low3=high2+medium2;
                   no3=low3+low2;
                   g.setColor(Color.red);
                   g.fillArc(100,100,200,200,0,(int)high2);
                   g.setColor(Color.blue);
                   g.fillArc(100,100,200,200,(int)high2,(int)medium2);
                   g.setColor(Color.green);
                   g.fillArc(100,100,200,200,(int)low3,(int)low2);
                   g.setColor(Color.pink);
                   g.fillArc(100,100,200,200,(int)no3,(int)no2);
         public void init(){
              draw=new Button("Draw pie chart");
              reset=new Button("Reset");
              thigh=new TextField("",10);
              tmedium=new TextField("",10);
              tlow=new TextField("",10);
              tno=new TextField("",10);
              l1=new Label("High Risk :$");
              l2=new Label("Medium Risk:$");
              l3=new Label("Low Risk :$");
              l4=new Label("No Risk :$");
              banner=new Label("Welcome");
              add(banner);
              add(l1);
              add(thigh);
              add(l2);
              add(tmedium);
              add(l3);
              add(tlow);
              add(l4);
              add(tno);
              add(draw);
              add(reset);
              draw.setActionCommand("Draw");
              draw.addActionListener(this);
              reset.setActionCommand("Reset");
              reset.addActionListener(this);
         public void actionPerformed(ActionEvent e) {
              if(e.getActionCommand() == "Draw") {
                   something="in";
                   repaint();
              } else if(e.getActionCommand()== "Reset") {
                   something="";
                   thigh.setText("");
                   tmedium.setText("");
                   tlow.setText("");
                   tno.setText("");
                   repaint();
    </code>

  • How to draw a simple pie chart?

    I want to draw a simple pie chart.
    I was wondering whether there already exists a method to allow me to do that in SDK 1.4.2. I saw on the net a method getPieChart( ).
    Do you know if its incorporated in SDK1.4.2 and how to draw the pie chart using this method. Can anybody guide me?
    Thanks.

    Have a look in your demos folder in your SDK, for example:
    C:\j2sdk1.4.2_04\demo\applets\GraphicsTest

  • Need help to make a Pie Chart

    I am trying to draw a pie chart for the Uptime Report.
    I have the Following table definition.
    create table downtime_detail ( env_code number, down_start date, down_end date );
    insert into downtime_detail values (1,to_date('26-JAN-2008 02:00:00','DD-MON-YYYY HH24:MI:SS'),to_date('26-JAN-2008 03:00:00','DD-MON-YYYY HH24:MI:SS') );
    insert into downtime_detail values (2,to_date('26-JAN-2008 02:00:00','DD-MON-YYYY HH24:MI:SS'),to_date('26-JAN-2008 03:00:00','DD-MON-YYYY HH24:MI:SS') );
    insert into downtime_detail values (2,to_date('01-FEB-2008 02:00:00','DD-MON-YYYY HH24:MI:SS'),to_date('03-FEB-2008 03:00:00','DD-MON-YYYY HH24:MI:SS') );
    insert into downtime_detail values (2,to_date('15-FEB-2008 02:00:00','DD-MON-YYYY HH24:MI:SS'),to_date('15-FEB-2008 03:00:00','DD-MON-YYYY HH24:MI:SS') );
    insert into downtime_detail values (2,to_date('26-FEB-2008 02:00:00','DD-MON-YYYY HH24:MI:SS'),to_date('28-FEB-2008 03:00:00','DD-MON-YYYY HH24:MI:SS') );
    Now the Below Query returns me the values val1 and val2 on the basis of which I need to draw a Pie Chart.
    ==========================================================
    select round((DOWN/TOTAL)*100,2) val1 , round(100-((DOWN/TOTAL)*100),2) val2
    from
         (select sum((DOWN_END - DOWN_START)*24) DOWN from DOWNTIME_DETAIL where ENV_CODE=2 ) a ,
         (select ((sysdate - to_date('01-JAN-2008','DD-MON-YYYY')) * 24) TOTAL from dual ) b
    VAL1 VAL2
    3.64 96.36
    ==========================================================
    Can someone help me try do this ?
    Actually I tried but I couldnt put my custom query to get this Pie chart. Or if there is any other better approach please let me know.

    nikhilskamik,
    I believe all that you are missing in your sql is a NULL. Below is the help text for creating a Flash pie chart.
    Specify the SQL query that will populate your chart, for example:
    select null, ename, sal
    from emp
    Alternatively you can write a PL/SQL function return a SQL query, for example:
    begin
    return 'select null, ename, sal from emp';
    end;
    Your query should then read:
    select null,round((DOWN/TOTAL)*100,2) val1 , round(100-((DOWN/TOTAL)*100),2) val2
    from
    (select sum((DOWN_END - DOWN_START)*24) DOWN from DOWNTIME_DETAIL where ENV_CODE=2 ) a ,
    (select ((sysdate - to_date('01-JAN-2008','DD-MON-YYYY')) * 24) TOTAL from dual ) b
    Jeff

  • Pie Chart changing data provider ?

    Iv created a pie chart to which the dataprovider is often going to change , the problem is how can i draw the pie chart when the datprovider changes as currently the chart is drawn when the dataprovider hasnt been set and thereforee nothing is displayed?
    Thanks Chris

    <fx:Script>
            <![CDATA[
                import mx.rpc.events.ResultEvent;
                import mx.collections.XMLListCollection;          
                import mx.events.ListEvent;
                import mx.controls.Alert;
                [Bindable]
                public var stats_list:XMLList;
                [Bindable]
                public var stats_list_collection:XMLListCollection;
                //Handler for stats list xml.           
                public function stats_result(event:ResultEvent):void
                    stats_list=event.result.stats
                    stats_list_collection=new XMLListCollection(stats_list);                                                             
            ]]>
        </fx:Script>
    <mx:PieChart id="piechart" dataProvider="{stats_list_collection}" showDataTips="true" color="#000000" name="Dynamic Pie Chart" right="0" left="0" top="40" bottom="10">
                <mx:series>
                    <mx:PieSeries explodeRadius=".1" labelPosition="callout" displayName="Series 1" field="value" nameField="type" fills="{[sc1, sc2, sc3, sc4]}"/>
                </mx:series>
    </mx:PieChart>
    Chris,
    I posted some information above that might be of some use to you.  Note that my PieChart dataProvider is: stats_list_collection 
    When the function "stats_result" is triggered it changes the data for the PieChart and I reset the value of stats_list_collection.  When that happens it changes the PieChart to contain the new values from your XMLListCollection.  Basically the way this application was setup is to have a dropdown that a user selects and option from and it populates the data in the PieChart depending on their selection.
    Another way of doing this (if you don't want to just update the dataProvider's content) is:
    <fx:Script>
             <![CDATA[
                  //pseudo code
              var dataprovider1:SOMETYPE = SOMETHING;
              var dataprovider2:SOMETYPE = SOMETHING;
              var dataprovider3:SOMETYPE = SOMETHING;
                public function WHATEVER YOU WANT THE TRIGGER TO BE(event:ResultEvent):void
                        switch(SOME CONDITION)
                             case "case 1":    piechart.dataProvider = dataprovider1;
                                                      break;
                             case "case 2":    piechart.dataProvider = dataprovider2;
                                                      break;
                             case "case 3":    piechart.dataProvider = dataprovider3;
                                                      break;
             ]]>
         </fx:Script>
    <mx:PieChart  id="piechart">
                <mx:series>
                     <mx:PieSeries explodeRadius=".1" labelPosition="callout"  displayName="Series 1" field="value" nameField="type" fills="{[sc1, sc2,  sc3, sc4]}"/>
                </mx:series>
    </mx:PieChart>
    Hope this helps.  The secondary option I posted was mostly pseduo code but the idea should give you a starting point.

  • Creating pie chart diagram in java  and converting into BMP file

    hi all ,
    my req. is to create draw a pie chart diagram and store
    the picture in BMP. it is Possible. if so how ?
    cheers
    senthil

    Hi Senthil,
    This response is a bit late but I hope it can help in some way.  Your requirement (to create draw a pie chart diagram and store the picture in BMP) is possible and actually quite easy if you don't mind using two open source libraries.  In his previous response to this thread, Detlev mentioned JFreeChart for as a solution for charting however he also mentioned that it lacks support for BMP.  Although this is true, you can use the JFreeChart library (http://www.jfree.org/jfreechart/index.html) in conjunction with an imaging library to meet your requirement.  I have used JFreeChart on multiple projects and I highly recommend it.  For the imaging library you have many options, however the only one I have used is The Java Imaging Utilities (JIU - http://jiu.sourceforge.net/).  Using these two class libraries, you can generate your pie chart and save it to a BMP file with the following block of code:
         try
             JFreeChart chart = this.createChart();
             FileOutputStream streamOut = new FileOutputStream("your/files/path/BMPfile.bmp");
             BufferedImage image = chart.createBufferedImage(600, 300);
             if(image == null)
                  reportError("Chart Image is NULL!!!!!!!!");
                  return(false);
             RGB24Image rgbImage = ImageCreator.convertImageToRGB24Image(image);
             Codec codec = new BMPCodec();
             codec.setImage(rgbImage);
             codec.setOutputStream(streamOut);
             codec.process();
             codec.close();
             streamOut.flush();
             streamOut.close();
        }catch(IOException ioExcept)
             // throw or handle IOException...
             return(false);
        }catch(OperationFailedException opFailedExcept)
             // throw or handle OperationFailedException...
             return(false);
    The first line inside the catch block calls a helper method that should create the actual chart using the JFreeChart library.  Once you have your chart instance (all chart types are represented using the JFreeChart class), you can then retrieve a BufferedImage of the chart (JFreeChart.createBufferedImage(int width, int height);).  In our situation, the BufferedImage class will act as an "intermediate" class, for both libraries (the charting and imaging) can make sense of BufferedImages.  The rest of the code deals with storing the generated chart (the BufferedImage) as a BMP file to disk.  The RGB24Image, Codec, BMPCodec, CodecMode, and OperationFailedException classes are all part of the JIU library.  Also, note that the storage  source is not solely limited to a File on disk; the Codec.setOutputStream(OutputStream os) method will accept any subclass of OutputStream.  This implies that not only can you store to the actual App Server disk (where your app is running) but also to sources such as Knowledge Management (KM) resources or even directly to the clients browser (in the case of an iView). 
    Once again, sorry for the late response and let me know if you have any questions regarding the code above. 
    Regards,
    Michael Portner

  • Pie Charts show Table Sum?  Huh?

    Hello all.
    I am making a simple home budget, with a table of data, which has a final row that totals the previous entries. I selected a pie chart to show this info, but the pie chart includes the total row data, which makes no sense. How do I tell Numbers to not show that total entry in the chart?
    Example:
    Row 1 = $500
    Row 2 = $400
    Row 3 = $300
    Row 4 = Calculates sum which in this case is $1200.
    Numbers draws a pie chart showing 4 items, not 3 items and their corresponding percentages of the entire chart.

    Try placing a summary footer then plot the individual data items.
    Regards,

  • How to create a pie chart with jsp/servlet?

    I want to create a servlet which can be used like below:
    <img src="pieservlet?param1=<%=x%>&param2=<%=y%>&..." width="100" height="100" >
    can you give me some guide?

    Hai ,
    I have implemented a trial working pie chart , dynamically created from jsp using ServletOutputStream , BufferedImage & JPEGImageEncoder (found in com.sun.image.codec.jpeg.* package & bundled along with jdk ) .
    <%
    ServletOutputStream sout = response.getOutputStream();
    response.setContentType("image/jpeg");
    BufferedImage img = new BufferedImage(400,400,BufferedImage.TYPE_INT_RGB);
    Graphics2D gr = img.createGraphics();
    /* Actually this will be got as values of request.getParameter */
    Vector values = new Vector();
    values.addElement(new String("45") );
    values.addElement(new String("125") );
    values.addElement(new String("75") );
    values.addElement(new String("25") );
    values.addElement(new String("90") );
    // my demo class      
    temp.pieChart fr = new temp.pieChart(400,400,values);
    /* This pieChart is class extends JFrame , in paint method of it all Drawing of pie chart using graphics2D fillArc done */
    fr.paint(gr);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sout);
    encoder.encode(img);
    sout.flush();
    %>
    Hope this helps to build your own custom pie chart .
    Let me know if details needed on pieChart class
    rakesh
         

  • Is Apple allow core plot framework to draw Pie chart in iPhone application?

    Is Apple allow core plot framework to draw Pie chart in iPhone application?
    http://code.google.com/p/core-plot/wiki/AppsUsingCorePlot

    Wrong forum. Ask in the developer's forum.

  • Drawing pie chart

    import java.applet.*;
    import java.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    public class x2 extends Applet implements ActionListener {
         private Button draw,draw2,reset;
         private TextField thigh,tmedium,tlow,tno;
         private Label banner,l1, l2, l3, l4;
         double rhigh,rmedium,rlow,rno;
         double high, medium, low, no, total, high2=0, medium2=0, low2=0, no2=0,low3=0,no3=0;
         String something="";
         public void paint(Graphics g){
         setBackground(Color.white);
         if(something=="pie"){
              try{
    rhigh=Double.parseDouble(thigh.getText());
    rmedium=Double.parseDouble(tmedium.getText());
                   rlow=Double.parseDouble(tlow.getText());
                   rno=Double.parseDouble(tno.getText());
    if(rhigh<0||rmedium<0||rlow<0||no<0){
         throw new NumberFormatException();
              total=rhigh+rmedium+rlow+rno;
         high=(rhigh/total)*100;
         medium=(rmedium/total)*100;
         low=(rlow/total)*100;
         no=(rno/total)*100;
         high2=high*360/100;
              medium2=medium*360/100;
              low2=low*360/100;
              no2=no*360/100;     
              low3=high2+medium2;
              no3=low3+low2;
              DecimalFormat F=new DecimalFormat("###.000");
    g.setColor(Color.black);
    g.drawString("THE INVESTMENT ARE:",250,100);
    g.drawString("Pie Chart",450,100);
    g.setColor(Color.red);
    g.drawString(F.format(high)+" "+"% High Risk",250,140);
    g.setColor(Color.blue);
    g.drawString(F.format(medium)+" "+"%High Risk",250,180);
    g.setColor(Color.green);
    g.drawString(F.format(low)+" "+"% Low Risk",250,220);
    g.setColor(Color.pink);
    g.drawString(F.format(no)+" "+"% No Risk",250,260);
    g.setColor(Color.red);
    g.fillArc(500,80,200,200,0,360-(int)(medium2+low2+no2));
    g.setColor(Color.blue);
    g.fillArc(500,80,200,200,(int)high2,360-(int)(high2+low2+no2));
    g.setColor(Color.green);
    g.fillArc(500,80,200,200,(int)low3,360-(int)(high2+medium2+no2));
    g.setColor(Color.pink);
    g.fillArc(500,80,200,200,(int)no3,360-(int)(high2+medium2+low2));
    g.setColor(Color.red);
    g.fillRect(450,300,60,30);
    g.setColor(Color.blue);
    g.fillRect(450,330,60,30);
    g.setColor(Color.green);
    g.fillRect(450,360,60,30);
    g.setColor(Color.pink);
    g.fillRect(450,390,60,30);
    g.setColor(Color.red);
    g.drawString("High Risk Investment",520,320);
    g.setColor(Color.blue);
    g.drawString("Medium Risk Investment",520,350);
    g.setColor(Color.green);
    g.drawString("Low Risk Investment",520,380);
    g.setColor(Color.pink);
    g.drawString("No Risk Investment",520,410);
         catch(NumberFormatException e){
    g.drawString("Invalid value click the reset button and reenter your value",300,200);
              else if(something=="bar") {
              try{
    rhigh=Double.parseDouble(thigh.getText());
    rmedium=Double.parseDouble(tmedium.getText());
    rlow=Double.parseDouble(tlow.getText());
    rno=Double.parseDouble(tno.getText());
    if(rhigh<0||rmedium<0||rlow<0||no<0){
         throw new NumberFormatException();
         total=rhigh+rmedium+rlow+rno;
         high=(rhigh/total)*100;
         medium=(rmedium/total)*100;
         low=(rlow/total)*100;
         no=(rno/total)*100;
    DecimalFormat F=new DecimalFormat("###.000");
    g.setColor(Color.black);
    g.drawString("THE INVESTMENT ARE:",250,100);
    g.drawString("Bar Chart",530,100);
    g.setColor(Color.red);
    g.drawString(F.format(high)+" "+"% High Risk",250,140);
    g.setColor(Color.blue);
    g.drawString(F.format(medium)+" "+"% High Risk",250,180);
    g.setColor(Color.green);
    g.drawString(F.format(low)+" "+"% Low Risk",250,220);
    g.setColor(Color.pink);
    g.drawString(F.format(no)+" "+"% No Risk",250,260);
    g.setColor(Color.red);
    g.fillRect(480,250-(int)high,40,(int)high);
    g.setColor(Color.blue);
    g.fillRect(530,250-(int)medium,40,(int)medium);
    g.setColor(Color.green);
    g.fillRect(580,250-(int)low,40,(int)low);
    g.setColor(Color.pink);
    g.fillRect(630,250-(int)no,40,(int)no);
    g.setColor(Color.black);
    g.drawLine(450,250,700,250);
    g.drawLine(450,130,450,250);
    g.drawLine(445,150,450,150);
    g.drawString("Hight",485,265);
    g.drawString("Medium",535,265);
    g.drawString("Low",585,265);
    g.drawString("No",635,265);
    g.drawString("Percentage%",425,125);
    g.drawString("Risks",710,250);
    g.drawString("100",420,150);
    g.setColor(Color.red);
    g.fillRect(450,300,60,30);
    g.setColor(Color.blue);
    g.fillRect(450,330,60,30);
    g.setColor(Color.green);
    g.fillRect(450,360,60,30);
    g.setColor(Color.pink);
    g.fillRect(450,390,60,30);
    g.setColor(Color.red);
    g.drawString("High Risk Investment",520,320);
    g.setColor(Color.blue);
    g.drawString("Medium Risk Investment",520,350);
    g.setColor(Color.green);
    g.drawString("Low Risk Investment",520,380);
    g.setColor(Color.pink);
    g.drawString("No Risk Investment",520,410);     
         catch(NumberFormatException e){
    g.drawString("Invalid value click the reset button and reenter your value",300,200);
         public void init(){
         setLayout (null);
         draw=new Button("Draw pie chart");
         draw2=new Button("Draw bar chart");
         reset=new Button("Reset");
         thigh=new TextField("",10);
         tmedium=new TextField("",10);
         tlow=new TextField("",10);
         tno=new TextField("",10);
         l1=new Label("High Risk :$");
         l2=new Label("Medium Risk:$");
         l3=new Label("Low Risk :$");
         l4=new Label("No Risk :$");
         banner=new Label("Welcome");
         banner.setBounds(new Rectangle(200,50,100,20));
         add(banner);
    l1.setBounds(new Rectangle(20,100,100,20));
    add(l1);
    thigh.setBounds(new Rectangle(120,100,100,20));
    add(thigh);
    l2.setBounds(new Rectangle(20,140,100,20));
    add(l2);
    tmedium.setBounds(new Rectangle(120,140,100,20));
    add(tmedium);
    l3.setBounds(new Rectangle(20,180,100,20));
    add(l3);
    tlow.setBounds(new Rectangle(120,180,100,20));
    add(tlow);
    l4.setBounds(new Rectangle(20,220,100,20));
    add(l4);
    tno.setBounds(new Rectangle(120,220,100,20));
    add(tno);
    draw.setBounds(new Rectangle(20,260,100,20));
    add(draw);
    draw2.setBounds(new Rectangle(120,260,100,20));
    add(draw2);
    reset.setBounds(new Rectangle(20,290,100,20));
    add(reset);
    draw.addActionListener(this);
    draw2.addActionListener(this);
    reset.addActionListener(this);
         public void actionPerformed(ActionEvent e){
              if(e.getSource()==draw) {
                   something="pie";
                   repaint();
              }else if(e.getSource()==draw2) {
                   something="bar";
                   repaint();
              if(e.getSource()==reset) {
                   something="";
                   thigh.setText("");
                   tmedium.setText("");
                   tlow.setText("");
                   tno.setText("");
                   repaint();

    import java.applet.*;
    import java.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Graphics;
    public class x2 extends Applet implements ActionListener
         private Button draw,draw2,reset;
         private TextField thigh,tmedium,tlow,tno;
         private Label banner,l1, l2, l3, l4;
         double  rhigh,rmedium,rlow,rno;
         double  high, medium, low, no, total, high2=0, medium2=0, low2=0, no2=0,low3=0,no3=0;
         String something="";
         Double  d1;
    public void paint(Graphics g)
         setBackground(Color.white);
         if(something=="pie")
              try
    //          rhigh=Double.parseDouble(thigh.getText());
    //          rmedium=Double.parseDouble(tmedium.getText());
    //          rlow=Double.parseDouble(tlow.getText());
    //          rno=Double.parseDouble(tno.getText());
                   rhigh   = get_double(thigh.getText());
                   rmedium = get_double(tmedium.getText());
                   rlow    = get_double(tlow.getText());
                   rno     = get_double(tno.getText());
                   if(rhigh<0||rmedium<0||rlow<0||no<0)
                        throw new NumberFormatException();
                   total=rhigh+rmedium+rlow+rno;
                   high=(rhigh/total)*100;
                   medium=(rmedium/total)*100;
                   low=(rlow/total)*100;
                   no=(rno/total)*100;
                   high2=high*360/100;
                   medium2=medium*360/100;
                   low2=low*360/100;
                   no2=no*360/100;
                   low3=high2+medium2;
                   no3=low3+low2;
                   DecimalFormat F=new DecimalFormat("###.000");
                   g.setColor(Color.black);
                   g.drawString("THE INVESTMENT ARE:",250,100);
                   g.drawString("Pie Chart",450,100);
                   g.setColor(Color.red);
                   g.drawString(F.format(high)+" "+"% High Risk",250,140);
                   g.setColor(Color.blue);
                   g.drawString(F.format(medium)+" "+"%High Risk",250,180);
                   g.setColor(Color.green);
                   g.drawString(F.format(low)+" "+"% Low Risk",250,220);
                   g.setColor(Color.pink);
                   g.drawString(F.format(no)+" "+"% No Risk",250,260);
                   g.setColor(Color.red);
                   g.fillArc(500,80,200,200,0,360-(int)(medium2+low2+no2));
                   g.setColor(Color.blue);
                   g.fillArc(500,80,200,200,(int)high2,360-(int)(high2+low2+no2));
                   g.setColor(Color.green);
                   g.fillArc(500,80,200,200,(int)low3,360-(int)(high2+medium2+no2));
                   g.setColor(Color.pink);
                   g.fillArc(500,80,200,200,(int)no3,360-(int)(high2+medium2+low2));
                   g.setColor(Color.red);
                   g.fillRect(450,300,60,30);
                   g.setColor(Color.blue);
                   g.fillRect(450,330,60,30);
                   g.setColor(Color.green);
                   g.fillRect(450,360,60,30);
                   g.setColor(Color.pink);
                   g.fillRect(450,390,60,30);
                   g.setColor(Color.red);
                   g.drawString("High Risk Investment",520,320);
                   g.setColor(Color.blue);
                   g.drawString("Medium Risk Investment",520,350);
                   g.setColor(Color.green);
                   g.drawString("Low Risk Investment",520,380);
                   g.setColor(Color.pink);
                   g.drawString("No Risk Investment",520,410);
              catch(NumberFormatException e)
                   g.drawString("Invalid value click the reset button and reenter your value",300,200);
         if(something=="bar")
              try
    //     rhigh=Double.parseDouble(thigh.getText());
    //     rmedium=Double.parseDouble(tmedium.getText());
    //  rlow=Double.parseDouble(tlow.getText());
    //  rno=Double.parseDouble(tno.getText());
                   rhigh   = get_double(thigh.getText());
                   rmedium = get_double(tmedium.getText());
                   rlow    = get_double(tlow.getText());
                   rno     = get_double(tno.getText());
                   if(rhigh<0||rmedium<0||rlow<0||no<0)
                        throw new NumberFormatException();
                   total=rhigh+rmedium+rlow+rno;
                   high=(rhigh/total)*100;
                   medium=(rmedium/total)*100;
                   low=(rlow/total)*100;
                   no=(rno/total)*100;
                   DecimalFormat F=new DecimalFormat("###.000");
                   g.setColor(Color.black);
                   g.drawString("THE INVESTMENT ARE:",250,100);
                   g.drawString("Bar Chart",530,100);
                   g.setColor(Color.red);
                   g.drawString(F.format(high)+" "+"% High Risk",250,140);
                   g.setColor(Color.blue);
                   g.drawString(F.format(medium)+" "+"% High Risk",250,180);
                   g.setColor(Color.green);
                   g.drawString(F.format(low)+" "+"% Low Risk",250,220);
                   g.setColor(Color.pink);
                   g.drawString(F.format(no)+" "+"% No Risk",250,260);
                   g.setColor(Color.red);
                   g.fillRect(480,250-(int)high,40,(int)high);
                   g.setColor(Color.blue);
                   g.fillRect(530,250-(int)medium,40,(int)medium);
                   g.setColor(Color.green);
                   g.fillRect(580,250-(int)low,40,(int)low);
                   g.setColor(Color.pink);
                   g.fillRect(630,250-(int)no,40,(int)no);
                   g.setColor(Color.black);
                   g.drawLine(450,250,700,250);
                   g.drawLine(450,130,450,250);
                   g.drawLine(445,150,450,150);
                   g.drawString("Hight",485,265);
                   g.drawString("Medium",535,265);
                   g.drawString("Low",585,265);
                   g.drawString("No",635,265);
                   g.drawString("Percentage%",425,125);
                   g.drawString("Risks",710,250);
                   g.drawString("100",420,150);
                   g.setColor(Color.red);
                   g.fillRect(450,300,60,30);
                   g.setColor(Color.blue);
                   g.fillRect(450,330,60,30);
                   g.setColor(Color.green);
                   g.fillRect(450,360,60,30);
                   g.setColor(Color.pink);
                   g.fillRect(450,390,60,30);
                   g.setColor(Color.red);
                   g.drawString("High Risk Investment",520,320);
                   g.setColor(Color.blue);
                   g.drawString("Medium Risk Investment",520,350);
                   g.setColor(Color.green);
                   g.drawString("Low Risk Investment",520,380);
                   g.setColor(Color.pink);
                   g.drawString("No Risk Investment",520,410);
              catch(NumberFormatException e)
                   g.drawString("Invalid value click the reset button and reenter your value",300,200);
    private double get_double(String s)
         try
              d1 = d1.valueOf(s);
              return(d1.doubleValue());
         catch (NumberFormatException nfe)
              return(-1);
    public void init()
         setLayout (null);
         draw    = new Button("Draw pie chart");
         draw2   = new Button("Draw bar chart");
         reset   = new Button("Reset");
         thigh   = new TextField("",10);
         tmedium = new TextField("",10);
         tlow    = new TextField("",10);
         tno     = new TextField("",10);
         l1      = new Label("High Risk :$");
         l2      = new Label("Medium Risk:$");
         l3      = new Label("Low Risk :$");
         l4      = new Label("No Risk :$");
         banner = new Label("Welcome");
         banner.setBounds(200,50,100,20);
         add(banner);
         l1.setBounds(20,100,100,20);
         add(l1);
         thigh.setBounds(120,100,100,20);
         add(thigh);
         l2.setBounds(20,140,100,20);
         add(l2);
         tmedium.setBounds(120,140,100,20);
         add(tmedium);
         l3.setBounds(20,180,100,20);
         add(l3);
         tlow.setBounds(120,180,100,20);
         add(tlow);
         l4.setBounds(20,220,100,20);
         add(l4);
         tno.setBounds(120,220,100,20);
         add(tno);
         draw.setBounds(20,260,100,20);
         add(draw);
         draw2.setBounds(120,260,100,20);
         add(draw2);
         reset.setBounds(20,290,100,20);
         add(reset);
         draw.addActionListener(this);
         draw2.addActionListener(this);
         reset.addActionListener(this);
    public void actionPerformed(ActionEvent e)
         if(e.getSource()==draw)
              something="pie";
         if(e.getSource()==draw2)
              something="bar";
         if(e.getSource()==reset)
              something="";
              thigh.setText("");
              tmedium.setText("");
              tlow.setText("");
              tno.setText("");
         repaint();
    Noah

  • Drawing pie charts

    ive constructed a pie chart using fillArc's but i want my arcs to have a border.
    how could i achieve this and make it look good.
    also, is their any way i could make diagnol lines not so jaggedy.
    cheers

    ive constructed a pie chart using fillArc's but i want
    my arcs to have a border.
    how could i achieve this and make it look good.Use Graphics2D methods:
    void draw(Shape shape) //Stroke border around shape
    void fill(Shape shape) //Fill interior of shape>
    also, is their any way i could make diagnol lines not
    so jaggedy.Antialiasing blurs jaggies. Here's how to set the rendering hint of a Graphics2D object to do this:
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);Unless you're just dabbling in the 2D API, it's a good idea to buy a book on it. Jonathan Knudsen's "Java 2D Graphics" (O'Reilly) is an easy introduction.
    --Paul

  • Urgent! Drawing Pie Chart

    Hi , i am trying to produce a pie chart to display the data I have. Is anyone have an example (simple code) on how a pie chart can be drawn?
    Thank you very much.

    Search this forum for "JFreeChart". I'm surprised that Dave Gilbert hasn't responded to this already. There was a time where he was posting links to his project thick and fast...

  • I just want to make a pie chart

    I've been assigned to make a pie chart in class (with each section a different color), and I've loaded the javax.swing.JApplet and java.awt.*
    I've only gotten as far as drawing the circle. I know how to create lines, but I can't figure out what I'm supposed to do to fill in the sections of the pie chart with different colors.
    Could anyone help me with this simple project? Like what method I should look at?

    Have you looked at the link?
    public abstract void fillArc(int x,
                                 int y,
                                 int width,
                                 int height,
                                 int startAngle,
                                 int arcAngle)So, let us guess at how to draw a circle, and 300 x 400, Mmm the x would be 300, and the y 400. It wants to have a radius of 100px, so thats the width & hieght sorted. Do you want it to be a complete circle? If so that is from 0-360 degrees . So that is the start & end angle.
    Actually, do you know draw to the screen?
    http://java.sun.com/docs/books/tutorial/2d/index.html

  • How to show negative value in Pie Chart from Webi?

    I have below example data, I want to convert this to a pie chart in Web Intelligence, my problem is after I convert it to a pie chart, the revenue '-30' is shown as '30', looks like the pie chart is not suppor the negative value to show, I want to know if there is any workaround or solution to make the pie chart to show the negative value? Is this behavior is by design? do we have any official document to explain this?
    The product I used is BOE XI 3.1 SP3.
    Department    Revenue
    A                      100
    B                       -30
    C                        80
    Edited by: Alex Wang on Jul 13, 2010 5:51 PM

    Why are you showing this information as a pie chart? It doesn't make sense to try and display a negative slice in a pie chart. I can't really think of a logical way to try and draw a negative slice in a pie chart. With a pie chart you will need all your information to either all be positive or all negative, otherwise it doesn't work.
    What you need is to have a bar chart, with positive and negative values on the y axis.

  • Pie chart problem with label!

    Hello,
    I found this example of pie chart, I tried to use several pie charts but the label square move in some chart. It shows the square moved down when it uses the vi.
    I attached the example with 4 pie charts and sometimes it show the 4 sqaures and sometimes down one. Any way to fit it?.
    I would like to see some example with 3d pie chart. Do you know any example?.
    Thanks in advance!.
    Fred
    Solved!
    Go to Solution.
    Attachments:
    Pie Charts.vi ‏25 KB
    PieCreateChart.vi ‏13 KB

    Sorry guys!. i got it.
    Changing the first time call to comparison of For Loop = 0, so always start with the value fixed to draw the square.
    Thanks.

Maybe you are looking for

  • What is an as2proj file?

    I do all of the flash work for my company, so, when I had to take a couple of days off for a funeral my boss had a contractor build a flash app that I would have built during that time. Yesterday we received the source files. AS2 publish for player8.

  • Error code -17306 while accessing container from TestStand

    Hi, I am getting an error -17306 while accessing the TestStand container present in Station Globals using invoke node property object. Please find below the code snippet. Thanks, Neha

  • Global Part Updates at the Board Level

    Hello, How would I globally update a part on my board, that I've changed in the part lib? I'm using Ultiboard 11.0.2. THX, Steve H

  • Error Linux386/Linux-2.0.34-8.1.0

    Hi, using Oracle Xe on linux. And somtimes while browsing application or tables getting empty page or page with info small squeres + Linux386/Linux-2.0.34-8.1.0 Server has database link to another Oracle database (not XE)

  • Gaps in text, on metro UI apps - 9860

    Updated to Build 9860 and since, there have been gaps in the text in metro UI apps and the Notification Center and search, see attached https://social.technet.microsoft.com/Forums/getfile/547988 https://social.technet.microsoft.com/Forums/getfile/547