Example usage for org.jfree.chart ChartFactory createLineChart3D

List of usage examples for org.jfree.chart ChartFactory createLineChart3D

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createLineChart3D.

Prototype

public static JFreeChart createLineChart3D(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a line chart with default settings.

Usage

From source file:userinterface.PatientRole.PatientLikeMeJPanel.java

private void tblPatientsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPatientsMouseClicked

    frameLineGraph.setVisible(false);// w w w .java  2  s .com
    int selectedRow = tblPatients.getSelectedRow();
    if (selectedRow < 0) {
        return;
    }

    selectedPatient = (Patient) tblPatients.getValueAt(selectedRow, 0);
    selectedUA = selectedPatient.getUserAccount();

    //JOptionPane.showMessageDialog(null, selectedPatient + " " +selectedPatient.vitalSignHistory.getVitalSignHistory());
    if (selectedPatient.vitalSignHistory.getVitalSignHistory().size() > 0) {

        String legend = null;
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (VitalSign vs : selectedPatient.vitalSignHistory.getVitalSignHistory()) {

            /*if(vs.getState().equalsIgnoreCase("ABNORMAL"))
            legend=vs.getTimestamp().concat(" (" +vs.getState()+")");
            else*/
            legend = vs.getTimestamp();
            ///JOptionPane.showMessageDialog(null,vs);

            dataset.addValue(vs.getRespiratoryRate(), legend, "Respiratory Rate");
            dataset.addValue(vs.getHeartRate(), legend, "Heart Rate");
            dataset.addValue(vs.getSystolicBloodPressure(), legend, "Blood Pressure");
            dataset.addValue(vs.getWeight(), legend, "Weight");

        }

        JFreeChart chart = ChartFactory.createLineChart3D("Vital Signs", "Vital Signs", "Values", dataset,
                PlotOrientation.VERTICAL, true, true, true);
        CategoryPlot P = chart.getCategoryPlot();
        P.setRangeGridlinePaint(Color.BLACK);

        frameLineGraph.getContentPane().removeAll();
        //ChartFrame frame  = new ChartFrame("Bar Charts",chart);
        ChartPanel cp = new ChartPanel(chart);
        frameLineGraph.getContentPane().add(cp);
        //frameLineGraph.repaint();
        //frameLineGraph.setSize(650, 550);            
        frameLineGraph.setVisible(true);

    } else {
        JOptionPane.showMessageDialog(null, "There's no Vital Sign reported for this patient");
        return;
    }

}

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createLineChart3D(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart3D("Line Chart Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   www . j av a2 s  .c om*/

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LineRenderer3D renderer = (LineRenderer3D) plot.getRenderer();

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.orange, 0.0f, 0.0f, new Color(0, 64, 64));
    renderer.setWallPaint(gp);

    return chart;

}

From source file:view.statistics.RequestStatsAndPrediction.java

private void predictButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_predictButtonActionPerformed
    int year = yearChooser.getYear();
    int month = monthChooser.getMonth() + 1;

    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    int currentMonth = Calendar.getInstance().get(Calendar.MONTH) + 1;

    int data[][] = null;

    try {/*  ww  w  . jav  a 2 s .c  o  m*/
        data = sdcontroller.getYearlyRequestCountsOf(month);
    } catch (ClassNotFoundException ex) {
    } catch (SQLException ex) {
    }

    if (year >= currentYear && month >= currentMonth) {

        try {
            predictText.setText(Predictions.getPredictedRequestsOf(year, month) + "");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(RequestStatsAndPrediction.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        JOptionPane.showMessageDialog(this,
                "Predictions available only for future months. Only the graph will be drawn", "Error",
                JOptionPane.ERROR_MESSAGE);
        predictText.setText("Invalid input!");
    }

    //if (data != null) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (data != null) {
        for (int i = 0; i < data[0].length; i++) {
            dataset.setValue(data[1][i], "Year", data[0][i] + "");
        }
    }

    JFreeChart chart = ChartFactory.createLineChart3D(
            "Yearly Blood Request Count For The Month of " + getMontName(month + ""), "Year", "Request Count",
            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);
    panel.setPreferredSize(new java.awt.Dimension(200, 350));
    chartAreaPanel.setLayout(new GridLayout());
    chartAreaPanel.removeAll();
    chartAreaPanel.revalidate();
    chartAreaPanel.add(panel);
    chartAreaPanel.repaint();

    this.repaint();

    //}
}

