Example usage for org.jfree.chart ChartFrame setSize

List of usage examples for org.jfree.chart ChartFrame setSize

Introduction

In this page you can find the example usage for org.jfree.chart ChartFrame setSize.

Prototype

public void setSize(int width, int height) 

Source Link

Document

The width and height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .

Usage

From source file:statisticsintegration.StatisticsLabr.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    List<String> Temp = new ArrayList<String>();
    List<String> check = new ArrayList<String>();
    List<Double> fnl = new ArrayList<>();
    List<String> frame = new ArrayList<String>();
    List<String> name = new ArrayList<String>();
    List<String> name2 = new ArrayList<String>();
    List<Double> frame2 = new ArrayList<Double>();
    List<Double> limitLeft = new ArrayList<>();
    List<Double> limitRight = new ArrayList<>();
    List<Double> trueLimitLeft = new ArrayList<>();
    List<Double> trueLimitRight = new ArrayList<>();
    List<Double> midpoint = new ArrayList<>();
    List<Integer> frequency = new ArrayList<>();
    List<Double> percent = new ArrayList<>();
    List<Integer> cf = new ArrayList<>();
    List<Double> cp = new ArrayList<>();

    Integer freq = 0;//www  .  ja v  a2s.  c om
    Double freqtot = 0.0;

    if (Categorical.isSelected() == true && Numerical.isSelected() == false) {
        for (int i = 0; i < jTable1.getRowCount(); i++) {
            frame.add((String) jTable1.getModel().getValueAt(i, 0));
        }
        Collections.sort(frame);

        Integer size = frame.size();
        System.out.println(size);
        for (Object b : frame) {
            String c = b + "";
            Temp.add(c);
        }

        for (int i = 0; i < jTable1.getRowCount(); i++) {
            for (int j = 0; j < jTable1.getColumnCount(); j++) {
                jTable1.setValueAt("", i, j);
            }
        }

        int ct = 0;
        for (Object z : frame) {
            String a = z + "";
            System.out.print(check.contains(a));
            if (!(check.contains(a))) {
                for (int i = 0; i < Temp.size(); i++) {
                    if (a.equals(Temp.get(i))) {
                        freq++;
                    }
                }
                Double freque = (((freq + .0) / size) * 100);
                fnl.add(freque);
                name.add(a);
                freqtot += freque;
                jTable1.getModel().setValueAt(a, ct, 0);
                jTable1.getModel().setValueAt(String.format("%1.1f", freque) + "%", ct, 1);
                ct++;
                freq = 0;

                check.add(a);
            }
            total.setText("Total :" + String.format("%1.1f", freqtot));
        }

        if (Chart.isSelected() == true) {
            DefaultPieDataset chart = new DefaultPieDataset();

            int h = 0;
            for (Double z : fnl) {
                chart.setValue(name.get(h) + "", new Double(z));
                h++;
            }
            JFreeChart mychart = ChartFactory.createPieChart3D(Desc.getText() + "", chart, true, true, true);
            PiePlot3D p = (PiePlot3D) mychart.getPlot();
            ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
            charteuFrame.setVisible(true);
            charteuFrame.setSize(450, 500);
        }

    } else if (Numerical.isSelected() == true && Categorical.isSelected() == false) {
        double subtrahend = 0.5;

        for (int i = 0; i < jTable1.getRowCount();) {
            double d = Double.parseDouble((String) jTable1.getModel().getValueAt(i, 0));
            frame2.add(d);
            i++;
        }
        double max = 0;
        double min = frame2.get(0);
        for (int j = 0; j < frame2.size(); j++) {
            System.out.print("Sulod");
            if (max < frame2.get(j)) {
                max = frame2.get(j);
            }
            if (min > frame2.get(j)) {
                min = frame2.get(j);
            }
        }

        System.out.print(frame2);
        double range = max - min;
        double k = Math.ceil(1 + 3.322 * Math.log10(frame2.size()));
        int width = (int) Math.ceil(range / k);

        System.out.println("char:   " + max + " " + min + " " + range + " " + k + " width: " + width);
        double limit = min;
        while (limit < max) {
            limitLeft.add(limit);
            limit += width;
        }

        for (int j = 0; j < limitLeft.size(); j++) {
            System.out.print(limitLeft.get(j) + " ");
        }

        double limit2 = min + width - 1;
        while (limit2 <= max) {
            limitRight.add(limit2);
            limit2 += width;
        }

        if (limitRight.get(limitRight.size() - 1) != max) {
            limitRight.add(max);
        }

        System.out.println();
        for (int j = 0; j < limitRight.size(); j++) {
            System.out.print(limitRight.get(j) + " ");
        }

        //true limit
        if (((String) choice.getSelectedItem()).equals("Integer")) {

            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitLeft.size(); j++) {
                System.out.print(trueLimitLeft.get(j) + " ");
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + 0.5);
            }

            System.out.println();
            for (int j = 0; j < trueLimitRight.size(); j++) {
                System.out.print(trueLimitRight.get(j) + " ");
            }

        } else if (((String) choice.getSelectedItem()).equals("Floating")) {

            int count1 = 0;
            float diff = 0;
            boolean flag = false;

            for (int j = 0; j < frame2.size(); j++) {
                double value = Math.floor(frame2.get(j));
                //                    System.out.println(frame.get(j));
                diff = (float) (frame2.get(j) - value);
                System.out.println("diff: " + diff);
                String counts = String.valueOf(diff);
                if (diff > 0.0) {
                    if (counts.length() - 1 > count1) {
                        count1 = counts.length() - 1;
                        System.out.println(count1);
                    }
                }
            }

            System.out.println(count1);

            for (int j = 0; j < count1 - 1; j++) {
                subtrahend /= 10;
                System.out.println(subtrahend);
            }

            System.out.println("sub: " + subtrahend);
            for (int j = 0; j < limitLeft.size(); j++) {
                trueLimitLeft.add(limitLeft.get(j) - subtrahend);
            }

            for (int j = 0; j < limitRight.size(); j++) {
                trueLimitRight.add(limitRight.get(j) + subtrahend);
            }
        }
        //midpoint
        for (int j = 0; j < limitLeft.size(); j++) {
            midpoint.add((limitLeft.get(j) + limitRight.get(j)) / 2);
        }

        System.out.println();
        for (int j = 0; j < midpoint.size(); j++) {
            System.out.print(midpoint.get(j) + " ");
        }

        //frequency
        for (int j = 0; j < limitLeft.size(); j++) {
            int count = 0;
            for (int m = 0; m < frame2.size(); m++) {
                if (frame2.get(m) >= limitLeft.get(j) && frame2.get(m) <= limitRight.get(j)) {
                    count++;
                }
            }
            frequency.add(count);
        }

        System.out.println();
        for (int j = 0; j < frequency.size(); j++) {
            System.out.print(frequency.get(j) + " ");
        }

        //percent
        for (int j = 0; j < frequency.size(); j++) {
            double pp = (((double) frequency.get(j) / frame2.size()) * 100);
            percent.add(pp);
        }

        System.out.println();
        for (int j = 0; j < percent.size(); j++) {
            System.out.print(percent.get(j) + " ");
        }

        int cff = 0;
        for (int j = 0; j < frequency.size(); j++) {
            cff += frequency.get(j);
            cf.add(cff);
        }

        System.out.println();
        for (int j = 0; j < cf.size(); j++) {
            System.out.print(cf.get(j) + " ");
        }

        double cpp = 0;
        for (int j = 0; j < percent.size(); j++) {
            cpp += percent.get(j);
            cp.add(cpp);
        }

        System.out.println();

        for (int j = 0; j < cp.size(); j++) {
            System.out.print(cp.get(j) + " ");
        }

        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        dtm.setRowCount(limitLeft.size());

        int ct = 0;
        if (collapse.isSelected() == true) {
            for (int j = 0; j < limitLeft.size(); j++) {
                if (ct == 0) {
                    jTable1.getModel().setValueAt("< " + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add("<");
                } else if (ct == limitLeft.size() - 1) {
                    jTable1.getModel().setValueAt("> " + limitLeft.get(j), ct, 1);
                    jTable1.getModel().setValueAt("-", ct, 3);
                    name.add(">");
                } else {
                    jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                    jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                    name.add(midpoint.get(j) + "");
                }
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }

        } else {
            for (int j = 0; j < limitLeft.size(); j++) {

                jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1);
                jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2);
                jTable1.getModel().setValueAt(midpoint.get(j), ct, 3);
                name.add(midpoint.get(j) + "");
                jTable1.getModel().setValueAt(frequency.get(j), ct, 4);
                jTable1.getModel().setValueAt(percent.get(j), ct, 5);
                jTable1.getModel().setValueAt(cf.get(j), ct, 6);
                jTable1.getModel().setValueAt(cp.get(j), ct, 7);
                ct++;
            }
        }
        if (Chart.isSelected() == true) {
            DefaultCategoryDataset chart = new DefaultCategoryDataset();

            int h = 0;
            for (Integer z : frequency) {
                chart.setValue(z, "Frequency", name.get(h));
                h++;
            }
            JFreeChart mychart = ChartFactory.createBarChart(Desc.getText() + "", "Midpoint", "Frequency",
                    chart, PlotOrientation.VERTICAL, true, false, false);
            CategoryPlot p = (CategoryPlot) mychart.getPlot();
            p.setDomainGridlinesVisible(true);
            p.getDomainAxis().setCategoryMargin(0.0);
            ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart);
            charteuFrame.setVisible(true);
            charteuFrame.setSize(450, 500);
        }
    }
}

