Example usage for org.jfree.chart ChartPanel setSize

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

Introduction

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

Prototype

public void setSize(int width, int height) 

Source Link

Document

Resizes this component so that it has width width and height height .

Usage

From source file:vinci.project2.pkg1.View.java

/**
 * Initializes the chart//from w w  w. java 2 s . co m
 */
private void setChart() {
    final JFreeChart chart = createChart(gd.createDataset(xySeries1, xySeries2, xySeries3));
    ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.setSize(400, 300);

    ChartFrame chartFrame = new ChartFrame("Taxes", chart);
    chartFrame.setSize(400, 300);

    chartFrame.add(chartPanel);
    chartFrame.pack();
    chartFrame.setVisible(false);

    chartFrame1.add(chartPanel);

    chartFrame1.setSize(400, 300);
    chartFrame1.repaint();
    chartFrame1.revalidate();
}

From source file:Visao.grafico.GraficoRelatorioEstoque.java

public void criaGrafico() {
    CategoryDataset cds = createDataset();
    String titulo = "Grfico de " + ControlePrincipal.tipo_grafico;
    String eixoy = "Valores";
    String txt_legenda = "Ledenda:";
    boolean legenda = true;
    boolean tooltips = true;
    boolean urls = true;
    JFreeChart graf = ChartFactory.createBarChart3D(titulo, txt_legenda, eixoy, cds, PlotOrientation.VERTICAL,
            legenda, tooltips, urls);/*from  w  w  w.j  ava 2  s  .  c  o  m*/
    ChartPanel myChartPanel = new ChartPanel(graf, true);
    myChartPanel.setSize(jPaneGraficoRE.getWidth(), jPaneGraficoRE.getHeight());
    myChartPanel.setVisible(true);
    jPaneGraficoRE.removeAll();
    jPaneGraficoRE.add(myChartPanel);
    jPaneGraficoRE.revalidate();
    jPaneGraficoRE.repaint();
}

From source file:Sales.TabbedPaneWin.java

