To display Pie chart in JSP

Hi Guys..
I want to to have a output from jsp page in the form of Piechart. What all should I use??
Regards,
Nachiket

You can use JFreeChart which is a free and good tool to generate graphs in Java. It has samples and other guides which you can use to get started...

Similar Messages

  • Create pie chart in jsp

    how to create pie chart in jsp based on sql server 2000 database
    please give example or code with explanation

    http://sourceforge.net/projects/jfreechart
    - Saish

  • Pie Chart in JSP

    Hi
    I want to create a Pie Chart in JSP. The data will come from Oracle Database. I am not very good with managing big open source projects like Cewolf to draw charts. Is it possible to do this in the simplest way possible as I am not experienced in this technology.
    Please send me the link to the simplest way to do it or guide me.
    Thanks in advance.

    Thanks alot. The example shown works fine on my local
    machine where I have got TomCat but it does not work
    on my university server as they say they do not have
    graphics card on their server and therefore any
    java.awt or swing class can not be used on server sideSo I guess you have to use another server's capability, like the one in play-free-games.com, for example :
    http://www.play-free-games.com/webmasters/dynamic-piechart/dynamic-piechart.cfm

  • I need to display pie chart data tips at specified location instead of default location?

    I need to display pie chart data tips at specified location instead of default location?
    can any body let me know how to do that?
    thanks guys.

    Hi,
    Check this thread.
    Log for J2EE Web Services?
    Regards,
    Harini S

  • I want to display some stats using a pie chart in jsp/java plz  guide me

    i am working on struts framework .the view is in jsp and coding in java.
    i have value in the database and have to display them using a pie chart.
    Edited by: kapil_scwcd on Jan 10, 2010 8:10 PM

    You can use JFreeChart which is a free and good tool to generate graphs in Java. It has samples and other guides which you can use to get started...

  • How to Display jFrame - chart in JSP PAge

    Hi all,
    Can any one help about this task..
    I have writeen a java file which generates multiaxis chart by using JFreeChart API....
    Say for ex..
    public class multiaxis extends JFrame
    /// till know no problem...
    Can any one tell its possible to display this chart (JFrame) in Browser (JSP Page) .. any idea over this..
    Thanks in advance

    there's examples around the forums about using JFreeChart in a servlet to generate a JPEG or PNG images.

  • How can we create dynamic pie chart in jsp

    hi im a new jsp programmer and i just want to know how can i create dynamic pie chart in jsp

    http://sourceforge.net/projects/jfreechart
    - Saish

  • Display pie charts

    I have a problem!
    I had to create a pie chart. So I tried to create one. But at the end when I want to test it, I only get a "X" (picture not available) on the site. If I use the same data I used for creating the pie chart for creating a "normal" chart, it will works.
    Now my question, how can I display a pie chart?
    (I hope you4ll understand, I4m not very good in english)
    Tanja

    Hi Tanja,
    It's not a problem .Pie charts ,if you look in the global settings it clearly says that it is a beta version .So Oracle does not give us any guarantee for those features.Pie charts are under Beta version for the last many months.Every time they will say that will work in the next version, but even to day it is a beta feature..
    Thanks
    Vishnu

  • How to display PIE chart Axis label horizontally?

    Hi
    Currently my PIE chart axis label is displying in 2 lines. How make it to display in one line?
    Thank you

    hi,
    For Pie chart there will be no X-axis or Y-axis terms generally.
    Label/Text could be one of the following.
    Title?
    or Sub Title?
    or Foot note?
    Right Click -> Format Title . Reduce the font size such that it fits into a single line.
    Regards,
    Vamsee

  • 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
         

  • How to display pie chart in smart forms

    hii experts,
                      my requirement is to display pi chart in smart forms . i have  googled but could not get any meaning full results. If any one knows this pls share ..
    Thanks and Regards
    Aditya Shrivastava

    Hi
    I really doubt If you did search at all in the first place. Anyhow, check this:
    https://www.sdn.sap.com/irj/scn/advancedsearch?query=piechartin+smartforms&cat=sdn_all
    Vishwa.

  • Drill Down feature for pie chart in JSP

    Hi,
    I need to have drill down feature in my Pie Chart which is generated using JFreeChart package. The pie chart is generated dynamically basing upon the database values as inputs .
    Now on click of any one sector i have to show other bar graph. The bargraphs would be different for different sectors clicked.How to use Mouse Listener? How can track or keep check on the boundaries of different sectors?.
    Please help me on this issue.
    Thanks in advance,
    Praveen

    @OP: don't ask the same question in two different threads:
    http://forum.java.sun.com/thread.jspa?threadID=5121491&messageID=9424672#9424672
    kind regards,
    Jos

  • Pdf generated through API's does not display pie chart

    I'm using BIP 10.1.3.4, running on Oracle Linux 5 connecting to a 11g database.
    I developed an RTF using the word template builder and included a pie chart. Previewing from within Word works fine, running the report directly from BIP works fine. I then used the API's to generate the pdf programmatically to have more control.
    I use RTFProcessor to convert my RTF into a XSL, DataProcessor to generate the xml data and FOProcessor to generate the final PDF. This works fine running from local JDeveloper, connecting through to the remote database.
    I've now loaded the java class with the API's into the database, and as per http://download.oracle.com/docs/cd/E12844_01/doc/bip.1013/e12188/T421739T517850.htm#T520954, loaded up the following jar's
    xdocore.jar - the core BI Publisher library
    aolj.jar - although this is an Oracle E-Business Suite library, it is required for standalone implementations as well
    i18nAPI_v3.jar - the i18n library used for localization functions
    xdoparser.jar - the scalable XML parser and XSLT 2.0 engine
    xmlparserv2-904.jar - the main XML parser/XSLT engine
    bipres.jar - a charting library
    bicmn.jar - a charting library
    jewt4.jar - a charting support library
    share.jar - a charting support library
    collections.jar - you only need this if you are working with the delivery APIs or bursting engine.
    The report works fine, all data tabels are shown but the pie chart is missing. I originally got the jar files from the TemplateBuilder/jlib directory. I also tried using the jar files from the BIP/xmlpserver\WEB-INF\lib directory as well. Problem remains - everything works fine except for the lack of the pie chart !
    Any help would be greatly appreciated :)
    Cheers,
    Brent

    bump .... anyone had similar problems ?

  • How to display bar charts in jsp

    I need bar charts for web application.
    I search alot but I didn't find any solution.
    From where I can find the content for same?

    You're right I did read about Cewolf. Here's how
    You can simply define a chart by including a chart tag into your JSP like this:
    <cewolf:chart
    id="XYChart"
    type="xy"
    title="XYChart"
    <cewolf:gradient>
    <cewolf:point x="0" y="0" color="#FFFFFF"/>
    <cewolf:point x="0" y="300" color="#C8C8C8"/>
    </cewolf:gradient>
    <cewolf:data>
    <cewolf:producer id="xyData"/>
    </cewolf:data>
    </cewolf:chart>
    <cewolf:img chartid="XYChart" renderer="cewolf" width="400" height="300"/>
    keep coding..
    Ciao.
    Div

  • Help With Displaying Pie Chart

    Hi, I've put some code together but cannot seem to get my chart to display. I hope it's something simple but being very new to this I'm having a difficult time.Thanks in advance.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    import java.awt.Color;
    public class MortgageCalc_wk5 extends JFrame implements ActionListener {
         private static final long serialVersionUID = 6L;
         private static final Rectangle Rectangle = null;
    //Set up panels for Frame
         JPanel topPanel = new JPanel();
         JPanel bottomPanel = new JPanel();
         JPanel radioPanel = new JPanel();
         JPanel grfxPanel = new JPanel();     //new line
         //Set up Layout
         FlowLayout flowLayout = new FlowLayout();
         BorderLayout borderLayout = new BorderLayout();
    //Radio Choice Style Buttons    
         JRadioButton Choice1 = new JRadioButton ("User Input", true);
         JRadioButton Choice2 = new JRadioButton ("User Selection", false);
    //Set up JLabels, JButtons, and JTextFields
         JLabel amountLabel = new JLabel("Loan Amount");
         JTextField loanField = new JTextField(7);
         JLabel termLabel = new JLabel("Term(Yrs)");
         JTextField termField = new JTextField(4);
         JLabel rateLabel = new JLabel("Rate");
         JTextField rateField = new JTextField(4);
         JComboBox options = new JComboBox();
         JLabel optionsLabel = new JLabel();
         JButton calcButton = new JButton("Calculate");
         JButton resetButton = new JButton("Reset");
         JButton exitButton = new JButton("Exit");
         JButton grfxButton = new JButton("Display Graphics");    //new line
         JLabel paymentLabel = new JLabel("Monthly Payment =");
         JTextField paymentField = new JTextField(6);
         JLabel outputLabel = new JLabel("Loan Amoritization Chart");
         JTextArea calcField = new JTextArea(10, 25);
         JScrollPane scroll = new JScrollPane(calcField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
         ButtonGroup radioSelect = new ButtonGroup();
         JLabel grfxLabel =new JLabel ("Graphic Chart");        //new line
         JTextField grfxField = new JTextField ("Graphics");   // new line
    //Default constructor
         public MortgageCalc_wk5() {
              super("Tony's Calculator - Week 5");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              setVisible(true);
    //add ActionListeners
              loanField.addActionListener(this);
              termField.addActionListener(this);
              rateField.addActionListener(this);
              options.addActionListener(this);
              calcButton.addActionListener(this);
              grfxButton.addActionListener(this);    //new line
              resetButton.addActionListener(this);
              exitButton.addActionListener(this);
              Choice1.addActionListener(this);
              Choice2.addActionListener(this);
    //Top Panel Layout
              topPanel.setLayout(flowLayout);
              topPanel.add(amountLabel);
              topPanel.add(loanField);
              radioSelect.add(Choice1);
              radioSelect.add(Choice2);
              topPanel.add(Choice1);
              topPanel.add(Choice2);
    //Loan Term Options For JComboBox
              options.addItem("7 years @ 5.35%");
              options.addItem("15 years @ 5.5%");
              options.addItem("30 years @ 5.75%");
              options.setEnabled(false); 
              topPanel.add(options);
              topPanel.add(termLabel);
              topPanel.add(termField);
              topPanel.add(rateLabel);
              topPanel.add(rateField);
              topPanel.add(paymentLabel);
              topPanel.add(paymentField);
              paymentField.setEditable(false);
    //Was Bottom Panel Now East Panel, Calculate Reset,Exit, and Display Buttons        
              bottomPanel.add(calcButton);
              bottomPanel.add(resetButton);
              bottomPanel.add(exitButton);
              bottomPanel.add(grfxButton);             //new line
              calcButton.setBackground(Color.blue);
              resetButton.setBackground(Color.white);
              exitButton.setBackground(Color.red);
              calcField.setBackground(Color.orange);
              grfxPanel.setBackground(Color.green);   //new line
              grfxPanel.add(grfxField);               // new line 
              //add Container
             Container pane = getContentPane();
              pane.setLayout(borderLayout);
              pane.add(topPanel, BorderLayout.NORTH);
              pane.add(calcField, BorderLayout.WEST);
              pane.add(grfxPanel, BorderLayout.SOUTH);   //new line
              pane.add(bottomPanel, BorderLayout.EAST);
              calcField.setLineWrap(true);
              calcField.setWrapStyleWord(true);
              calcField.setEditable(false);
              pane.add(scroll);
              scroll.setViewportView(calcField);
              pack();
              grfxPanel.setBounds(Rectangle);    //new line
    //actionEvent Listeners
        public void actionPerformed(ActionEvent event) {
              Object source = event.getSource();
              if (source == calcButton)  {
                   startCalculations();
              if (source == resetButton) {
                   reset();
              if (source == grfxButton)  {                  //new line
                    ChartPanel();
              if (source == exitButton)  {
                   end();
                        if (source == Choice1) {
                   options.setEnabled(false);
                   termField.setEnabled(true);
                   rateField.setEnabled(true);
              if (source == Choice2) {
                    options.setEnabled(true);
                    termField.setEnabled(false);
                    rateField.setEnabled(false);
    public void ChartPanel() {                       //newline
         JFrame grfxPanel = new JFrame();
        grfxPanel.setSize(400, 300);
        double[] values = new double[3];
        String[] names = new String[3];
        values[0] = 1;
        names[0] = "Item 1";
        values[1] = 2;
        names[1] = "Item 2";
        values[2] = 4;
        names[2] = "Item 3";
        grfxPanel.getContentPane().add(new ChartPanel(values, names, "title"));
    public class ChartPanel extends JPanel {
           private static final long serialVersionUID = 6L;     
    public double[] values;
    public String[] names;
    public String title;
    public ChartPanel(double[] v, String[] n, String t) {
        names = n;
        values = v;
        title = t;
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (values == null || values.length == 0)
          return;
        double minValue = 0;
        double maxValue = 0;
        for (int i = 0; i < values.length; i++) {
          if (minValue > values)
    minValue = values[i];
    if (maxValue < values[i])
    maxValue = values[i];
    Dimension d = getSize();
    int clientWidth = d.width;
    int clientHeight = d.height;
    int barWidth = clientWidth / values.length;
    Font titleFont = new Font("SansSerif", Font.BOLD, 20);
    FontMetrics titleFontMetrics = g.getFontMetrics(titleFont);
    Font labelFont = new Font("SansSerif", Font.PLAIN, 10);
    FontMetrics labelFontMetrics = g.getFontMetrics(labelFont);
    int titleWidth = titleFontMetrics.stringWidth(title);
    int y = titleFontMetrics.getAscent();
    int x = (clientWidth - titleWidth) / 2;
    g.setFont(titleFont);
    g.drawString(title, x, y);
    int top = titleFontMetrics.getHeight();
    int bottom = labelFontMetrics.getHeight();
    if (maxValue == minValue)
    return;
    double scale = (clientHeight - top - bottom) / (maxValue - minValue);
    y = clientHeight - labelFontMetrics.getDescent();
    g.setFont(labelFont);
    for (int i = 0; i < values.length; i++) {
    int valueX = i * barWidth + 1;
    int valueY = top;
    int height = (int) (values[i] * scale);
    if (values[i] >= 0)
    valueY += (int) ((maxValue - values[i]) * scale);
    else {
    valueY += (int) (maxValue * scale);
    height = -height;
    g.setColor(Color.red);
    g.fillRect(valueX, valueY, barWidth - 2, height);
    g.setColor(Color.black);
    g.drawRect(valueX, valueY, barWidth - 2, height);
    int labelWidth = labelFontMetrics.stringWidth(names[i]);
    x = i * barWidth + (barWidth - labelWidth) / 2;
    g.drawString(names[i], x, y);
    //Calculation Section
    void startCalculations() {
    NumberFormat currency = NumberFormat.getCurrencyInstance();
    //Variables
    double amount = 0;
    double term = 0;
    double interest = 0;
    double moIn = 0;
    double moTerm = 0;
    double payment = 0;
    double newPrin = amount;
    boolean Exception = false;
    //Input Validation
    try {
    amount = Double.parseDouble(loanField.getText());
    } catch (NumberFormatException e) {
    JOptionPane.showMessageDialog(null, "Commas, Letters, and Puncuation NOT Allowed",
    "Message Dialog", JOptionPane.ERROR_MESSAGE);
    loanField.setText(null);
    calcField.setText(null);
    //User's Loan Choice
    if (Choice2.isSelected())
    if(options.getSelectedIndex() == 0)
    term=7;
    interest=5.35;
    else if(options.getSelectedIndex() ==1)
    term=15;
    interest=5.5;
    else
    term=30;
    interest=5.75;
    else
    //More Validation      
    try
    term = Double.parseDouble(termField.getText());
    catch (NumberFormatException e)
    JOptionPane.showMessageDialog(this,"Enter amounts greater than zero","Please enter new amount",JOptionPane.ERROR_MESSAGE);
    Exception=true;
    termField.setText(null);
    try
    interest= Double.parseDouble(rateField.getText());
    catch (NumberFormatException e)
    JOptionPane.showMessageDialog(this,"Enter an Amount Greater Than Zero, % Not Allowed","Please enter Another Amount",JOptionPane.ERROR_MESSAGE);
    Exception=true;
    rateField.setText(null);
    if ((amount <= 0 || term <= 0 || interest <= 0) && (Exception == false)) {
    JOptionPane.showMessageDialog(null, "Please Enter a Number Greater Than ZERO.",
    "Message Dialog", JOptionPane.ERROR_MESSAGE);
    if(amount <= 0)
    loanField.setText(null);
    paymentField.setText(null);
    calcField.setText(null);
    termField.setText(null);
    rateField.setText(null);
    //Amortization Results Chart
    if (amount >7) {
    amount = Double.parseDouble(loanField.getText());
    moIn = (interest / 12) / 100;
    moTerm = term * 12;
    payment = amount * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTerm))));
    paymentField.setText("" + currency.format(payment));
    calcField.append("Period");
    calcField.append(" ");
    calcField.append("Payment Amount");
    calcField.append(" ");
    calcField.append("Interest Paid");
    calcField.append(" ");
    calcField.append("Principle Paid");
    calcField.append(" ");
    calcField.append("Loan Balance");
    calcField.append(" \n");
    for (int i = 1; i <= moTerm; i++) {
    double newIn = moIn * amount;
    double reduct = payment - newIn;
    newPrin = amount - reduct;
    amount = newPrin;
    calcField.append(" " + i);
    calcField.append(" " + currency.format(payment));
    calcField.append(" " + currency.format(newIn));
    calcField.append(" " + currency.format(reduct));
    calcField.append(" " + currency.format(newPrin) + "\n");
    calcField.setCaretPosition(0);
    // Program Reset, User Can Calculate Another Amount or Choose A Different Style
    void reset () {
    loanField.setText(null);
    paymentField.setText(null);
    calcField.setText(null);
    termField.setText(null);
    rateField.setText(null);
    // Exit Command
    void end() {
    System.exit(0);
    // main method
    public static void main(String args[]) {
    MortgageCalc_wk5 calc = new MortgageCalc_wk5();
    calc.pack();
    calc.setVisible(true);
    // end of program

    Will you please describe the problem.
    Your program works fine for one who doesn't know your precise requirement.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    import java.awt.Color;
    public class MortgageCalc_wk5 extends JFrame implements ActionListener {
      private static final long serialVersionUID = 6;
      private static final Rectangle rectangle = null;
      //Set up panels for Frame
      JPanel topPanel = new JPanel();
      JPanel bottomPanel = new JPanel();
      JPanel radioPanel = new JPanel();
      JPanel grfxPanel = new JPanel();
      //Set up Layout
      FlowLayout flowLayout = new FlowLayout();
      BorderLayout borderLayout = new BorderLayout();
      //Radio Choice Style Buttons
      JRadioButton Choice1 = new JRadioButton ("User Input", true);
      JRadioButton Choice2 = new JRadioButton ("User Selection", false);
      //Set up JLabels, JButtons, and JTextFields
      JLabel amountLabel = new JLabel("Loan Amount");
      JTextField loanField = new JTextField(7);
      JLabel termLabel = new JLabel("Term(Yrs)");
      JTextField termField = new JTextField(4);
      JLabel rateLabel = new JLabel("Rate");
      JTextField rateField = new JTextField(4);
      JComboBox options = new JComboBox();
      JLabel optionsLabel = new JLabel();
      JButton calcButton = new JButton("Calculate");
      JButton resetButton = new JButton("Reset");
      JButton exitButton = new JButton("Exit");
      JButton grfxButton = new JButton("Display Graphics");
      JLabel paymentLabel = new JLabel("Monthly Payment =");
      JTextField paymentField = new JTextField(6);
      JLabel outputLabel = new JLabel("Loan Amoritization Chart");
      JTextArea calcField = new JTextArea(10, 25);
      JScrollPane scroll
        = new JScrollPane(calcField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
          JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      ButtonGroup radioSelect = new ButtonGroup();
      JLabel grfxLabel =new JLabel ("Graphic Chart");
      JTextField grfxField = new JTextField ("Graphics");
      //Default constructor
      public MortgageCalc_wk5() {
        super("Tony's Calculator - Week 5");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
        //add ActionListeners
        loanField.addActionListener(this);
        termField.addActionListener(this);
        rateField.addActionListener(this);
        options.addActionListener(this);
        calcButton.addActionListener(this);
        grfxButton.addActionListener(this);
        resetButton.addActionListener(this);
        exitButton.addActionListener(this);
        Choice1.addActionListener(this);
        Choice2.addActionListener(this);
        //Top Panel Layout
        topPanel.setLayout(flowLayout);
        topPanel.add(amountLabel);
        topPanel.add(loanField);
        radioSelect.add(Choice1);
        radioSelect.add(Choice2);
        topPanel.add(Choice1);
        topPanel.add(Choice2);
        //Loan Term Options For JComboBox
        options.addItem("7 years @ 5.35%");
        options.addItem("15 years @ 5.5%");
        options.addItem("30 years @ 5.75%");
        options.setEnabled(false);
        topPanel.add(options);
        topPanel.add(termLabel);
        topPanel.add(termField);
        topPanel.add(rateLabel);
        topPanel.add(rateField);
        topPanel.add(paymentLabel);
        topPanel.add(paymentField);
        paymentField.setEditable(false);
    //Was Bottom Panel Now East Panel, Calculate Reset,Exit, and Display Buttons
        bottomPanel.add(calcButton);
        bottomPanel.add(resetButton);
        bottomPanel.add(exitButton);
        bottomPanel.add(grfxButton);
        calcButton.setBackground(Color.blue);
        resetButton.setBackground(Color.white);
        exitButton.setBackground(Color.red);
        calcField.setBackground(Color.orange);
        grfxPanel.setBackground(Color.green);
        grfxPanel.add(grfxField);
        //add Container
        Container pane = getContentPane();
        pane.setLayout(borderLayout);
        pane.add(topPanel, BorderLayout.NORTH);
        pane.add(calcField, BorderLayout.WEST);
        pane.add(grfxPanel, BorderLayout.SOUTH);
        pane.add(bottomPanel, BorderLayout.EAST);
        calcField.setLineWrap(true);
        calcField.setWrapStyleWord(true);
        calcField.setEditable(false);
        pane.add(scroll);
        scroll.setViewportView(calcField);
        pack();
        grfxPanel.setBounds(new Rectangle(0, 0, 400, 400));
      //actionEvent Listeners
      public void actionPerformed(ActionEvent event) {
        Object source = event.getSource();
        if (source == calcButton)  {
          startCalculations();
        else if (source == resetButton) {
          reset();
        else if (source == grfxButton)  {
          chartPanel();
        else if (source == exitButton)  {
          end();
        else if (source == Choice1) {
          options.setEnabled(false);
          termField.setEnabled(true);
          rateField.setEnabled(true);
        else if (source == Choice2) {
          options.setEnabled(true);
          termField.setEnabled(false);
          rateField.setEnabled(false);
      public void chartPanel() {
        JFrame grfxFrame = new JFrame();
        grfxFrame.setSize(400, 300);
        double[] values = new double[3];
        String[] names = new String[3];
        values[0] = 1;
        names[0] = "Item 1";
        values[1] = 2;
        names[1] = "Item 2";
        values[2] = 4;
        names[2] = "Item 3";
        grfxFrame.getContentPane().add(new ChartPanel(values, names, "title"));
        grfxFrame.setVisible(true);
      // public class ChartPanel extends JPanel {
      class ChartPanel extends JPanel {
        private static final long serialVersionUID = 6;
        public double[] values;
        public String[] names;
        public String title;
        public ChartPanel(double[] v, String[] n, String t) {
          names = n;
          values = v;
          title = t;
        public void paintComponent(Graphics g) {
          super.paintComponent(g);
          if (values == null || values.length == 0){
            return;
          double minValue = 0;
          double maxValue = 0;
          for (int i = 0; i < values.length; i++) {
            if (minValue > values){
    minValue = values[i];
    if (maxValue < values[i]){
    maxValue = values[i];
    Dimension d = getSize();
    int clientWidth = d.width;
    int clientHeight = d.height;
    int barWidth = clientWidth / values.length;
    Font titleFont = new Font("SansSerif", Font.BOLD, 20);
    FontMetrics titleFontMetrics = g.getFontMetrics(titleFont);
    Font labelFont = new Font("SansSerif", Font.PLAIN, 10);
    FontMetrics labelFontMetrics = g.getFontMetrics(labelFont);
    int titleWidth = titleFontMetrics.stringWidth(title);
    int y = titleFontMetrics.getAscent();
    int x = (clientWidth - titleWidth) / 2;
    g.setFont(titleFont);
    g.drawString(title, x, y);
    int top = titleFontMetrics.getHeight();
    int bottom = labelFontMetrics.getHeight();
    if (maxValue == minValue){
    return;
    double scale = (clientHeight - top - bottom) / (maxValue - minValue);
    y = clientHeight - labelFontMetrics.getDescent();
    g.setFont(labelFont);
    for (int i = 0; i < values.length; i++) {
    int valueX = i * barWidth + 1;
    int valueY = top;
    int height = (int) (values[i] * scale);
    if (values[i] >= 0){
    valueY += (int) ((maxValue - values[i]) * scale);
    else {
    valueY += (int) (maxValue * scale);
    height = -height;
    g.setColor(Color.red);
    g.fillRect(valueX, valueY, barWidth - 2, height);
    g.setColor(Color.black);
    g.drawRect(valueX, valueY, barWidth - 2, height);
    int labelWidth = labelFontMetrics.stringWidth(names[i]);
    x = i * barWidth + (barWidth - labelWidth) / 2;
    g.drawString(names[i], x, y);
    //Calculation Section
    void startCalculations() {
    NumberFormat currency = NumberFormat.getCurrencyInstance();
    //Variables
    double amount = 0;
    double term = 0;
    double interest = 0;
    double moIn = 0;
    double moTerm = 0;
    double payment = 0;
    double newPrin = amount;
    boolean Exception = false;
    //Input Validation
    try {
    amount = Double.parseDouble(loanField.getText());
    } catch (NumberFormatException e) {
    JOptionPane.showMessageDialog
    (null, "Commas, Letters, and Puncuation NOT Allowed",
    "Message Dialog", JOptionPane.ERROR_MESSAGE);
    loanField.setText(null);
    calcField.setText(null);
    //User's Loan Choice
    if (Choice2.isSelected()){
    if(options.getSelectedIndex() == 0){
    term=7;
    interest=5.35;
    else if(options.getSelectedIndex() ==1){
    term=15;
    interest=5.5;
    else{
    term=30;
    interest=5.75;
    else{
    //More Validation
    try{
    term = Double.parseDouble(termField.getText());
    catch (NumberFormatException e){
    JOptionPane.showMessageDialog
    (this,"Enter amounts greater than zero","Please enter new amount",
    JOptionPane.ERROR_MESSAGE);
    Exception=true;
    termField.setText(null);
    try{
    interest= Double.parseDouble(rateField.getText());
    catch (NumberFormatException e){
    JOptionPane.showMessageDialog
    (this, "Enter an Amount Greater Than Zero, % Not Allowed",
    "Please enter Another Amount", JOptionPane.ERROR_MESSAGE);
    Exception=true;
    rateField.setText(null);
    if ((amount <= 0 || term <= 0 || interest <= 0) && (Exception == false)) {
    JOptionPane.showMessageDialog
    (null, "Please Enter a Number Greater Than ZERO.",
    "Message Dialog", JOptionPane.ERROR_MESSAGE);
    if(amount <= 0)
    loanField.setText(null);
    paymentField.setText(null);
    calcField.setText(null);
    termField.setText(null);
    rateField.setText(null);
    //Amortization Results Chart
    if (amount >7) {
    amount = Double.parseDouble(loanField.getText());
    moIn = (interest / 12) / 100;
    moTerm = term * 12;
    payment
    = amount * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTerm))));
    paymentField.setText("" + currency.format(payment));
    calcField.append("Period");
    calcField.append(" ");
    calcField.append("Payment Amount");
    calcField.append(" ");
    calcField.append("Interest Paid");
    calcField.append(" ");
    calcField.append("Principle Paid");
    calcField.append(" ");
    calcField.append("Loan Balance");
    calcField.append(" \n");
    for (int i = 1; i <= moTerm; i++) {
    double newIn = moIn * amount;
    double reduct = payment - newIn;
    newPrin = amount - reduct;
    amount = newPrin;
    calcField.append(" " + i);
    calcField.append(" " + currency.format(payment));
    calcField.append(" " + currency.format(newIn));
    calcField.append(" " + currency.format(reduct));
    calcField.append
    (" " + currency.format(newPrin) + "\n");
    calcField.setCaretPosition(0);
    // Program Reset, User Can Calculate Another Amount or Choose A Different Style
    void reset () {
    loanField.setText(null);
    paymentField.setText(null);
    calcField.setText(null);
    termField.setText(null);
    rateField.setText(null);
    // Exit Command
    void end() {
    System.exit(0);
    // main method
    public static void main(String args[]) {
    java.util.Locale.setDefault(java.util.Locale.US);
    MortgageCalc_wk5 calc = new MortgageCalc_wk5();
    calc.pack();
    calc.setVisible(true);
    // end of program
    Message was edited by:
    hiwa

Maybe you are looking for

  • Adobe Photoshop CC Problems

    HI, I RECENTLY PURCHASED CC(PREVIOUSLY USING CS6) AND INSTALLED PHOTOSHOP CC ON MY PC WITH WIN 8, I7-3770, 16GB DDR3, 2G NVIDIA 670 GPU, 120GB SSD. AND I AM FACING A WERIED PROBLEM, LIKE WHEN I APPLY HIGH PASS FILTER TO A LAYER IT NOT AFFECTING IMMED

  • Querying XML data in  Object Relational tables

    Hi, Can someone help me? I have registered the purchaseorder.xsd in my database schema. [ http://www.oracle.com/technology/oramag/oracle/03-jul/o43xml.html ] declare l_bfile bfile; begin l_bfile := bfilename( 'XMLSAMP', 'purchaseOrder.xsd'); dbms_lob

  • Apple push notification service certificates

    I buy a server app to create my own network at my home business. the apple push notification service certificates have additional cost? I enter my pass but the app do not show me a price for a device. Normally all apple in-app upgrade show an alert.

  • Disable Pass-through

    Hi I imported a big update.xml with pass-through authentication configuration ... Now I can't log in web admin console as configurator. How can I disable the great pass-through? Big Thanks JXXE

  • LR Mobile- editing etc on iPad?

    I have LR 5 all upgraded etc, have now added LR mobile, mostly because I thought it would better allow mw to use the LR editing features for pictures I may take with my iPhone or iPad. I was able to get LR Mobile all set up with the App to use my iPa