Example usage for org.jfree.chart ChartFactory createBarChart

List of usage examples for org.jfree.chart ChartFactory createBarChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createBarChart.

Prototype

public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a bar chart.

Usage

From source file:com.joey.software.Launcher.microneedleAnalysis.DataAnalysisViewer.java

public void replotData() {

    if (modeBox.getSelectedIndex() == MODE_All_FOREARM) {
        CategoryDataset data = null;/* w  w w.jav a  2 s  .  c om*/
        data = getAllForeArmData();
        chartHolder.setChart(ChartFactory.createBarChart("Experiment", "Cat", "Value", data,
                PlotOrientation.VERTICAL, true, false, false));
    } else if (modeBox.getSelectedIndex() == MODE_AVG_FOREARM) {
        CategoryDataset data = null;
        data = getAVGForeArmData();
        chartHolder.setChart(ChartFactory.createBarChart("Experiment", "Cat", "Value", data,
                PlotOrientation.VERTICAL, true, false, false));
    } else if (modeBox.getSelectedIndex() == MODE_All_FINGER) {
        XYSeriesCollection collection = getAllFingerData();
        chartHolder.setChart(ChartFactory.createScatterPlot("Data", "Time (min)", "Dim", collection,
                PlotOrientation.VERTICAL, true, false, false));
    }

}

From source file:dumbara.view.Chart1.java

public static void paymentHistory() {
    DefaultCategoryDataset objDataset = new DefaultCategoryDataset();
    try {// ww w .  j ava  2s.  c o  m
        LoanSettle[] loanSettles = LoanSettleController.viewLoanSettle();
        for (LoanSettle loanSettle : loanSettles) {
            objDataset.setValue(Double.parseDouble(loanSettle.getPayment()), "Loan Payments",
                    loanSettle.getLoanSettleID());
        }
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(Chart1.class.getName()).log(Level.SEVERE, null, ex);
    }
    //
    JFreeChart objChart = ChartFactory.createBarChart("Sales Comparisson", "Sales ID", "Sales Income",
            objDataset, PlotOrientation.VERTICAL, true, true, false);
    ChartFrame frame = new ChartFrame("Data Analysis Wizard - v2.1.4", objChart);
    frame.pack();
    frame.setSize(1000, 600);
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);
}

From source file:org.owasp.jbrofuzz.graph.canvas.JaccardIndexChart.java

public ChartPanel getPlotCanvas() {

    final JFreeChart chart = ChartFactory.createBarChart("JBroFuzz Jaccard Index Bar Chart", // chart title
            "File Name", // domain axis label
            "Jaccard Similarity Coefficient", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            true // URLs?
    );//  w  w  w  .  j  a v  a2 s . c  o  m

    final Plot plot = chart.getPlot();
    plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage());
    plot.setBackgroundImageAlignment(Align.TOP_RIGHT);

    final CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    return new ChartPanel(chart);

}

From source file:org.remus.marketplace.scheduling.GenerateStatisticsJob.java

