Drawing a chart or diagram

I'm new to drawing with Java. What I would like to do is draw an event sequence diagram. Basically, a list of endpoints at the top of the diagram, a vertical line below each endpoint, and lines that connect the endpoints in a sequence. I know I'll need to use Graphics and Graphics2D, but I'm not sure where to start.
Anyone have any tips or good references that do something like this?
Thanks.

import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
public class PlotThis
    public PlotThis()
        float[] data = {
            100f, 220f, 12.9f, 65f, 47.3f, 175f, 190f, -18f
        Plotter plotter = new Plotter();
        for(float f : data)
            plotter.plot(f);
        JFrame f = new JFrame("Plot +/- Float Values");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(plotter);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    public static void main(String[] args)
        new PlotThis();
class Plotter extends JPanel
    final float PAD = 25;
    List<Float> dataList;
    public Plotter()
        dataList = new ArrayList<Float>();
        setBackground(Color.white);
        setPreferredSize(new Dimension(400,300));
    public void paintComponent(Graphics g)
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        float width = getWidth();
        float height = getHeight();
        float xStep = (width - 2*PAD)/(dataList.size() - 1);
        float x = PAD;
        float y;
        // scale data
        float max = Collections.max(dataList);
        float min = Collections.min(dataList);
        float vertSpace = height - 2*PAD;
        float yOffset = height - PAD;
        float yDataOffset = (min >= 0 ? min : max > 0 ? 0 : max);
        float scale = vertSpace/(max - min);
        float yOrigin = yOffset +
                            (min > 0 ? 0 : max > 0 ? scale*min : - vertSpace);
        // draw ordinate
        g2.draw(new Line2D.Float(PAD, PAD, PAD, yOffset));
        // draw abcissa
        g2.draw(new Line2D.Float(PAD, yOrigin, width - PAD, yOrigin));
        // label ordinate limits
        g2.drawString(String.valueOf(max), 10, PAD - 10);
        g2.drawString(String.valueOf(min), 10, yOffset + PAD*2/3);
        float lastX = 0, lastY = 0;
        for(int j = 0; j < dataList.size(); j++)
            y = yOrigin - scale * (dataList.get(j) - yDataOffset);
            g2.setPaint(Color.red);
            g2.draw(new Ellipse2D.Float(x - 2, y - 2, 4, 4));
            if( j > 0)
                g2.setPaint(Color.black);
                g2.draw(new Line2D.Float(lastX, lastY, x, y));
            lastX = x;
            lastY = y;
            x += xStep;
    protected void plot(float input)
        dataList.add(input);
        repaint();
}