From source file:ui.Interface.java

private void butChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butChartActionPerformed
    try {/*w  w w.j  a v  a2 s  .co m*/
        if (txtNumbersAll.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "Please fill out the Empty fields!",
                    "Sorting Algo Simulator v2.0", javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(InsertInstructionCount, "InsertionSort", "InsertionSort");
        dataset.setValue(SelectInstructionCount, "SelectionSort", "SelectionSort");
        JFreeChart chart = ChartFactory.createBarChart("Instruction Count", "Instruction Count",
                "Unique Counts", dataset, PlotOrientation.VERTICAL, false, true, false);
        chart.setBackgroundPaint(Color.white);
        chart.getTitle().setPaint(Color.blue);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.red);
        ChartFrame frame1 = new ChartFrame("Insertion Sort Vs Selection Sort - Performance Analyze", chart);

        Dimension screenSize = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
        Dimension windowSize = new Dimension(getPreferredSize());
        int wdwLeft2 = screenSize.width / 2 - windowSize.width / 2 - 200;
        int wdwTop2 = screenSize.height / 2 - windowSize.height / 2;
        frame1.setLocation(wdwLeft2, wdwTop2);
        frame1.pack();
        frame1.setSize(400, 350);
        frame1.setVisible(true);

        DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
        dataset2.setValue(InsertTimeDiff, "InsertionSort", "InsertionSort");
        dataset2.setValue(SelectTimeDiff, "SelectionSort", "SelectionSort");
        JFreeChart chart2 = ChartFactory.createBarChart("Time Complexity* (can be vary)", "Time Complexity",
                "Nano Seconds", dataset2, PlotOrientation.VERTICAL, false, true, false);
        chart2.setBackgroundPaint(Color.white);
        chart2.getTitle().setPaint(Color.blue);
        CategoryPlot p2 = chart2.getCategoryPlot();
        p2.setRangeGridlinePaint(Color.red);
        ChartFrame frame2 = new ChartFrame("Insertion Sort Vs Selection Sort - Performance Analyze", chart2);

        int wdwLeft = 50 + screenSize.width / 2 - windowSize.width / 2 + 200;
        int wdwTop = screenSize.height / 2 - windowSize.height / 2;
        frame2.setLocation(wdwLeft, wdwTop);
        frame2.pack();
        frame2.setVisible(true);
        frame2.setSize(400, 350);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java

private void createChart() {
    DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset();
    int selectedRow = vitalSignjTable.getSelectedRow();
    Member member = (Member) vitalSignjTable.getValueAt(selectedRow, 0);
    ArrayList<VitalSign> vitalSignList = member.getVitalSignList().getVitalSignList();
    /*At least 2 vital sign records needed to show chart */
    if (vitalSignList.isEmpty() || vitalSignList.size() == 1) {
        JOptionPane.showMessageDialog(this,
                "No vital signs or only one vital sign found. At least 2 vital sign records needed to show chart!",
                "Warning", JOptionPane.INFORMATION_MESSAGE);
        return;/*from w ww .  j  av a 2  s. c o m*/
    }
    for (VitalSign vitalSign : vitalSignList) {
        vitalSignDataset.addValue(vitalSign.getRespiratoryRate(), "RR", vitalSign.getTimestamp());
        vitalSignDataset.addValue(vitalSign.getHeartRate(), "HR", vitalSign.getTimestamp());
        vitalSignDataset.addValue(vitalSign.getBloodPressure(), "BP", vitalSign.getTimestamp());
        vitalSignDataset.addValue(vitalSign.getTemperature(), "Temp", vitalSign.getTimestamp());
    }

    JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Vital Sign Chart", "Time Stamp", "Rate",
            vitalSignDataset, PlotOrientation.VERTICAL, true, false, false);
    vitalSignChart.setBackgroundPaint(Color.white);
    CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot();
    vitalSignChartPlot.setBackgroundPaint(Color.lightGray);

    CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis();
    vitalSignDomainAxis
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis();
    vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame chartFrame = new ChartFrame("Chart", vitalSignChart);
    chartFrame.setVisible(true);
    chartFrame.setSize(500, 500);

}