private void createClickStatistics(Integer id, File folder, Node node, Calendar instance) {
    Map<Date, Integer> map = new HashMap<Date, Integer>();
    for (int i = 0, n = month; i < n; i++) {
        Calendar instance2 = Calendar.getInstance();
        instance2.setTime(new Date());
        instance2.add(Calendar.MONTH, i * -1);
        map.put(instance2.getTime(), 0);
    }/*from   w w w  .j av a 2s.  c o  m*/
    AdvancedCriteria criteria = new AdvancedCriteria()
            .addRestriction(Restrictions.between(Clickthrough.TIME, instance.getTime(), new Date()))
            .addRestriction(Restrictions.eq(Clickthrough.NODE, node));
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.count(Clickthrough.NODE));

    projectionList
            .add(Projections.sqlGroupProjection("month({alias}.time) as month, year({alias}.time) as year",
                    "month({alias}.time), year({alias}.time)", new String[] { "month", "year" },
                    new Type[] { Hibernate.INTEGER, Hibernate.INTEGER }));
    criteria.setProjection(projectionList);

    List<Object> query = clickthroughDao.query(criteria);
    for (Object object : query) {
        Object[] data = (Object[]) object;
        Integer count = (Integer) data[0];
        Integer month = (Integer) data[1];
        Integer year = (Integer) data[2];
        Set<Date> keySet = map.keySet();
        for (Date date : keySet) {
            Calendar instance2 = Calendar.getInstance();
            instance2.setTime(date);
            if (instance2.get(Calendar.YEAR) == year && instance2.get(Calendar.MONTH) == month - 1) {
                map.put(date, count);
            }
        }

    }

    DefaultCategoryDataset data = new DefaultCategoryDataset();
    List<Date> keySet = new ArrayList<Date>(map.keySet());
    Collections.sort(keySet, new Comparator<Date>() {

        @Override
        public int compare(Date o1, Date o2) {
            return o1.compareTo(o2);
        }
    });
    for (Date date : keySet) {
        Integer integer = map.get(date);
        Calendar instance2 = Calendar.getInstance();
        instance2.setTime(date);
        int year = instance2.get(Calendar.YEAR);
        int month = instance2.get(Calendar.MONTH) + 1;
        data.addValue(integer, "Column1", month + "-" + year);
    }

    JFreeChart createBarChart = ChartFactory.createBarChart("Clicks", "Month", "", data,
            PlotOrientation.VERTICAL, false, false, false);

    File file = new File(folder, "clicks_" + id + ".png");
    if (file.exists()) {
        file.delete();
    }
    try {
        ChartUtilities.saveChartAsPNG(file, createBarChart, 500, 300);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.modeln.build.ctrl.charts.CMnPatchCountChart.java

/**
 * Create a chart representing an arbitrary collection of name/value pairs. 
 * The data is passed in as a hashtable where the key is the name and the  
 * value is the number items. /*from w  ww.j av a 2 s  . c om*/
 */
public static final JFreeChart getBarChart(Hashtable<String, Integer> data, String title, String nameLabel,
        String valueLabel) {
    JFreeChart chart = null;

    // Sort the data by name
    Vector<String> names = new Vector<String>();
    Enumeration nameList = data.keys();
    while (nameList.hasMoreElements()) {
        names.add((String) nameList.nextElement());
    }
    Collections.sort(names);

    // Populate the dataset with data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Iterator keyIter = names.iterator();
    while (keyIter.hasNext()) {
        String name = (String) keyIter.next();
        Integer value = data.get(name);
        dataset.addValue(value, valueLabel, name);
    }

    // Create the chart
    chart = ChartFactory.createBarChart(title, /*title*/
            nameLabel, /*categoryAxisLabel*/
            valueLabel, /*valueAxisLabel*/
            dataset, /*dataset*/
            PlotOrientation.VERTICAL, /*orientation*/
            false, /*legend*/
            false, /*tooltips*/
            false /*urls*/
    );

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //chartFormatter.formatMetricChart(plot, "min");

    // Set the chart colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    renderer.setSeriesPaint(0, gp);

    // Set the label orientation
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}

From source file:j2se.jfreechart.barchart.BarChartDemo7.java

/**
 * Creates a sample chart./*from w w  w. j a v  a2s .com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 7", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final IntervalMarker target = new IntervalMarker(4.5, 7.5);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    //      renderer.setLabelGenerator(new BarChartDemo7.LabelGenerator());
    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPosition(p);

    final ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPositionFallback(p2);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:org.owasp.jbrofuzz.graph.canvas.HammingDistanceChart.java

public ChartPanel getPlotCanvas() {

    final JFreeChart chart = ChartFactory.createBarChart("JBroFuzz Hamming Distance Bar Chart", // chart title
            "File Name", // domain axis label
            "Hamming Distance", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            true // URLs?
    );/*from www .  ja  v  a 2 s.  c  o m*/

    final Plot plot = chart.getPlot();
    plot.setBackgroundImage(ImageCreator.IMG_OWASP_MED.getImage());
    plot.setBackgroundImageAlignment(Align.TOP_RIGHT);

    final CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    return new ChartPanel(chart);
}

From source file:UserInterface.CommunityRuralHouseholdWorkArea.ShowChartJPanel.java