private void initCustom() throws Exception {
    ///Client//from w w w  .j a  v  a2s .co m
    //setting next CleientID
    nextClientId();
    clientIdTxtF2.setText(getNextClientIdStr());
    //refreshing Table
    try {
        jTable3.setModel(DbUtils.resultSetToTableModel(refreshTableClient()));
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex);
    }
    ////

    ///Agreemnrt
    nextAgreementId();
    agreementIdTxtF1.setText(getNextAgreementIdStr());

    try {
        jTable1.setModel(DbUtils.resultSetToTableModel(OOAgreement.dispalyTableExpiary()));
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex);//Logiing errors
        System.err.println(ex.getMessage());
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Unknown Error", JOptionPane.ERROR_MESSAGE);
    }
    ///////

    ///Invoice
    nextInvoiceId();
    invoiceNoTxtF.setText(getNextInvoiceIdStr());

    incrementations.nextOrderId();
    clientIdTxtF1.setText(incrementations.getNextOrderIdStr());

    try {
        selectItemsTable.setModel(DbUtils.resultSetToTableModel(refreshTableInvoice()));
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex);
    }
    ///

    jLabel45.setVisible(false);
    jLabel70.setVisible(false);
    jLabel73.setVisible(false);
    jLabel72.setVisible(false);
    jLabel18.setVisible(false);
    jLabel43.setVisible(false);
    jLabel1.setVisible(false);
    jLabel44.setVisible(false);
    jLabel71.setVisible(false);
    jLabel74.setVisible(false);
    jLabel75.setVisible(false);
    jLabel67.setVisible(false);
    jLabel74.setVisible(false);
    jLabel76.setVisible(false);

    jLabel80.setVisible(false);
    jLabel79.setVisible(false);
    jLabel82.setVisible(false);
    jLabel77.setVisible(false);
    jLabel78.setVisible(false);
    jLabel81.setVisible(false);
    jLabel83.setVisible(false);
    jLabel85.setVisible(false);
    jLabel84.setVisible(false);

    //Item PIe Chart
    DefaultPieDataset dataSet = new DefaultPieDataset();

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery(
                "Select distinct citem.item_code,citem.`type`,Sum(Invoice_Detail.saleQty) as 'Sum QTy'\n"
                        + "from citem,Invoice_Detail\n" + "where Invoice_Detail.itemCode = citem.item_code \n"
                        + "group by citem.item_code,citem.`type`");

        while (rs.next()) {
            dataSet.setValue(rs.getString("type"), rs.getInt("Sum QTy"));
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    JFreeChart chart = ChartFactory.createPieChart("Products Sold by Brand", dataSet, true, true, true);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(490, 376);

    jPanel11.add(chartPanel);
    jPanel11.setVisible(true);

    //Year Bar chart
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery(
                "select distinct DATE_FORMAT(Invoice.`date`,'%Y')as 'Year',SUM(invoice.grandTotal)\n"
                        + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y')\n" + "");

        while (rs.next()) {
            if (rs.getString("Year") != null) {
                dataset2.setValue(rs.getInt("SUM(invoice.grandTotal)"), rs.getString("Year"),
                        rs.getString("Year"));
            }
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    JFreeChart chart2 = ChartFactory.createBarChart("Yearly Sales", "Year", "Total Sales(Rs)", dataset2,
            PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel2 = new ChartPanel(chart2);
    chartPanel2.setSize(480, 420);

    jPanel18.add(chartPanel2);
    jPanel18.setVisible(true);

    //Month Bar Chart
    DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery(
                "select distinct DATE_FORMAT(Invoice.`date`,'%Y-%m')as 'Month',SUM(invoice.grandTotal)\n"
                        + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y-%m')");

        while (rs.next()) {

            String month = rs.getString("Month");
            if (month != null) {//if no data
                if (String.valueOf(Calendar.getInstance().get(Calendar.YEAR)).equals(month.substring(0, 4))) { //for sum up to curet year only
                    if ("01".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jan", "Jan");
                    } else if ("02".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Feb", "Feb");
                    } else if ("03".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Mar", "Mar");
                    } else if ("04".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Apr", "Apr");
                    } else if ("05".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "May", "May");
                    } else if ("06".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jun", "Jun");
                    } else if ("07".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jul", "Jul");
                    } else if ("08".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Aug", "Aug");
                    } else if ("09".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sep", "Sep");
                    } else if ("10".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Oct", "Oct");
                    } else if ("11".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Nov", "Nov");
                    } else if ("12".equals(month.substring(5, 7))) {
                        dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Dec", "Dec");
                    }
                }
            }
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    JFreeChart chart3 = ChartFactory.createBarChart(
            "Monthly Sales of " + String.valueOf(Calendar.getInstance().get(Calendar.YEAR)), "Month",
            "Total Sales(Rs)", dataset3, PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel3 = new ChartPanel(chart3);
    chartPanel3.setSize(480, 431);

    jPanel21.add(chartPanel3);
    jPanel21.setVisible(true);

    //Daily Bar Chart
    DefaultCategoryDataset dataset4 = new DefaultCategoryDataset();
    int weekNo = 1;

    try {
        Connection con = DBAccess.getConnection();
        Statement st = con.createStatement();
        SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;

        ResultSet rs = st.executeQuery(
                "select distinct DATE_FORMAT(Invoice.`date`,'%Y-%m-%d')as 'Day',SUM(invoice.grandTotal)\n"
                        + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y-%m-%d')");

        while (rs.next()) {
            String day = rs.getString("Day");

            if (day != null) {
                if (String.valueOf(Calendar.getInstance().get(Calendar.YEAR)).equals(day.substring(0, 4))) { //for sum up to curet year only

                    date = newDateFormat.parse(day);
                    day = date.toString().substring(0, 3);

                    if (day.equals("Mon")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Mon", "Mon");
                    } else if (day.equals("Tue")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Tue", "Tue");
                    } else if (day.equals("Wed")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Wed", "Wed");
                    } else if (day.equals("Thu")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Thu", "Thu");
                    } else if (day.equals("Fri")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Fri", "Fri");
                    } else if (day.equals("Sat")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sat", "Sat");
                    } else if (day.equals("Sun")) {
                        dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sun", "Sun");
                    }
                }
            }
        }

    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }

    Calendar cal = Calendar.getInstance();
    JFreeChart chart4 = ChartFactory.createBarChart(
            "Daily Sales of " + new SimpleDateFormat("MMM").format(cal.getTime()) + " Week " + weekNo, "Day",
            "Total Sales(Rs)", dataset4, PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel4 = new ChartPanel(chart4);
    chartPanel4.setSize(480, 431);

    jPanel25.add(chartPanel4);
    jPanel25.setVisible(true);
}