view.statistics.IssueChart.java Source code

Java tutorial

Introduction

Here is the source code for view.statistics.IssueChart.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view.statistics;

import controller.issueing.IssueController;
import controller.issueing.SampleDetailsController;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author Nands
 */
public class IssueChart extends javax.swing.JInternalFrame {

    /**
     * Creates new form IssueChart
     */
    public IssueChart(Dimension d) throws FileNotFoundException, IOException {
        initComponents();
        FileInputStream imgStream = null;
        File imgfile = new File("..\\BBMS\\src\\images\\drop.png");
        imgStream = new FileInputStream(imgfile);
        BufferedImage bi = ImageIO.read(imgStream);
        ImageIcon myImg = new ImageIcon(bi);
        this.setFrameIcon(myImg);
        setTitle("Issue Chart");
        setSize(d);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        yearCombo = new javax.swing.JComboBox();
        monthCombo = new javax.swing.JComboBox();
        showChartBtn1 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        optionCombo = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        chartCombo = new javax.swing.JComboBox();
        chartArea = new javax.swing.JPanel();

        jLabel1.setFont(new java.awt.Font("Rockwell Extra Bold", 1, 24)); // NOI18N
        jLabel1.setText("Issues");

        jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 204, 204), 2, true));

        jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel4.setText("Select Year");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel5.setText("Select Month");

        yearCombo.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        yearCombo.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009",
                        "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020",
                        "2021", "2022", "2023", "2024", "2025", "2026", "2027", "2028", "2029", "2030" }));

        monthCombo.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        monthCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "January", "February", "March",
                "April", "May", "June", "July", "August", "September", "October", "November", "December" }));

        showChartBtn1.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        showChartBtn1.setText("Show Chart");
        showChartBtn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showChartBtn1ActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel6.setText("Select By");

        optionCombo.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        optionCombo.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "Blood Groups", "Blood Components", "Gender", "Age Groups", "Hospitals", " " }));

        jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel7.setText("Chart Type");

        chartCombo.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        chartCombo.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Pie Chart", "Line Chart", "Bar Chart" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(32, 32, 32).addGroup(jPanel2Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(showChartBtn1)
                        .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                jPanel2Layout.createSequentialGroup()
                                                        .addGroup(jPanel2Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel5).addComponent(jLabel4))
                                                        .addGap(18, 18, 18))
                                        .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel6)
                                                .addGap(39, 39, 39)))
                                .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel7).addGap(29, 29,
                                        29)))
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(chartCombo, 0, 114, Short.MAX_VALUE)
                                        .addComponent(optionCombo, 0, 1, Short.MAX_VALUE)
                                        .addComponent(yearCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE)
                                        .addComponent(monthCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                Short.MAX_VALUE))))
                        .addContainerGap(33, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addGap(27, 27, 27)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6).addComponent(optionCombo,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 17,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4).addComponent(yearCombo,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 17,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5).addComponent(monthCombo,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel7).addComponent(chartCombo,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(94, 94, 94).addComponent(showChartBtn1).addContainerGap(141, Short.MAX_VALUE)));

        javax.swing.GroupLayout chartAreaLayout = new javax.swing.GroupLayout(chartArea);
        chartArea.setLayout(chartAreaLayout);
        chartAreaLayout.setHorizontalGroup(chartAreaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 716, Short.MAX_VALUE));
        chartAreaLayout.setVerticalGroup(chartAreaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(22, 22, 22)
                                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(41, 41, 41).addComponent(chartArea,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup().addGap(42, 42, 42).addComponent(jLabel1)))
                        .addContainerGap(51, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addGap(18, 18, 18)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(chartArea, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(42, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void showChartBtn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showChartBtn1ActionPerformed
        String option = "" + optionCombo.getSelectedItem();
        String chartType = "" + chartCombo.getSelectedItem();
        if (option.equals("Blood Components")) {
            try {
                int cryoCount = 0;
                int ffpCount = 0;
                int freshBloodCount = 0;
                int plasmaCount = 0;
                int plateletsCount = 0;

                ResultSet rst = null;
                String year = "" + yearCombo.getSelectedItem();
                String month = "" + monthCombo.getSelectedItem();
                rst = IssueController.getIssueInfo(year, month);

                while (rst.next()) {

                    String type = rst.getString("BloodType");
                    if (type.equalsIgnoreCase("CRYO")) {
                        cryoCount++;
                    } else if (type.equalsIgnoreCase("FFP")) {
                        ffpCount++;
                    } else if (type.equalsIgnoreCase("Fresh Blood")) {
                        freshBloodCount++;
                    } else if (type.equalsIgnoreCase("Plasma/CSP")) {
                        plasmaCount++;
                    } else if (type.equalsIgnoreCase("Platelets")) {
                        plateletsCount++;
                    }
                }

                if (chartType.equals("Pie Chart")) {
                    DefaultPieDataset piedataset = new DefaultPieDataset();
                    piedataset.setValue("CRYO", cryoCount);
                    piedataset.setValue("FFP", ffpCount);
                    piedataset.setValue("Fresh Blood", freshBloodCount);
                    piedataset.setValue("Plasma/CSP", plasmaCount);
                    piedataset.setValue("Platelets", plateletsCount);
                    JFreeChart chart = ChartFactory.createPieChart3D("Issued Blood Components", piedataset, true,
                            true, true);
                    ChartPanel panel = new ChartPanel(chart);
                    chart.setBackgroundPaint(Color.PINK);
                    chart.getTitle().setPaint(Color.RED);
                    chartArea.add(panel);
                    panel.setSize(chartArea.getSize());
                    panel.setVisible(true);
                } else {
                    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
                    dataset.setValue(cryoCount, "Issued Values", "CRYO");
                    dataset.setValue(ffpCount, "Issued Values", "FFP");
                    dataset.setValue(freshBloodCount, "Issued Values", "Fresh Blood");
                    dataset.setValue(plasmaCount, "Issued Values", "Plasma/CSP");
                    dataset.setValue(plateletsCount, "Issued Values", "Platelets");
                    if (chartType.equals("Bar Chart")) {
                        JFreeChart chart = ChartFactory.createBarChart3D("Issued Bloood Components",
                                "Blood Component", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true,
                                false);

                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    } else if (chartType.equals("Line Chart")) {
                        JFreeChart chart = ChartFactory.createLineChart3D("Issued Blood Components",
                                "Blood Component", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true,
                                false);

                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    }
                }

            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "-1Data Error!", "Warning!", JOptionPane.OK_OPTION);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (option.equals("Blood Groups")) {
            try {
                int Apos = 0;
                int Bpos = 0;
                int Aneg = 0;
                int Bneg = 0;
                int ABpos = 0;
                int Opos = 0;
                int ABneg = 0;
                int Oneg = 0;

                ResultSet rst = null;
                String year = "" + yearCombo.getSelectedItem();
                String month = "" + monthCombo.getSelectedItem();

                rst = IssueController.getIssueInfo(year, month);

                while (rst.next()) {

                    String type = rst.getString("BloodGroup");
                    if (type.equalsIgnoreCase("A+")) {
                        Apos++;
                    } else if (type.equalsIgnoreCase("B+")) {
                        Bpos++;
                    } else if (type.equalsIgnoreCase("A-")) {
                        Aneg++;
                    } else if (type.equalsIgnoreCase("B-")) {
                        Bneg++;
                    } else if (type.equalsIgnoreCase("AB+")) {
                        ABpos++;
                    } else if (type.equalsIgnoreCase("AB-")) {
                        ABneg++;
                    } else if (type.equalsIgnoreCase("O+")) {
                        Opos++;
                    } else if (type.equalsIgnoreCase("O-")) {
                        Oneg++;
                    }
                }

                if (chartType.equals("Pie Chart")) {
                    DefaultPieDataset piedataset = new DefaultPieDataset();
                    piedataset.setValue("A+", Apos);
                    piedataset.setValue("A-", Aneg);
                    piedataset.setValue("B+", Bpos);
                    piedataset.setValue("B-", Bneg);
                    piedataset.setValue("AB+", ABpos);
                    piedataset.setValue("AB-", ABneg);
                    piedataset.setValue("O+", Opos);
                    piedataset.setValue("O-", Oneg);

                    JFreeChart chart = ChartFactory.createPieChart3D("Issued Blood Groups", piedataset, true, true,
                            true);
                    ChartPanel panel = new ChartPanel(chart);
                    chart.setBackgroundPaint(Color.PINK);
                    chart.getTitle().setPaint(Color.RED);
                    chartArea.add(panel);
                    panel.setSize(chartArea.getSize());
                    panel.setVisible(true);
                } else {
                    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
                    dataset.setValue(Apos, "Issued Values", "A+");
                    dataset.setValue(Aneg, "Issued Values", "A-");
                    dataset.setValue(Bpos, "Issued Values", "B+");
                    dataset.setValue(Bneg, "Issued Values", "B-");
                    dataset.setValue(ABpos, "Issued Values", "AB+");
                    dataset.setValue(ABneg, "Issued Values", "AB-");
                    dataset.setValue(Opos, "Issued Values", "O+");
                    dataset.setValue(Oneg, "Issued Values", "O-");
                    if (chartType.equals("Bar Chart")) {
                        JFreeChart chart = ChartFactory.createBarChart3D("Issued Bloood Groups", "Blood Group",
                                "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false);

                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    } else if (chartType.equals("Line Chart")) {
                        JFreeChart chart = ChartFactory.createLineChart3D("Issued Blood Groups", "Blood Group",
                                "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false);
                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    }

                }
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "0Data Error!", "Warning!", JOptionPane.OK_OPTION);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (option.equals("Gender")) {
            try {
                int male = 0;
                int female = 0;

                ResultSet rst = null;
                String year = "" + yearCombo.getSelectedItem();
                String month = "" + monthCombo.getSelectedItem();
                rst = IssueController.getRequesteeInfo(year, month);

                while (rst.next()) {

                    String type = rst.getString("Gender");
                    if (type.equalsIgnoreCase("Male")) {
                        male++;
                    } else if (type.equalsIgnoreCase("Female")) {
                        female++;
                    }
                }

                if (chartType.equals("Pie Chart")) {
                    DefaultPieDataset piedataset = new DefaultPieDataset();
                    piedataset.setValue("Male", male);
                    piedataset.setValue("Female", female);

                    JFreeChart chart = ChartFactory.createPieChart3D("Blood Requestees", piedataset, true, true,
                            true);
                    ChartPanel panel = new ChartPanel(chart);
                    chart.setBackgroundPaint(Color.PINK);
                    chart.getTitle().setPaint(Color.RED);
                    chartArea.add(panel);
                    panel.setSize(chartArea.getSize());
                    panel.setVisible(true);
                } else {
                    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
                    dataset.setValue(male, "", "Male");
                    dataset.setValue(female, "", "Female");

                    if (chartType.equals("Bar Chart")) {
                        JFreeChart chart = ChartFactory.createBarChart3D("Blood Requestees", "Gender", "", dataset,
                                PlotOrientation.VERTICAL, false, true, false);

                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    } else if (chartType.equals("Line Chart")) {
                        JFreeChart chart = ChartFactory.createLineChart3D("Blood Requestees", "Gender", "", dataset,
                                PlotOrientation.VERTICAL, false, true, false);
                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    }
                }
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "1Data Error!", "Warning!", JOptionPane.OK_OPTION);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (option.equals("Hospitals")) {
            try {

                String[] hospitals = new String[10];
                int[] hospitalCount = new int[10];
                int noOfHospitals = 0;
                ResultSet rst = null;
                String year = "" + yearCombo.getSelectedItem();
                String month = "" + monthCombo.getSelectedItem();
                rst = SampleDetailsController.getAllHospitals();
                while (rst.next()) {
                    hospitals[noOfHospitals] = rst.getString("Name");
                    hospitalCount[noOfHospitals] = 0;
                    noOfHospitals++;
                }

                rst = IssueController.getRequesteeInfo(year, month);

                while (rst.next()) {
                    String type = rst.getString("Hospital");
                    for (int i = 0; i < noOfHospitals; i++) {
                        if (type.equalsIgnoreCase(hospitals[i])) {
                            hospitalCount[i]++;
                        }
                    }
                }

                if (chartType.equals("Pie Chart")) {
                    DefaultPieDataset piedataset = new DefaultPieDataset();
                    for (int i = 0; i < noOfHospitals; i++) {
                        piedataset.setValue(hospitals[i], hospitalCount[i]);
                    }

                    JFreeChart chart = ChartFactory.createPieChart3D("Issued Hospitals", piedataset, true, true,
                            true);
                    ChartPanel panel = new ChartPanel(chart);
                    chart.setBackgroundPaint(Color.PINK);
                    chart.getTitle().setPaint(Color.RED);
                    chartArea.add(panel);
                    panel.setSize(chartArea.getSize());
                    panel.setVisible(true);
                } else {
                    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
                    for (int i = 0; i < noOfHospitals; i++) {
                        dataset.setValue(hospitalCount[i], "Issued Values", hospitals[i]);
                    }

                    if (chartType.equals("Bar Chart")) {
                        JFreeChart chart = ChartFactory.createBarChart3D("Issued Hospitals", "Hospital",
                                "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false);

                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    } else if (chartType.equals("Line Chart")) {
                        JFreeChart chart = ChartFactory.createLineChart3D("Issued Hospitals", "Hospital",
                                "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false);
                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    }
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null, "2Data Error!", "Warning!", JOptionPane.OK_OPTION);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (option.equals("Age Groups")) {
            try {
                int[] ages = new int[10];
                for (int i = 0; i < 10; i++) {
                    ages[i] = 0;
                }
                ResultSet rst = null;
                String year = "" + yearCombo.getSelectedItem();
                String month = "" + monthCombo.getSelectedItem();
                rst = IssueController.getRequesteeInfo(year, month);

                while (rst.next()) {
                    int age = Integer.parseInt(rst.getString("Age"));
                    if (age <= 10 && age > 0) {
                        ages[0]++;
                    } else if (age <= 20 && age > 10) {
                        ages[1]++;
                    } else if (age <= 30 && age > 20) {
                        ages[2]++;
                    } else if (age <= 40 && age > 30) {
                        ages[3]++;
                    } else if (age <= 50 && age > 40) {
                        ages[4]++;
                    } else if (age <= 60 && age > 50) {
                        ages[5]++;
                    } else if (age <= 70 && age > 60) {
                        ages[6]++;
                    } else if (age <= 80 && age > 70) {
                        ages[7]++;
                    } else if (age <= 90 && age > 80) {
                        ages[8]++;
                    } else if (age <= 100 && age > 90) {
                        ages[9]++;
                    }
                }

                rst = IssueController.getRequesteeInfo(year, month);

                if (chartType.equals("Pie Chart")) {
                    DefaultPieDataset piedataset = new DefaultPieDataset();
                    for (int i = 0; i < 10; i++) {
                        piedataset.setValue(i * 10 + "-" + (i * 10 + 10), ages[i]);
                    }

                    JFreeChart chart = ChartFactory.createPieChart3D("Issued Age Groups", piedataset, true, true,
                            true);
                    ChartPanel panel = new ChartPanel(chart);
                    chart.setBackgroundPaint(Color.PINK);
                    chart.getTitle().setPaint(Color.RED);
                    chartArea.add(panel);
                    panel.setSize(chartArea.getSize());
                    panel.setVisible(true);
                } else {
                    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
                    for (int i = 0; i < 10; i++) {
                        dataset.setValue(ages[i], "Issued Values", i * 10 + "-" + (i * 10 + 10));
                    }

                    if (chartType.equals("Bar Chart")) {
                        JFreeChart chart = ChartFactory.createBarChart3D("Issued Age Groups", "Age Groups",
                                "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false);

                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    } else if (chartType.equals("Line Chart")) {
                        JFreeChart chart = ChartFactory.createLineChart3D("Issued Age Groups", "Age Groups",
                                "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false);
                        chart.setBackgroundPaint(Color.PINK);
                        chart.getTitle().setPaint(Color.RED);

                        CategoryPlot p = chart.getCategoryPlot();
                        p.setRangeGridlinePaint(Color.BLUE);
                        ChartPanel panel = new ChartPanel(chart);
                        chartArea.add(panel);
                        panel.setSize(chartArea.getSize());
                        panel.setVisible(true);
                    }
                }
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "3Data Error!", "Warning!", JOptionPane.OK_OPTION);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_showChartBtn1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel chartArea;
    private javax.swing.JComboBox chartCombo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JComboBox monthCombo;
    private javax.swing.JComboBox optionCombo;
    private javax.swing.JButton showChartBtn1;
    private javax.swing.JComboBox yearCombo;
    // End of variables declaration//GEN-END:variables
}