From source file:UserInterface.SystemAdmin.ReportsJPanel.java

private void buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonActionPerformed
    if (c == null) {
        JOptionPane.showMessageDialog(null, "No Customer");
        return;// w w  w  .j a v  a 2  s  .  co  m
    }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (WaterUsage waterUsage : c.getWaterUsageHistory()) {
        dataset.setValue(waterUsage.getUsageVolume(), waterUsage.getDate(), "Usage Volume");
    }

    JFreeChart chart = ChartFactory.createBarChart("Customer Water Usage Trends over a period of time",
            "Time of Usage", "Gallons", dataset, PlotOrientation.VERTICAL, true, true, true);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.cyan);
    ChartFrame frame = new ChartFrame("Bar Char for Weight", chart);

    frame.setVisible(true);
    frame.setSize(450, 350);

}

From source file:UserInterface.SystemAdmin.ReportsJPanel.java

private void usageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usageActionPerformed

    int selectedRow = customerTable.getSelectedRow();

    if (selectedRow < 0) {
        JOptionPane.showMessageDialog(null, "Select a customer first");
        return;//from  w  ww .ja  va2 s .co  m
    }

    Customer customer = (Customer) customerTable.getValueAt(selectedRow, 0);

    if (customer.getWaterUsageHistory().size() == 0) {
        JOptionPane.showMessageDialog(null, "No water usage yet");
        return;
    }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (WaterUsage waterUsage : customer.getWaterUsageHistory()) {
        dataset.setValue(waterUsage.getUsageVolume(), waterUsage.getDate(), "Usage Volume");
    }

    JFreeChart chart = ChartFactory.createBarChart("Customer Water Usage Trends over a period of time",
            "Time of Usage", "Gallons", dataset, PlotOrientation.VERTICAL, true, true, true);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.cyan);
    ChartFrame frame = new ChartFrame("Bar Char for Weight", chart);

    frame.setVisible(true);
    frame.setSize(450, 350);

}

