Example usage for org.jfree.chart ChartFrame add

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

Introduction

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

Prototype

public Component add(String name, Component comp) 

Source Link

Document

Adds the specified component to this container.

Usage

From source file:graph.plotter.PieMenu.java

/**
 * This is the main working button for this class... It creates pie chart analyZing whole data set
 * //w  ww .  j  a  v a 2  s .c o m
 * @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:graph.plotter.BarMenu.java

/**
 * This is the main working button for this class... It creates bar chart analyZing whole data set
 * //from w  w  w.  j  av  a  2s .c  om
 * @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) {

    }
}

From source file:graph.plotter.LineGraph.java

/**
 * This is the main working button for this class... It creates Line Graph analyZing whole data set
 * /*from w w w  .j  av  a  2s. com*/
 * @param evt 
 */
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        int i;
        i = 0;
        String genre = " ";
        if (button1 == 2) {
            if (button2 == 1)
                while (i < cnt) {
                    double aa = Double.parseDouble(Table.getModel().getValueAt(i, 1).toString());
                    String str = Table.getModel().getValueAt(i, 0).toString();
                    dataset.setValue(new Double(aa), genre, str);
                    i++;
                    //genre+=" ";

                }
            else {
                try {
                    BufferedReader br = new BufferedReader(new FileReader(jTextField4.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(LineGraph.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(LineGraph.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        } else if (button1 == 1) {

            String input = jTextField1.getText();
            input = input.replaceAll("sin", "@");
            input = input.replaceAll("cos", "#");
            input = input.replaceAll("tan", "Q");
            input = input.replaceAll("log", "~");
            input = input.replaceAll("e", "&");
            input = input.replaceAll("cosec", "r");
            input = input.replaceAll("cot", "w");
            input = input.replaceAll("sec", "y");

            //System.out.println(input);
            int len;
            len = input.length();
            String so = ".";

            for (ind = 0; ind < 360; ind++) {
                String gini = input;

                String sa = Integer.toString(ind);
                gini = gini.replaceAll("X", sa);

                Polish polish = new Polish(gini);
                double Calculate = Polish.Calculate();
                dataset.setValue(new Double(Calculate), ".", sa);
                so += ".";
            }

        }

        JFreeChart chart = ChartFactory.createLineChart("Line Graph", "X - Axis", "Y - Axis", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.YELLOW);
        p.setBackgroundPaint(Color.BLACK);
        ChartFrame frame = new ChartFrame("Line Chart", 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("Line_Chart.png");
                    ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
                } catch (Exception ex) {

                }

            }
        });
        frame.setVisible(true);

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

    }
}