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

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

Introduction

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

Prototype

public JDBCCategoryDataset(Connection connection, String query) throws SQLException 

Source Link

Document

Creates a new dataset with the given database connection, and executes the supplied query to populate the dataset.

Usage

From source file:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java

public static void relatoriosFiliais() {
    String sql = "";

    try {// www .  j a  v a 2s .  com
        Connection conn = Conexoes.obterConexao();

        JDBCCategoryDataset ds = new JDBCCategoryDataset(conn, sql);

        ds.executeQuery(sql);

        JFreeChart grafico = ChartFactory.createLineChart("Grfico de Disponibilidade", "Filial", "Quantidade",
                ds, PlotOrientation.HORIZONTAL, true, true, true);

    } catch (SQLException | ClassNotFoundException ex) {
        System.err.println(ex.getMessage());
    }
}

From source file:sms.Reports.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    try {/*from   ww  w  . ja  v a 2 s.c om*/

        methods m = new methods();
        String query = "SELECT  updated_at ,(maths+eng+chem+phy+geo+hist+bio+agri+bs+kiswa+cre)/11 FROM exam WHERE year='"
                + 1 + "'";
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(m.getConnection(), query);
        JFreeChart chart = ChartFactory.createBarChart("QUR", "year", "maths", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        JFreeChart charti = ChartFactory.createLineChart("QUR", "year", "maths", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Chart", chart);
        frame.setVisible(true);
        frame.setSize(400, 450);

        ChartFrame frame1 = new ChartFrame("Chart", charti);
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation(dim.width / 10 - frame.getSize().width / 10,
                dim.height / 12 - frame.getSize().height / 12);
        frame1.setVisible(true);
        frame1.setSize(400, 450);
        frame1.setLocation(dim.width - frame1.getSize().width, dim.height - frame1.getSize().height);
        //.createAreaChart("QUERY CHART","maths"," eng", dataset,)
    } catch (SQLException ex) {
        Logger.getLogger(Reports.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:library.ChartGUI.java

private void btLine1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLine1ActionPerformed
    try {/*from w  w w .  ja v  a 2 s . c  o m*/
        // TODO add your handling code here:
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql0);
        JFreeChart chart = ChartFactory.createLineChart3D("Sum Brought Books", "Month", "Count", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Sum Brought Books Chart", chart);
        frame.setVisible(true);
        frame.setSize(1250, 700);
        frame.setResizable(false);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
}

From source file:library.ChartGUI.java

private void btLine2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLine2ActionPerformed
    // TODO add your handling code here:
    try {//from   ww  w  .j  ava 2s . c o m
        // TODO add your handling code here:
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql1);
        JFreeChart chart = ChartFactory.createLineChart3D("Sum New Readers", "Month", "Count", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Sum New Readers Chart", chart);
        frame.setVisible(true);
        frame.setSize(1250, 700);
        frame.setResizable(false);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
}

From source file:org.opennms.netmgt.charts.ChartUtils.java

/**
 * @param chartConfig//from   ww  w . j  a v a2s  .c  o m
 * @param baseDataSet
 * @throws SQLException
 */
private static DefaultCategoryDataset buildCategoryDataSet(BarChart chartConfig) throws SQLException {
    DefaultCategoryDataset baseDataSet = new DefaultCategoryDataset();
    /*
     * Configuration can contain more than one series.  This loop adds
     * single series data sets returned from sql query to a base data set
     * to be displayed in a the chart. 
     */
    Connection conn = null;
    try {
        conn = DataSourceFactory.getInstance().getConnection();
        Iterator<SeriesDef> it = chartConfig.getSeriesDefCollection().iterator();
        while (it.hasNext()) {
            SeriesDef def = it.next();
            JDBCCategoryDataset dataSet = new JDBCCategoryDataset(conn, def.getJdbcDataSet().getSql());

            for (int i = 0; i < dataSet.getRowCount(); i++) {
                for (int j = 0; j < dataSet.getColumnCount(); j++) {
                    baseDataSet.addValue(dataSet.getValue(i, j), def.getSeriesName(), dataSet.getColumnKey(j));
                }
            }
        }
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
    return baseDataSet;
}

From source file:library.ChartGUI.java

private void btArea1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btArea1ActionPerformed
    try {/*from ww  w .j  a v  a2s  .c o  m*/
        // TODO add your handling code here:
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql0);
        JFreeChart chart = ChartFactory.createAreaChart("Sum Brought Books", "Month", "Count", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Sum Brought Books Chart", chart);
        frame.setVisible(true);
        frame.setSize(1250, 700);
        frame.setResizable(false);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
}

From source file:library.ChartGUI.java

private void btBar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBar1ActionPerformed
    try {/*  w w  w.  j av  a2s.c o m*/
        // TODO add your handling code here:
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql0);
        JFreeChart chart = ChartFactory.createBarChart3D("Sum Brought Books", "Month", "Count", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Sum Brought Books Chart", chart);
        frame.setVisible(true);
        frame.setSize(1250, 700);
        frame.setResizable(false);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
}

From source file:library.ChartGUI.java

private void btArea2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btArea2ActionPerformed
    try {/*from   w w w .  j a  v  a  2 s. co m*/
        // TODO add your handling code here:
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql1);
        JFreeChart chart = ChartFactory.createAreaChart("Sum New Readers", "Month", "Count", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Sum New Readers Chart", chart);
        frame.setVisible(true);
        frame.setSize(1250, 700);
        frame.setResizable(false);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
}

From source file:library.ChartGUI.java

private void btBar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBar2ActionPerformed
    try {/*from w ww  .j  ava 2 s.c o m*/
        // TODO add your handling code here:
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(da.getConnection(), sql1);
        JFreeChart chart = ChartFactory.createBarChart3D("Sum New Readers", "Month", "Count", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartFrame frame = new ChartFrame("Sum New Readers Chart", chart);
        frame.setVisible(true);
        frame.setSize(1250, 700);
        frame.setResizable(false);
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex);
    }
}

From source file:com.main.Welcome.java

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    try {//w  ww .  ja  v a2s .  c  o  m
        String sql2 = "Select patient_name,reason,COUNT(*) FROM patient_visit_information WHERE reason='LUNG CANCER' OR reason ='HEART ATTACK' OR reason ='ASTHMA' OR reason ='HIGH BP' GROUP BY patient_name,reason";
        ps2 = con.prepareStatement(sql2);
        rs2 = ps2.executeQuery();
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(MysqlConnect.ConnectDB(), sql2);
        //          JFreeChart chart= ChartFactory.createLineChart("Quey chart","patient_name", "reason", dataset, PlotOrientation.VERTICAL,false,true,true);
        //           BarRenderer rener = null;
        //           CategoryPlot plot = null;
        //           rener = new BarRenderer();
        JFreeChart chart = ChartFactory.createBarChart("count(*)", "patient_name", "reason", dataset,
                PlotOrientation.VERTICAL, false, true, true);
        CategoryPlot p = chart.getCategoryPlot();
        p.setRangeGridlinePaint(Color.black);
        ChartFrame fra = new ChartFrame("Analytics Report", chart);
        fra.setVisible(true);
        fra.setSize(400, 650);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}