From source file:view.statistics.IssueChart.java

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 {//  ww  w .j  a v  a 2 s  .  c  o m
            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);
        }
    }
}

From source file:direccion.Reportes.java

public Reportes() {

    String titulo = "Reportes";
    jFrame = new JFrame(titulo);
    jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    jFrame.setSize(800, 600);/*from   ww w.j  av  a2s.c om*/

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screenSize.width / 2) - (jFrame.getSize().width / 2);
    int y = (screenSize.height / 2) - (jFrame.getSize().height / 2);
    jFrame.setLocation(x, y);

    JLabel etiqueta = new JLabel("Reportes");
    etiqueta.setBounds(300, 25, 200, 50);
    etiqueta.setFont(new Font("Verdana", Font.BOLD, 30));
    etiqueta.setForeground(Color.BLACK);

    JMenuBar jMenuBar = new JMenuBar();

    JMenu acceso = new JMenu("Acceso a");
    JMenu ayuda = new JMenu("Ayuda");

    JMenuItem rec_hum = new JMenuItem("Recursos Humanos");
    JMenuItem conta = new JMenuItem("Contabilidad");
    JMenuItem ventas = new JMenuItem("Ventas");
    JMenuItem compras = new JMenuItem("Compras");
    JMenuItem inventario = new JMenuItem("Inventario");

    JMenuItem acerca_de = new JMenuItem("Acerca de");
    acerca_de.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Ayuda", "Ayuda", 3);
        }
    });

    acceso.add(rec_hum);
    acceso.add(conta);
    acceso.add(ventas);
    acceso.add(compras);
    acceso.add(inventario);

    ayuda.add(acerca_de);

    jMenuBar.add(acceso);
    jMenuBar.add(ayuda);

    JCalendar cal1 = new JCalendar();
    cal1.setBounds(250, 150, 400, 300);
    JCalendarCombo cal2 = new JCalendarCombo();
    cal2.setBounds(250, 150, 400, 300);

    String reportes[] = { "Mantenimiento", "Compras", "Ventas", "Inventario", "Contabilidad",
            "Recursos Humanos" };
    JComboBox combobox = new JComboBox(reportes);
    combobox.setBounds(300, 100, 150, 30);

    JLabel calendario = new JLabel("Fecha de Operacin:");
    calendario.setBounds(60, 150, 150, 30);

    JButton aceptar = new JButton("Aceptar");
    aceptar.setBounds(50, 200, 150, 30);
    aceptar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (combobox.getSelectedIndex() == 0) {

                datos_mantenimiento.setValue("Recursos Humanos", d_mant_rh);
                datos_mantenimiento.setValue("Contabilidad", d_mant_cont);
                datos_mantenimiento.setValue("Ventas", d_mant_vent);
                datos_mantenimiento.setValue("Compras", d_mant_comp);
                datos_mantenimiento.setValue("Inventario", d_mant_inv);
                datos_mantenimiento.setValue("Mantenimiento", d_mant_mant);

                Grafica = ChartFactory.createPieChart3D("Mantenimiento", datos_mantenimiento, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Mantenimiento.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Mantenimiento");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Mantenimiento.xls");
                        Cell celda;

                        String[] titulos = { "Recursos Humanos", "Contabilidad", "Ventas", "Compras",
                                "Inventario", "Mantenimiento" };
                        Double[] datos = { d_mant_rh, d_mant_cont, d_mant_vent, d_mant_comp, d_mant_inv,
                                d_mant_mant };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 1) {

                datos_compras.setValue("Nomina", d_comp_nom);
                datos_compras.setValue("Compras", d_comp_comp);
                datos_compras.setValue("Gastos Fijos", d_comp_gf);
                datos_compras.setValue("Gastos Variables", d_comp_gv);
                datos_compras.setValue("Gastos Otros", d_comp_go);

                Grafica = ChartFactory.createPieChart3D("Compras", datos_compras, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Compras.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        menu.setVisible(false);
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(850, 850);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Compras");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Compras.xls");
                        Cell celda;

                        String[] titulos = { "Nomina", "Compras", "Gastos Fijos", "Gastos Variables",
                                "Gastos Otros" };
                        Double[] datos = { d_comp_nom, d_comp_comp, d_comp_gf, d_comp_gv, d_comp_go };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 2) {

                datos_ventas.addValue(d_vent_s1_lu, "Semana 1", "Lunes");
                datos_ventas.addValue(d_vent_s1_ma, "Semana 1", "Martes");
                datos_ventas.addValue(d_vent_s1_mi, "Semana 1", "Mircoles");
                datos_ventas.addValue(d_vent_s1_ju, "Semana 1", "Jueves");
                datos_ventas.addValue(d_vent_s1_vi, "Semana 1", "Viernes");
                datos_ventas.addValue(d_vent_s1_sa, "Semana 1", "Sbado");
                datos_ventas.addValue(d_vent_s1_do, "Semana 1", "Domingo");

                datos_ventas.addValue(d_vent_s2_lu, "Semana 2", "Lunes");
                datos_ventas.addValue(d_vent_s2_ma, "Semana 2", "Martes");
                datos_ventas.addValue(d_vent_s2_mi, "Semana 2", "Mircoles");
                datos_ventas.addValue(d_vent_s2_ju, "Semana 2", "Jueves");
                datos_ventas.addValue(d_vent_s2_vi, "Semana 2", "Viernes");
                datos_ventas.addValue(d_vent_s2_sa, "Semana 2", "Sbado");
                datos_ventas.addValue(d_vent_s2_do, "Semana 2", "Domingo");

                Grafica = ChartFactory.createLineChart3D("Ventas", "Das", "Ingresos", datos_ventas,
                        PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Ventas.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Ventas");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Ventas.xls");
                        Cell celda;

                        String[] titulos1 = { "S1 lunes", "S1 martes", "S1 miercoles", "S1 jueves",
                                "S1 viernes", "S1 sabado", "S1 domingo" };
                        String[] titulos2 = { "S2 lunes", "S2 martes", "S2 miercoles", "S2 jueves",
                                "S2 viernes", "S2 sabado", "S2 domingo" };
                        Double[] datos1 = { d_vent_s1_lu, d_vent_s1_ma, d_vent_s1_mi, d_vent_s1_ju,
                                d_vent_s1_vi, d_vent_s1_sa, d_vent_s1_do };
                        Double[] datos2 = { d_vent_s2_lu, d_vent_s2_ma, d_vent_s2_mi, d_vent_s2_ju,
                                d_vent_s2_vi, d_vent_s2_sa, d_vent_s2_do };

                        int i, j;
                        for (i = 0; i < titulos1.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos1[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos1.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos1[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < titulos2.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(titulos2[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < datos2.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(datos2[j]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 3) {

                datos_inventario.setValue("Producto 1", d_inv_p1);
                datos_inventario.setValue("Producto 2", d_inv_p2);
                datos_inventario.setValue("Producto 3", d_inv_p3);
                datos_inventario.setValue("Producto 4", d_inv_p4);
                datos_inventario.setValue("Producto 5", d_inv_p5);

                Grafica = ChartFactory.createPieChart3D("Inventario", datos_inventario, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Inventario.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Inventario");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Inventario.xls");
                        Cell celda;

                        String[] titulos = { "Producto 1", "Producto 2", "Prroducto 3", "Producto 4",
                                "Producto 5" };
                        Double[] datos = { d_inv_p1, d_inv_p2, d_inv_p3, d_inv_p4, d_inv_p5 };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 4) {

                datos_contabilidad.addValue(d_cont_e_lu, "Entradas", "Lunes");
                datos_contabilidad.addValue(d_cont_e_ma, "Entradas", "Martes");
                datos_contabilidad.addValue(d_cont_e_mi, "Entradas", "Mircoles");
                datos_contabilidad.addValue(d_cont_e_ju, "Entradas", "Jueves");
                datos_contabilidad.addValue(d_cont_e_vi, "Entradas", "Viernes");
                datos_contabilidad.addValue(d_cont_e_sa, "Entradas", "Sbado");
                datos_contabilidad.addValue(d_cont_e_do, "Entradas", "Domingo");

                datos_contabilidad.addValue(d_cont_s_lu, "Salidas", "Lunes");
                datos_contabilidad.addValue(d_cont_s_ma, "Salidas", "Martes");
                datos_contabilidad.addValue(d_cont_s_mi, "Salidas", "Mircoles");
                datos_contabilidad.addValue(d_cont_s_ju, "Salidas", "Jueves");
                datos_contabilidad.addValue(d_cont_s_vi, "Salidas", "Viernes");
                datos_contabilidad.addValue(d_cont_s_sa, "Salidas", "Sbado");
                datos_contabilidad.addValue(d_cont_s_do, "Salidas", "Domingo");

                datos_contabilidad.addValue(d_cont_u_lu, "Utilidades", "Lunes");
                datos_contabilidad.addValue(d_cont_u_ma, "Utilidades", "Martes");
                datos_contabilidad.addValue(d_cont_u_mi, "Utilidades", "Mircoles");
                datos_contabilidad.addValue(d_cont_u_ju, "Utilidades", "Jueves");
                datos_contabilidad.addValue(d_cont_u_vi, "Utilidades", "Viernes");
                datos_contabilidad.addValue(d_cont_u_sa, "Utilidades", "Sbado");
                datos_contabilidad.addValue(d_cont_u_do, "Utilidades", "Domingo");

                Grafica = ChartFactory.createLineChart3D("Contabilidad", "Das", "Ingresos",
                        datos_contabilidad, PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Contabilidad.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Contabilidad");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Contabilidad.xls");
                        Cell celda;

                        String[] t_ent = { "E lunes", "E martes", "E miercoles", "E jueves", "E viernes",
                                "E sabado", "E domingo" };
                        String[] t_sal = { "S lunes", "S martes", "S miercoles", "S jueves", "S viernes",
                                "S sabado", "S domingo" };
                        String[] t_uti = { "U lunes", "U martes", "U miercoles", "U jueves", "U viernes",
                                "U sabado", "U domingo" };
                        Double[] d_ent = { d_cont_e_lu, d_cont_e_ma, d_cont_e_mi, d_cont_e_ju, d_cont_e_vi,
                                d_cont_e_sa, d_cont_e_do };
                        Double[] d_sal = { d_cont_s_lu, d_cont_s_ma, d_cont_s_mi, d_cont_s_ju, d_cont_s_vi,
                                d_cont_s_sa, d_cont_s_do };
                        Double[] d_uti = { d_cont_u_lu, d_cont_u_ma, d_cont_u_mi, d_cont_u_ju, d_cont_u_vi,
                                d_cont_u_sa, d_cont_u_do };

                        int i, j, k;
                        for (i = 0; i < t_ent.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(t_ent[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < d_ent.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(d_ent[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < t_sal.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(t_sal[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < d_sal.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(d_sal[j]);
                        }
                        fila = sheet.createRow(6);
                        for (k = 0; k < t_uti.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(t_uti[k]);
                        }
                        fila = sheet.createRow(7);
                        for (k = 0; k < d_uti.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(d_uti[k]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 5) {

                datos_rec_hum.addValue(d_rh_a_lu, "Asistencias", "Lunes");
                datos_rec_hum.addValue(d_rh_a_ma, "Asistencias", "Martes");
                datos_rec_hum.addValue(d_rh_a_mi, "Asistencias", "Mircoles");
                datos_rec_hum.addValue(d_rh_a_ju, "Asistencias", "Jueves");
                datos_rec_hum.addValue(d_rh_a_vi, "Asistencias", "Viernes");
                datos_rec_hum.addValue(d_rh_a_sa, "Asistencias", "Sbado");
                datos_rec_hum.addValue(d_rh_a_do, "Asistencias", "Domingo");

                datos_rec_hum.addValue(d_rh_r_lu, "Retardos", "Lunes");
                datos_rec_hum.addValue(d_rh_r_ma, "Retardos", "Martes");
                datos_rec_hum.addValue(d_rh_r_mi, "Retardos", "Mircoles");
                datos_rec_hum.addValue(d_rh_r_ju, "Retardos", "Jueves");
                datos_rec_hum.addValue(d_rh_r_vi, "Retardos", "Viernes");
                datos_rec_hum.addValue(d_rh_r_sa, "Retardos", "Sbado");
                datos_rec_hum.addValue(d_rh_r_do, "Retardos", "Domingo");

                datos_rec_hum.addValue(d_rh_f_lu, "Faltas", "Lunes");
                datos_rec_hum.addValue(d_rh_f_ma, "Faltas", "Martes");
                datos_rec_hum.addValue(d_rh_f_mi, "Faltas", "Mircoles");
                datos_rec_hum.addValue(d_rh_f_ju, "Faltas", "Jueves");
                datos_rec_hum.addValue(d_rh_f_vi, "Faltas", "Viernes");
                datos_rec_hum.addValue(d_rh_f_sa, "Faltas", "Sbado");
                datos_rec_hum.addValue(d_rh_f_do, "Faltas", "Domingo");

                Grafica = ChartFactory.createBarChart3D("Recursos Humanos", "Das", "Nmero de Empleados",
                        datos_rec_hum, PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Recursos Humanos.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Recursos Humanos");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Recursos Humanos.xls");
                        Cell celda;

                        String[] t_asi = { "A lunes", "A martes", "A miercoles", "A jueves", "A viernes",
                                "A sabado", "A domingo" };
                        String[] t_ret = { "R lunes", "R martes", "R miercoles", "R jueves", "R viernes",
                                "R sabado", "R domingo" };
                        String[] t_fal = { "F lunes", "F martes", "F miercoles", "F jueves", "F viernes",
                                "F sabado", "F domingo" };
                        int[] d_asi = { d_rh_a_lu, d_rh_a_ma, d_rh_a_mi, d_rh_a_ju, d_rh_a_vi, d_rh_a_sa,
                                d_rh_a_do };
                        int[] d_ret = { d_rh_r_lu, d_rh_r_ma, d_rh_r_mi, d_rh_r_ju, d_rh_r_vi, d_rh_r_sa,
                                d_rh_r_do };
                        int[] d_fal = { d_rh_f_lu, d_rh_r_ma, d_rh_r_mi, d_rh_r_ju, d_rh_r_vi, d_rh_r_sa,
                                d_rh_r_do };

                        int i, j, k;
                        for (i = 0; i < t_asi.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(t_asi[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < d_asi.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(d_asi[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < t_ret.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(t_ret[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < d_ret.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(d_ret[j]);
                        }
                        fila = sheet.createRow(6);
                        for (k = 0; k < t_fal.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(t_fal[k]);
                        }
                        fila = sheet.createRow(7);
                        for (k = 0; k < d_fal.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(d_fal[k]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
        }
    });

    jPanel = new JPanel();
    jPanel.setLayout(null);

    jPanel.add(cal1);
    jPanel.add(cal2);
    jPanel.add(etiqueta);
    jPanel.add(combobox);
    jPanel.add(calendario);
    jPanel.add(aceptar);
    jFrame.setJMenuBar(jMenuBar);
    jFrame.add(jPanel);

    jFrame.setVisible(true);
}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private byte[] generateLineChart(String siteId, CategoryDataset dataset, int width, int height,
        boolean render3d, float transparency, boolean itemLabelsVisible, boolean smallFontInDomainAxis) {
    JFreeChart chart = null;//  www .  j a  va2 s.  co m
    if (render3d)
        chart = ChartFactory.createLineChart3D(null, null, null, dataset, PlotOrientation.VERTICAL, true, false,
                false);
    else
        chart = ChartFactory.createLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, false,
                false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set transparency
    plot.setForegroundAlpha(transparency);

    // set background
    chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set antialias
    chart.setAntiAlias(true);

    // set domain axis font size
    if (smallFontInDomainAxis && !canUseNormalFontSize(width)) {
        plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 8));
        plot.getDomainAxis().setCategoryMargin(0.05);
    }

    // set outline
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setDrawOutlines(true);

    // item labels
    if (itemLabelsVisible) {
        plot.getRangeAxis().setUpperMargin(0.2);
        renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
            private static final long serialVersionUID = 1L;

            @Override
            public String generateLabel(CategoryDataset dataset, int row, int column) {
                Number n = dataset.getValue(row, column);
                if (n.intValue() != 0)
                    //return n.intValue()+"";
                    return n.toString();
                return "";
            }
        });
        renderer.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 8));
        renderer.setItemLabelsVisible(true);
    }

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        LOG.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:hudson.plugins.plot.PlotData.java

/**
 * Creates a Chart of the style indicated by getEffStyle() using the given dataset.
 * Defaults to using createLineChart.// w ww .  j av  a 2  s.  c  om
 */
private JFreeChart createChart(PlotCategoryDataset dataset) {
    String s = getUrlStyle();
    if (s.equalsIgnoreCase("area")) {
        return ChartFactory.createAreaChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("bar")) {
        return ChartFactory.createBarChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("bar3d")) {
        return ChartFactory.createBarChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("line3d")) {
        return ChartFactory.createLineChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedarea")) {
        return ChartFactory.createStackedAreaChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedbar")) {
        return ChartFactory.createStackedBarChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("stackedbar3d")) {
        return ChartFactory.createStackedBarChart3D(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(),
                dataset, PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    if (s.equalsIgnoreCase("waterfall")) {
        return ChartFactory.createWaterfallChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
                PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
    }
    return ChartFactory.createLineChart(getURLTitle(), /*categoryAxisLabel=*/null, getYaxis(), dataset,
            PlotOrientation.VERTICAL, hasLegend(), /*tooltips=*/true, /*url=*/false);
}

From source file:org.adempiere.apps.graph.ChartBuilder.java

private JFreeChart create3DLineChart() {
    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart3D(chartModel.get_Translation(MChart.COLUMNNAME_Name), // chart title
            chartModel.get_Translation(MChart.COLUMNNAME_DomainLabel), // domain axis label
            chartModel.get_Translation(MChart.COLUMNNAME_RangeLabel), // range axis label
            getCategoryDataset(), // data
            X_AD_Chart.CHARTORIENTATION_Horizontal.equals(chartModel.getChartOrientation())
                    ? PlotOrientation.HORIZONTAL
                    : PlotOrientation.VERTICAL, // orientation
            chartModel.isDisplayLegend(), // include legend
            true, // tooltips?
            true // URLs?
    );/*from ww w. jav a  2  s. c  om*/

    setupCategoryChart(chart);
    return chart;
}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

public JFreeChart makeLineChart(ChartModel chartModel, MultiSeriesDataModel dataModel,
        IChartLinkGenerator linkGenerator) {
    DefaultCategoryDataset categoryDataset = createCategoryDataset(dataModel);
    org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel
            .getPlot();/*from ww  w . j a  va 2  s. c  om*/

    String title = "";
    if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null)
            && (chartModel.getTitle().getText().trim().length() > 0)) {
        title = chartModel.getTitle().getText();
    }
    AxesLabels axesLabels = getAxesLabels(chartModel);
    PlotOrientation plotOrientation = (twoAxisPlot.getOrientation() == Orientation.HORIZONTAL)
            ? PlotOrientation.HORIZONTAL
            : PlotOrientation.VERTICAL;
    boolean showLegend = (chartModel.getLegend() != null) && (chartModel.getLegend().getVisible());
    JFreeChart chart = null;

    LinePlot linePlot = (LinePlot) twoAxisPlot;
    if (linePlot.getFlavor() == LinePlotFlavor.THREED) {
        chart = ChartFactory.createLineChart3D(title, axesLabels.domainAxisLabel, axesLabels.rangeAxisLabel,
                categoryDataset, plotOrientation, showLegend, true, false);
    } else {
        chart = ChartFactory.createLineChart(title, axesLabels.domainAxisLabel, axesLabels.rangeAxisLabel,
                categoryDataset, plotOrientation, showLegend, true, false);
        Stroke stroke = getLineStyleStroke(linePlot.getFlavor(), linePlot.getLineWidth());
        ((CategoryPlot) chart.getPlot()).getRenderer().setStroke(stroke);
    }

    initCategoryPlot(chart, chartModel, linkGenerator);
    initChart(chart, chartModel);

    return chart;
}

From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java

/**
 * onClick button Line Bar 3D Chart. <br>
 * /*from   www. j a v a2s.  c  o m*/
 * @param event
 * @throws IOException
 */
public void onClick$button_CustomerChart_LineBar3D(Event event) throws InterruptedException, IOException {
    // logger.debug(event.toString());

    div_chartArea.getChildren().clear();

    // get the customer ID for which we want show a chart
    long kunId = getCustomer().getId();

    // get a list of data
    List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId);

    if (kunAmountList.size() > 0) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for (ChartData chartData : kunAmountList) {

            Calendar calendar = new GregorianCalendar();
            calendar.setTime(chartData.getChartKunInvoiceDate());

            int month = calendar.get(Calendar.MONTH) + 1;
            int year = calendar.get(Calendar.YEAR);
            String key = String.valueOf(month) + "/" + String.valueOf(year);

            BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3);
            String amount = String.valueOf(bd.doubleValue());

            // fill the data
            dataset.setValue(new Double(chartData.getChartKunInvoiceAmount().doubleValue()), "2009",
                    key + " " + amount);
        }

        String title = "Monthly amount for year 2009";
        PlotOrientation po = PlotOrientation.VERTICAL;
        JFreeChart chart = ChartFactory.createLineChart3D(title, "Month", "Amount", dataset, po, true, true,
                true);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null);
        byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);

        AImage chartImage = new AImage("Line Bar Chart 3D", bytes);

        Image img = new Image();
        img.setContent(chartImage);
        img.setParent(div_chartArea);

    } else {

        div_chartArea.getChildren().clear();

        Label label = new Label();
        label.setValue("This customer have no data for showing in a chart!");

        label.setParent(div_chartArea);

    }
}