From source file:UserInterface.SystemAdmin.ReportsJPanel.java

private void flowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flowActionPerformed
    int selectedRow = customerTable.getSelectedRow();
    if (selectedRow < 0) {
        JOptionPane.showMessageDialog(null, "Select a customer first");
        return;// w  ww  . j av a2s  .c om
    }

    Customer customer = (Customer) customerTable.getValueAt(selectedRow, 0);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (SensorValue sensorValue : customer.getTargetSensor().getSensorValueList()) {
        dataset.addValue(sensorValue.getFlowrate(), "Date", sensorValue.getDate());
    }
    if (customer.getTargetSensor().getSensorValueList().size() == 1) {
        JFreeChart chart = ChartFactory.createBarChart(
                "Customer's water flowrate variation over a period of time", "Time of Usage",
                "FlowRate(gallons/sec)", dataset, PlotOrientation.VERTICAL, true, true, true);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.cyan);
        ChartFrame frame = new ChartFrame("Bar Char for Weight", chart);

        frame.setVisible(true);
        frame.setSize(450, 350);
    } else {
        JFreeChart chart = ChartFactory.createLineChart(
                "Customer's water flowrate variation over a period of time", "Time of Usage",
                "FlowRate(gallons/sec)", dataset, PlotOrientation.VERTICAL, true, true, true);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.cyan);
        ChartFrame frame = new ChartFrame("Bar Char for Weight", chart);
        RefineryUtilities.centerFrameOnScreen(frame);

        frame.setVisible(true);
        frame.setSize(450, 350);
    }

}