private void createChart3() {
    System.out.println("Inside create chart fucntion");
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("  Power Consumption of each Appliance ", // chart title
            "Appliance ", // domain axis label
            "Power Consumption", // range axis label
            createDataset2(), // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   w  w  w  .  ja v  a2  s  .c om*/

    ChartPanel chart3 = new ChartPanel(chart);
    chartPanel3.removeAll();
    chartPanel3.add(chart3, BorderLayout.CENTER);
    chartPanel3.validate();

}

From source file:projekt.CustomRenderer.java

public void raport_lokalny() throws IOException, ClassNotFoundException, SQLException {

    loginController login = new loginController();
    String zapytanie = "select count(*) as Aktualne from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Aktualne' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";
    String zapytanie1 = "select count(*) as FORTEST from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'FORTEST' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";
    String zapytanie2 = "select count(*) as Zakonczone from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Zakonczone' and idUzytkownika = '"
            + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt";

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8",
            "root", "");
    PreparedStatement statment;//from   w  w w.j  av  a2  s  .c o m
    ResultSet result;
    double odp = 0, odp1 = 0, odp2 = 0;
    statment = con.prepareStatement(zapytanie);
    result = statment.executeQuery();
    if (result.next()) {
        odp = result.getDouble("Aktualne");
    }
    statment = con.prepareStatement(zapytanie1);
    result = statment.executeQuery();
    if (result.next()) {
        odp1 = result.getDouble("FORTEST");
    }
    statment = con.prepareStatement(zapytanie2);
    result = statment.executeQuery();
    if (result.next()) {
        odp2 = result.getDouble("Zakonczone");
    }
    //tu tez zmienic na id
    statment = con.prepareStatement(
            "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '"
                    + login.uzytkownikID + "'");
    result = statment.executeQuery();
    String bbc = "";
    if (result.next()) {
        bbc = result.getString(1);
    }

    DefaultCategoryDataset set2 = new DefaultCategoryDataset();
    set2.setValue(odp, "", "Aktualne");
    set2.setValue(odp1, "", "FORTEST");
    set2.setValue(odp2, "", "Zakonczone");
    JFreeChart chart = ChartFactory.createBarChart(
            "Wszystkie zadania z projektow za ktore odpowiada " + result.getString(1), "Zadania", "Ilosc", set2,
            PlotOrientation.VERTICAL, false, true, false);

    final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.blue, Color.pink, Color.cyan,
            Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue });

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");

    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 45.0);
    renderer.setPositiveItemLabelPosition(p);
    plot.setRenderer(renderer);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsJPEG(out, chart, 450, 600);
    DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    Date data = new Date();
    String fileName = "Raport lokalny " + dataformat1.format(data) + ".pdf";
    try {
        PDRectangle PAGE_SIZE = PDRectangle.A4;
        PDDocument doc = new PDDocument();
        PDFont font = PDType0Font.load(doc,
                getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf"));
        PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf"));
        PDPage page = new PDPage(PAGE_SIZE);
        PDPage page1 = new PDPage(PAGE_SIZE);
        doc.addPage(page);
        PDPageContentStream content = new PDPageContentStream(doc, page);
        //naglowek strona 1
        Naglowek1(content, dataformat, data);
        //stopka strona1
        Stopka(content, doc);
        content.beginText();
        content.setFont(font1, 48);
        content.moveTextPositionByAmount(135, 550);
        content.showText("Raport lokalny");
        content.endText();

        content.beginText();
        content.setFont(font, 22);
        content.moveTextPositionByAmount(30, 250);
        content.showText("Wersja systemu : 1.0");
        content.newLine();
        content.moveTextPositionByAmount(0, 35);
        content.showText("Autor raportu : " + result.getString("osoba"));
        content.endText();
        content.close();

        PDPageContentStream content1 = new PDPageContentStream(doc, page1);

        PDPage page2 = new PDPage(PAGE_SIZE);
        doc.addPage(page2);
        PDPageContentStream content2 = new PDPageContentStream(doc, page2);
        Naglowek1(content2, dataformat, data);
        //stopka strona2
        Stopka(content2, doc);
        content2.beginText();
        content2.setFont(font, 14);
        content2.moveTextPositionByAmount(30, 775);
        content2.showText("Wszystkie projekty za ktre odpowiada: " + result.getString(1));
        statment = con.prepareStatement(
                "Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty where idUzytkownika='"
                        + login.uzytkownikID + "'");
        result = statment.executeQuery();
        content2.newLine();
        int liczba = 615;
        content2.moveTextPositionByAmount(0, -15);
        while (result.next()) {
            content2.newLine();
            content2.moveTextPositionByAmount(0, -22);
            liczba += 22;
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));

            content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString(1));
            content2.newLine();
            content2.moveTextPositionByAmount(0, -17);
            liczba += 22;
            content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: "
                    + result.getString("Koniec"));

        }
        content2.endText();
        //          content2.setLineWidth(2);
        //        content2.moveTo(10, liczba + 5);
        //        content2.lineTo(10, liczba +5);
        //        content2.closeAndStroke();
        DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd");
        statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '"
                + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'");
        result = statment.executeQuery();
        int aktualne = 0, zakonczone = 0;
        if (result.next()) {
            aktualne = result.getInt("Aktualne");
        }
        statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '"
                + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'");
        result = statment.executeQuery();
        if (result.next()) {
            zakonczone = result.getInt("Zakonczone");
        }

        DefaultPieDataset pieDataset = new DefaultPieDataset();
        pieDataset.setValue("Aktualne", aktualne);
        pieDataset.setValue("Zakonczone", zakonczone);
        JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projekt za ktore odpowiada" + bbc, // Title
                pieDataset, // Dataset
                true, // Show legend
                true, // Use tooltips
                false // Configure chart to generate URLs?
        );

        PiePlot plot1 = (PiePlot) chart1.getPlot();
        plot1.setSectionPaint("Aktualne", Color.blue);
        plot1.setSectionPaint("Zakonczone", Color.yellow);
        plot1.setExplodePercent("Aktualne", 0.10);
        plot1.setSimpleLabels(true);

        PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
                new DecimalFormat("0"), new DecimalFormat("0%"));
        plot1.setLabelGenerator(gen);

        ByteArrayOutputStream out1 = new ByteArrayOutputStream();
        ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600);
        PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray()));

        content2.close();
        PDPage page3 = new PDPage(PAGE_SIZE);
        doc.addPage(page3);
        PDPageContentStream content3 = new PDPageContentStream(doc, page3);
        Naglowek1(content3, dataformat, data);
        //stopka strona2
        Stopka(content3, doc);
        content3.drawImage(img1, 50, 50);
        content3.close();
        PDPage page4 = new PDPage(PAGE_SIZE);
        doc.addPage(page4);
        PDPageContentStream content4 = new PDPageContentStream(doc, page4);
        Naglowek1(content4, dataformat, data);
        //stopka strona2
        Stopka(content4, doc);
        content4.beginText();
        content4.setFont(font, 14);
        content4.moveTextPositionByAmount(30, 780);
        content4.showText("Wszystkie zadania w projektach za ktore odpowiada:" + bbc);
        statment = con.prepareStatement(
                "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, ' ' , y.nazwisko) as 'UZY' FROM zadania , (select Nazwa from projekty where idUzytkownika = '"
                        + login.uzytkownikID
                        + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '"
                        + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12"); //poprawic
        result = statment.executeQuery();
        content4.newLine();
        int nw = 850;
        content4.moveTextPositionByAmount(0, -15);
        nw -= 15;
        while (result.next()) {
            content4.newLine();
            nw -= 22;
            content4.moveTextPositionByAmount(0, -22);
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));
            content4.showText("Nazwa : " + result.getString("zadania.Nazwa"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: "
                    + result.getString("zadania.Status_zadania"));
            content4.newLine();
            nw -= 17;
            content4.moveTextPositionByAmount(0, -17);
            content4.showText(" Projekt: " + result.getString("zadania.projekt")
                    + " Przydzielona osoba do zadania: " + result.getString("UZY"));

        }

        content4.endText();
        content4.close();
        statment = con.prepareStatement(
                "SELECT count(*) as 'liczba' FROM `zadania` where idUzytkownika='" + login.uzytkownikID + "'"); //poprawic
        result = statment.executeQuery();
        if (result.next()) {
        }
        statment = con.prepareStatement(
                "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, \" \", y.nazwisko) as \"UZY\" FROM zadania , (select Nazwa from projekty where idUzytkownika = '"
                        + login.uzytkownikID
                        + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '"
                        + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12,"
                        + result.getInt(1) + "");
        result = statment.executeQuery();
        PDPage page5 = new PDPage(PAGE_SIZE);
        doc.addPage(page5);
        PDPageContentStream content5 = new PDPageContentStream(doc, page5);
        Naglowek1(content5, dataformat, data);
        //stopka strona2
        Stopka(content5, doc);
        content5.beginText();
        content5.setFont(font, 14);
        content5.moveTextPositionByAmount(30, 700);
        while (result.next()) {
            content5.newLine();
            nw -= 22;
            content5.moveTextPositionByAmount(0, -22);
            //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec"));
            content5.showText("Nazwa : " + result.getString("zadania.Nazwa"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: "
                    + result.getString("zadania.Status_zadania"));
            content5.newLine();
            nw -= 17;
            content5.moveTextPositionByAmount(0, -17);
            content5.showText(" Projekt: " + result.getString("zadania.projekt")
                    + " Przydzielona osoba do zadania: " + result.getString("UZY"));
        }
        content5.endText();
        content5.close();
        doc.addPage(page1);
        //naglowek strona 2
        Naglowek1(content1, dataformat, data);
        //stopka strona2
        Stopka(content1, doc);
        PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray()));
        content1.drawImage(img, 50, 50);
        content1.close();
        doc.save(fileName);
        doc.close();

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

