Example usage for org.jfree.data.jdbc JDBCPieDataset JDBCPieDataset

List of usage examples for org.jfree.data.jdbc JDBCPieDataset JDBCPieDataset

Introduction

In this page you can find the example usage for org.jfree.data.jdbc JDBCPieDataset JDBCPieDataset.

Prototype

public JDBCPieDataset(Connection con) 

Source Link

Document

Creates a new JDBCPieDataset using a pre-existing database connection.

Usage

From source file:org.jw.service.factory.StatisticsChartFactory.java

public static PieDataset createPieDataset(Connection conn, String query) throws SQLException {
    JDBCPieDataset dataset = new JDBCPieDataset(conn);
    dataset.executeQuery(query);//from  w ww. ja v a  2  s  . c  o m
    return dataset;
}

From source file:org.jfree.chart.demo.JDBCPieChartDemo.java

private PieDataset readData() {
    JDBCPieDataset jdbcpiedataset = null;
    String s = "jdbc:postgresql://nomad/jfreechartdb";
    try {//from w ww .ja v  a  2  s  .  co  m
        Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException classnotfoundexception) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(classnotfoundexception.getMessage());
    }
    try {
        Connection connection = DriverManager.getConnection(s, "jfreechart", "password");
        jdbcpiedataset = new JDBCPieDataset(connection);
        String s1 = "SELECT * FROM PIEDATA1;";
        jdbcpiedataset.executeQuery(s1);
        connection.close();
    } catch (SQLException sqlexception) {
        System.err.print("SQLException: ");
        System.err.println(sqlexception.getMessage());
    } catch (Exception exception) {
        System.err.print("Exception: ");
        System.err.println(exception.getMessage());
    }
    return jdbcpiedataset;
}

From source file:org.posterita.core.PieChart.java

public void getDataSetFromSQL(String sql) throws OperationException {

    JDBCPieDataset jdbcDataset = new JDBCPieDataset(DB.getConnectionRO());

    try {// w  w  w . j a  v  a2s.com
        jdbcDataset.executeQuery(sql);
        this.dataset = jdbcDataset;
    } catch (SQLException e) {
        throw new OperationException(e);
    }
}

From source file:fr.crnan.videso3d.ihm.PLNSPanel.java

private JToolBar createToolbar() {
    JToolBar toolbar = new JToolBar();

    JButton newGraph = new JButton("Nouveau");
    newGraph.addActionListener(new ActionListener() {

        @Override//from   ww w  .  j  a v a 2s. c o  m
        public void actionPerformed(ActionEvent e) {
            PLNSChartCreateUI chartCreator = new PLNSChartCreateUI(PLNSPanel.this);
            JFreeChart chart = null;
            try {
                if (chartCreator.showDialog(PLNSPanel.this)) {
                    switch (chartCreator.getChartType()) {
                    case 0://XY
                        JDBCXYDataset dataset = new JDBCXYDataset(plnsAnalyzer.getConnection());
                        dataset.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createXYAreaChart(chartCreator.getChartTitle(),
                                chartCreator.getAbscissesTitle(), chartCreator.getOrdonneesTitle(), dataset,
                                PlotOrientation.VERTICAL, false, true, false);
                        break;
                    case 1://Pie
                        JDBCPieDataset dataset1 = new JDBCPieDataset(plnsAnalyzer.getConnection());
                        dataset1.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createPieChart3D(chartCreator.getChartTitle(), dataset1, false,
                                true, false);
                        break;
                    case 2://Category
                        JDBCCategoryDataset dataset2 = new JDBCCategoryDataset(plnsAnalyzer.getConnection());
                        dataset2.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createBarChart(chartCreator.getChartTitle(),
                                chartCreator.getAbscissesTitle(), chartCreator.getOrdonneesTitle(), dataset2,
                                PlotOrientation.VERTICAL, false, true, false);
                        break;
                    default:
                        break;
                    }
                }
            } catch (SQLException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(PLNSPanel.this,
                        "<html>L'excution de la requte a chou :<br />" + e1 + "</html>",
                        "Impossible de crer le graphique", JOptionPane.ERROR_MESSAGE);
            }
            if (chart != null)
                addChart(chart);

        }
    });

    toolbar.add(newGraph);

    JButton retile = new JButton("Rarranger");
    retile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            desktop.tile(true);
        }
    });
    toolbar.add(retile);

    return toolbar;
}

From source file:com.sun.portal.os.portlets.PortletChartUtilities.java

protected static Dataset generatePieDataSet(Connection con, String sql) {
    JDBCPieDataset data = null;/*from www. ja v a2s. c om*/

    try {
        data = new JDBCPieDataset(con);

        data.executeQuery(sql);
        con.close();
    } catch (SQLException e) {
        System.err.print("SQLException: ");
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.print("Exception: ");
        System.err.println(e.getMessage());
    }
    return data;
}

From source file:com.sun.portal.os.portlets.ChartServlet.java

protected Dataset generatePieDataSet(Connection con, String sql) {
    JDBCPieDataset data = null;// w  w  w.j  a v  a 2 s . c  o m

    try {
        data = new JDBCPieDataset(con);

        data.executeQuery(sql);
        con.close();
    } catch (SQLException e) {
        System.err.print("SQLException: ");
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.print("Exception: ");
        System.err.println(e.getMessage());
    }
    return data;
}