From source file:UserInterface.SystemAdmin.ReportsJPanel.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    int total = 0;
    //        for(Network network : system.getNetworkList()){
    //            for(Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()){
    //        for(Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()){
    //            if(organization instanceof CustomerOrganization){
    //                for(Employee employee : organization.getEmployeeDirectory().getEmployeeList()){
    //                    Customer customer = (Customer) employee;
    //                    total += customer.getTotalUsageVolume();
    //                }
    //            }
    //        }/*from ww w.j  a  va 2  s .c o  m*/
    //        }
    //        }

    for (Network network : system.getNetworkList()) {
        for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) {
            if (enterprise instanceof WaterEnterprise) {
                for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) {
                    if (organization instanceof CustomerOrganization) {
                        for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) {
                            Customer customer = (Customer) employee;
                            total += customer.getTotalUsageVolume();
                        }
                    }
                }
            }
        }
    }

    if (total == 0) {
        JOptionPane.showMessageDialog(null, "No Customer has used water yet");
        return;
    }
    DefaultPieDataset dataset = new DefaultPieDataset();
    for (Network network : system.getNetworkList()) {
        for (Enterprise enterprise : network.getEnterpriseDirectory().getEnterpriseList()) {
            for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) {
                if (organization instanceof CustomerOrganization) {
                    for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) {
                        Customer customer = (Customer) employee;
                        dataset.setValue(customer.getName(), customer.getTotalUsageVolume());
                    }
                }
            }
        }
    }

    JFreeChart chart = ChartFactory.createPieChart3D("Customer Water Usage", dataset, true, true, true);
    ChartFrame frame = new ChartFrame("Pie Chart demonstrating customer water usage ", chart);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(200);
    plot.setForegroundAlpha(0.50f);
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
    frame.setSize(650, 550);
}

From source file:graph.plotter.PieMenu.java