From source file:org.sakaiproject.gradebookng.tool.panels.AssignmentStatisticsPanel.java

@Override
public void onInitialize() {
    super.onInitialize();

    final Long assignmentId = ((Model<Long>) getDefaultModel()).getObject();

    final Assignment assignment = this.businessService.getAssignment(assignmentId.longValue());

    AssignmentStatisticsPanel.this.window.setTitle(
            (new StringResourceModel("label.statistics.title", null, new Object[] { assignment.getName() })
                    .getString()));/*from   w  ww.j  a  v a 2s. com*/

    final List<GbStudentGradeInfo> gradeInfo = this.businessService.buildGradeMatrix(Arrays.asList(assignment));

    final List<Double> allGrades = new ArrayList<>();

    for (int i = 0; i < gradeInfo.size(); i++) {
        final GbStudentGradeInfo studentGradeInfo = gradeInfo.get(i);

        final Map<Long, GbGradeInfo> studentGrades = studentGradeInfo.getGrades();
        final GbGradeInfo grade = studentGrades.get(assignmentId);

        if (grade == null || grade.getGrade() == null) {
            // this is not the grade you are looking for
        } else {
            allGrades.add(Double.valueOf(grade.getGrade()));
        }
    }

    Collections.sort(allGrades);

    final DefaultCategoryDataset data = new DefaultCategoryDataset();

    final Map<String, Integer> counts = new TreeMap<>();
    Integer extraCredits = 0;

    // Start off with a 0-50% range
    counts.put(String.format("%d-%d", 0, 50), 0);

    final int range = 10;
    for (int start = 50; start < 100; start = start + range) {
        final String key = String.format("%d-%d", start, start + range);
        counts.put(key, 0);
    }

    for (final Double grade : allGrades) {
        if (isExtraCredit(grade, assignment)) {
            extraCredits = extraCredits + 1;
            continue;
        }

        final double percentage;
        if (GradingType.PERCENTAGE.equals(this.gradingType)) {
            percentage = grade;
        } else {
            percentage = grade / assignment.getPoints() * 100;
        }

        final int total = Double.valueOf(Math.ceil(percentage) / range).intValue();

        int start = total * range;

        if (start == 100) {
            start = start - range;
        }

        String key = String.format("%d-%d", start, start + range);

        if (start < 50) {
            key = String.format("%d-%d", 0, 50);
        }

        counts.put(key, counts.get(key) + 1);
    }

    for (final String label : counts.keySet()) {
        data.addValue(counts.get(label), "count", label);
    }
    if (extraCredits > 0) {
        data.addValue(extraCredits, "count", getString("label.statistics.chart.extracredit"));
    }

    final JFreeChart chart = ChartFactory.createBarChart(null, // the chart title
            getString("label.statistics.chart.xaxis"), // the label for the category axis
            getString("label.statistics.chart.yaxis"), // the label for the value axis
            data, // the dataset for the chart
            PlotOrientation.VERTICAL, // the plot orientation
            false, // show legend
            true, // show tooltips
            false); // show urls

    chart.setBorderVisible(false);

    chart.setAntiAlias(false);

    final CategoryPlot categoryPlot = chart.getCategoryPlot();
    final BarRenderer br = (BarRenderer) categoryPlot.getRenderer();

    br.setItemMargin(0);
    br.setMinimumBarLength(0.05);
    br.setMaximumBarWidth(0.1);
    br.setSeriesPaint(0, new Color(51, 122, 183));
    br.setBarPainter(new StandardBarPainter());
    br.setShadowPaint(new Color(220, 220, 220));
    BarRenderer.setDefaultShadowsVisible(true);

    br.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(getString("label.statistics.chart.tooltip"),
            NumberFormat.getInstance()));

    categoryPlot.setRenderer(br);

    // show only integers in the count axis
    categoryPlot.getRangeAxis().setStandardTickUnits(new NumberTickUnitSource(true));
    categoryPlot.setBackgroundPaint(Color.white);

    add(new JFreeChartImageWithToolTip("chart", Model.of(chart), "tooltip", 540, 300));

    add(new Label("graded", String.valueOf(allGrades.size())));

    if (allGrades.size() > 0) {
        add(new Label("average", constructAverageLabel(allGrades, assignment)));
        add(new Label("median", constructMedianLabel(allGrades, assignment)));
        add(new Label("lowest", constructLowestLabel(allGrades, assignment)));
        add(new Label("highest", constructHighestLabel(allGrades, assignment)));
        add(new Label("deviation", constructStandardDeviationLabel(allGrades)));
    } else {
        add(new Label("average", "-"));
        add(new Label("median", "-"));
        add(new Label("lowest", "-"));
        add(new Label("highest", "-"));
        add(new Label("deviation", "-"));
    }

    add(new GbAjaxLink("done") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            AssignmentStatisticsPanel.this.window.close(target);
        }
    });
}