Similar Messages

  • Openoffice spreadsheet draw combination charts  programatically

    hi all,
    we need to develop a project that is an extension in OO so that it could display a mutitype chart we have drawn in Excel.
    Essentially, we have a combination chart consists of a candle stick chart and a line chart appearing together. OO could not display it!
    (see http://qa.openoffice.org/issues/show_bug.cgi?id=27363).
    We have research the problem for a while and figure that the easiest way is to develop an extension in Java using the Netbean Integration tool. Probably, adding a new chart type so that it is matched to the excel version. In chart2, it appears that they have changed the structure to a MVC model and under the diagram service, a coordinate system could have a list of charttype. So it appears that it is possible to draw a chart with different charttype on it even without the extension. However, we have not tried the chart2 API as we can't find a working example and SUN is not very helpful either and they discourage us to use chart2.
    (see http://graphics.openoffice.org/chart/chart2codestructure.html)
    can you give us advise how to approach this problem ?
    documentation resources , code snippets to call chart2 api from java code and any other helpful suggestion will be very welcomed.
    thanks.

    ok let me put it simply :
    com:sun:star:chart2 is not written in java, it is all written in C++ with those horrible IDL files which I don�t want to know about.
    However, i do think UNO make it possible to be used in a java environment.
    i searched the OOo website and also the web for an example snippet of a java program that calls com:sun:star:chart2 ; but i didn't found anything.
    it would be great if SUN engineers in this forum show me an example of how to use the OOo chart2 API in a java program.
    thanks.

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

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

  • I wanna draw line chart

    hi, i wanna draw line chart for some analysis of an image.
    how can i do that?? plz help me in that, code would be more
    better.thank u.

    Yes, you can use the code for free and you can include it in your application for free. JFreeChart is and will always be free software.
    What's not free is the JFreeChart Developer Guide (a 300 page Acrobat PDF document) and access to the JFreeChart Priority Support Forum. You have to pay for these, if you want them, the idea being that a well-funded project will progress faster than one that relies solely on volunteers.
    I get some criticism for taking this "commercial" approach, but I am 100% certain that it has made JFreeChart a better product, so I don't care...
    Regards,
    Dave Gilbert
    JFreeChart Project Leader

  • Drawing editable charts

    Hi,
    I have been working on a project management tool and I need to draw some charts like gantt and pert. I want them to be editable like when the users drags a task it should extend its end date and etc. What's the best approach I can take? Do you know of some good libs that I can employ?
    A second question is what new features would you want in a project management tool? Our design has both web and swing parts and we are planning to use RMI and struts.

    nobody knows? :((

  • 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

  • HT1338 I am trying (without success) to design an organization chart on Diagram Painter, please advise fastest and easiest way to complete this task?

    I am trying (without success) to design an organization chart on Diagram Painter, please advise fastest and easiest way to complete this task?

    Purchasing an app from the App Store does not mean that Apple's forums are the right place to ask questions about it. Asking about it here is roughly similar to asking another customer at Wal-mart how to assemble the bicycle you bought there. Ask the company that created the app, using the link Bob gave you.

  • How to draw flow chart?

    Anybody knows if Java support drawing flow chart,such as visio and rose software? If Java can do it,please give some examples.
    Thanks

    I know there are libraries out there for editing Word and Excell documents in java, but I'm not sure about Visio. Have you tried google?

  • Way to draw Class and Sequence Diagrams in JDEV

    Hi All,
    I am new to JDeveloper. I am using JDev - 10.1.3.3.
    Can anyone suggest me an example to draw Sequence and Class Diagrams in JDEV
    Thanks

    Maybe the online help can help you then:
    http://www.oracle.com/webapps/online-help/jdeveloper/10.1.3/state/content/navId.4/navSetId._/vtTopicFile.umlmodeling%7Cumlmodeling%7Cmod_umlclassmodeling%7Ehtml/
    Or watch these 10.1.2 demos that also apply to 10.1.3:
    http://www.oracle.com/technology/products/jdev/viewlets/10g/UML_Class_10g_final_viewlet_swf.html

  • Can't seem to draw a chart (line chart) using dates rather than numbers

    I'm trying to draw a Line Chart but rather using numbers i want to use dates for example: Switzerland 23/06/2008 - 23/08/2008. Can't seem to get it to work? it seems to all go wrong when I change the cell format to 'date'
    Can anyone help?
    Thanks
    PS. I can do it easily in Excel

    Hello
    From my point of view, it's not surprising.
    In XL, a date is a number to which a date format is applied. So, it may be charted.
    Same thing with the good old AppleWorks.
    With Numbers, a date is NOT a number, it IS a specific class of data.
    The consequence is that it can't be charted directly.
    Happily, we may easily convert a date into a number.
    In column B the formula is
    =A-$A$1
    which calculates the numeric difference between stored dates and the date stored in A1.
    So, we may chart the results.
    I know that it's far from perfect but we have to live with the choices made by Numbers's designers.
    Yvan KOENIG (from FRANCE vendredi 18 avril 2008 18:44:14)

  • Drawing On Chart But It's Disappearing

    I created a column chart and added an annotation element to it:
    [code]
    <mx:annotationElements>
            <mx:CartesianDataCanvas id="chartCanvas"/>
    </mx:annotationElements>
    [/code]
    I added a creation complete method to draw on the canvas. The following function is called on creationComplete.
    [code]  
    protected function drawSteps():void
           trace("chartCanvas.width is: " + chartCanvas.width);
          chartCanvas.graphics.lineStyle(1, 0x000000, 0.5);
          chartCanvas.graphics.beginFill(0xd4e3f0, 0.5);
          chartCanvas.graphics.moveTo(chartCanvas.width/2, yAxisMax);
          chartCanvas.graphics.lineTo(chartCanvas.width/2, 0);
          chartCanvas.graphics.endFill();
    [/code]
    This works fine when the chart first loads but if I update the chart series the line goes away. I have added a call to the 'drawSteps()' function in my method that updates the chart series as well but it didn't work. I don't understand why changing the chart series would cause this to stop displaying though, especially considering I call it again when the series is changed. Can anyone help?

    Other things may be drawn into the graphics object, and those things might clear what is there first.  It might be better to draw by overriding updateDisplayList()

  • Third-part tool to draw rectangle on block diagram

    I know there was once a third-party tool that enabled me to draw a nice double-bordered rectangle on the block diagram.  Yes, that is the block diagram not the front panel.  It was very useful for making annotations and denoting functional groupings.  Does anyone know what that might be?  I have installed VI Package Manager and gone through everything I can think of without finding it.
    Unfortunately, the documentation for these potentially very useful add-ons is poor.  The "Get info" is terse to the point of useless and clicking on "Product Homepage" rarely gets you more than a logo, not informative.  Surely, there must be more details somewhere.
    Solved!
    Go to Solution.

    I don't know what tool you're referring to. What does this logo look like? Perhaps someone may recognize it.
    What's wrong with the flat frame?
    Attachments:
    flat frame.png ‏33 KB

  • 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

  • Package or component to draw candle charts in j2me ??

    hi all,
    I want a package or component API to draw candle stick charts.
    best regards,
    ahmed

    Default drawing functions in lcdui are enough to draw charts manually, or u can search google for 3'rd party implemantation.

Maybe you are looking for

  • Black dropzones?  Can't add photos, or movie clips?

    Hello,      I am trying to make an iDVD.  I have made many before, but I have never had a problem like this before?  Whenever I try to add a movie, or even a photo to any of the dropzones, all I see is a black dropzone?  No photo, no image.  When I a

  • Creating protected PDF files

    Does anybody know if it is possible to protect your PDF files from the following when sent to an external party: - Creating a copy of the PDF by using 'Save As' or other methods - Stopping the PDF from being Screen grabbed or screen captured - Emaili

  • Creating an acrobat Website

    I know there are better ways to go about creating a website, however, I am a mere animator and have no web training. I did once create a cd portfolio for a class with links and buttons to other pages. I have set up a series of .gif images that compos

  • Itunes won't run after upgrade

    I upgraded to the latest iTunes (10.6), but when I click on the icon I get an error message that says it can't open my iTunes library because it was created by a newer version of iTunes. How is that even possible if I just upgraded? Now I can't get i

  • Time on 24 hour clock after midnight

    Just got a 17" MacBook Pro today, and noted that when midnight passed (doesn't everyone stay up past midnight after getting a new Mac?) the clock changed day of the week, but unlike my iMac G5, on which the clock changes to 00:00:01 and onward, the M