/**
 * This is the main working button for this class... It creates pie chart analyZing whole data set
 * //from   w  ww.j a  v a  2 s .  com
 * @param evt 
 */
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    try {
        DefaultPieDataset pieDataset = new DefaultPieDataset(); /** Initializing pie dataset*/
        int i;
        i = 0;
        String genre = "a";
        if (Button == 1) { /** For User Input*/
            while (i < cnt) {
                double aa = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString());
                String str = Table.getModel().getValueAt(i, 0).toString();

                pieDataset.setValue(str, new Double(aa));
                i++;
                genre += "a";

            }
        } else {
            try {
                BufferedReader br = new BufferedReader(new FileReader(jTextField3.getText()));
                String Line;
                while ((Line = br.readLine()) != null) {
                    String[] value = Line.split(",");
                    double val = Double.parseDouble(value[1]);
                    pieDataset.setValue(value[0], new Double(val));
                    //                dataset.setValue(new Double(val),genre,value[0]);
                    //                genre+="a";
                    // (value[0]);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(PieMenu.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(PieMenu.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true);
        PiePlot P = (PiePlot) chart.getPlot();
        P.setLabelLinkPaint(Color.BLACK);
        P.setBackgroundPaint(Color.white);
        ChartFrame frame = new ChartFrame("PieChart", chart);
        jButto1 = new JButton("Save");

        frame.setLayout(new BorderLayout());

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());

        GridBagConstraints gc = new GridBagConstraints();
        gc.gridx = 1;
        gc.gridy = 0;

        panel.add(jButto1, gc);

        frame.add(panel, BorderLayout.SOUTH);

        jButto1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                try {
                    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                    final File file1 = new File("Pie_Chart.png");
                    ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
                } catch (Exception ex) {

                }

            }
        });
        frame.setVisible(true);
        frame.setSize(858, 512);

        try {
            final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            final File file1 = new File("Pie_Chart.png");
            ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
        } catch (Exception e) {

        }
    } catch (Exception ex) {

    }
}

From source file:userinterface.DoctorWorkArea.DiagnosePatientJPanel.java

private void barBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_barBtnActionPerformed
    // TODO add your handling code here:
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    int i = 1;//  w ww .  jav  a2s.  c  o m
    Employee patient = (Employee) patientCombo.getSelectedItem();

    for (VitalSign vs : patient.getMedicalRecord().getVitalSignHistory().getVitalSignList()) {

        dataSet.setValue(vs.getBloodPressure(), "Blood Pressure", vs.getTimestamp());

        i++;

    }

    JFreeChart chart = ChartFactory.createBarChart("Blood Pressure Graph", "Timestamp", "Blood Pressure",
            dataSet, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame = new ChartFrame("Bar Chart for Patient", chart);
    frame.setVisible(true);
    frame.setSize(800, 550);

}

From source file:graph.plotter.BarMenu.java

/**
 * This is the main working button for this class... It creates bar chart analyZing whole data set
 * //from  www  .j  av  a2s .  co m
 * @param evt 
 */
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        int i;
        i = 0;
        String genre = " ";
        if (Button == 1)
            while (i < count) {
                double amount = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString());
                String name = Table.getModel().getValueAt(i, 0).toString();
                dataset.setValue(new Double(amount), genre, name);
                i++;
                genre += " ";

            }
        else {
            try {
                BufferedReader br = new BufferedReader(new FileReader(jTextField3.getText()));
                String Line;
                while ((Line = br.readLine()) != null) {
                    String[] value = Line.split(",");
                    double val = Double.parseDouble(value[1]);

                    dataset.setValue(new Double(val), genre, value[0]);
                    genre += " ";
                    System.out.println(value[0]);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(BarMenu.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(BarMenu.class.getName()).log(Level.SEVERE, null, ex);
            }

        }

        JFreeChart chart = ChartFactory.createBarChart3D("Amount", "Name", "Amount", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.white);
        p.setBackgroundPaint(Color.black);
        ChartFrame frame = new ChartFrame("Bar Chart", chart);
        saveButton = new JButton("Save image in Project Folder");

        frame.setLayout(new BorderLayout());

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());

        GridBagConstraints gc = new GridBagConstraints();
        gc.gridx = 1;
        gc.gridy = 0;

        panel.add(saveButton, gc);

        frame.add(panel, BorderLayout.SOUTH);

        saveButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                try {
                    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                    final File file1 = new File("Bar_Chart.png");
                    ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
                } catch (Exception ex) {

                }

            }
        });
        frame.setVisible(true);

        frame.setSize(858, 513);
    } catch (Exception e) {

    }
}