Rev 1994 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1830 | jmachado | 1 | package pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components; |
2 | |||
1994 | grupo3 | 3 | |
1917 | grupo3 | 4 | import jomm.utils.BytesUtils; |
5 | import jomm.utils.MimeTypeGuesser; |
||
6 | import org.jfree.chart.ChartFactory; |
||
7 | import org.jfree.chart.JFreeChart; |
||
1994 | grupo3 | 8 | import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; |
9 | import org.jfree.chart.plot.CategoryPlot; |
||
10 | import org.jfree.chart.plot.PlotOrientation; |
||
11 | import org.jfree.chart.renderer.category.StackedBarRenderer; |
||
12 | import org.jfree.data.category.DefaultCategoryDataset; |
||
13 | |||
14 | import org.jfree.ui.RectangleInsets; |
||
1917 | grupo3 | 15 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
16 | import pt.estgp.estgweb.utils.Globals; |
||
17 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
||
18 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
||
1830 | jmachado | 19 | |
1917 | grupo3 | 20 | import javax.imageio.ImageIO; |
21 | import java.awt.*; |
||
22 | import java.awt.image.BufferedImage; |
||
23 | import java.io.FileOutputStream; |
||
24 | import java.io.IOException; |
||
1994 | grupo3 | 25 | import java.text.DecimalFormat; |
26 | import java.util.List; |
||
1917 | grupo3 | 27 | |
1830 | jmachado | 28 | /** |
29 | * Created by jorgemachado on 31/10/17. |
||
30 | */ |
||
1917 | grupo3 | 31 | public class GlobalLearningResultsChartYearImg extends ImageComponent |
1830 | jmachado | 32 | { |
1994 | grupo3 | 33 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results, CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
34 | List<UnitsLearningResultYear> years = results.getYears(); |
||
1917 | grupo3 | 35 | |
36 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
||
37 | |||
1994 | grupo3 | 38 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
1990 | grupo3 | 39 | |
1994 | grupo3 | 40 | for (int i =0; i<years.size(); i++){ |
41 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(years.get(i).getAprovados1013Percent()), "Aprovados 10-13", years.get(i).getAno() + "º ano"); |
||
42 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(years.get(i).getAprovados1416Percent()), "Aprovados 14-16", years.get(i).getAno() + "º ano"); |
||
43 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(years.get(i).getAprovados1720Percent()), "Aprovados 17-20", years.get(i).getAno() + "º ano"); |
||
44 | } |
||
1990 | grupo3 | 45 | |
1994 | grupo3 | 46 | // Total |
47 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(results.getAprovados1013Percent()), "Aprovados 10-13", "Total"); |
||
48 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(results.getAprovados1416Percent()), "Aprovados 14-16", "Total"); |
||
49 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(results.getAprovados1720Percent()), "Aprovados 17-20", "Total"); |
||
1990 | grupo3 | 50 | |
1994 | grupo3 | 51 | JFreeChart chart = ChartFactory.createStackedBarChart(null,null,null, data, PlotOrientation.VERTICAL,true, false, false); |
1917 | grupo3 | 52 | |
1994 | grupo3 | 53 | chart.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
54 | // Legenda |
||
55 | chart.getLegend().setItemFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN,30)); |
||
1996 | grupo3 | 56 | chart.setPadding(new RectangleInsets(0,10F,30F,20F)); |
1917 | grupo3 | 57 | |
1994 | grupo3 | 58 | CategoryPlot plot = (CategoryPlot) chart.getPlot(); |
59 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
||
60 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.GRAY); |
||
61 | plot.setRangeGridlinesVisible(true); |
||
62 | plot.setRangeGridlineStroke(new 1.5.0/docs/api/java/awt/BasicStroke.html">BasicStroke(1.0f)); |
||
63 | plot.getDomainAxis().setTickLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
||
64 | plot.getRangeAxis().setTickLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
||
1917 | grupo3 | 65 | |
1994 | grupo3 | 66 | StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); |
67 | renderer.setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(237, 132, 0)); |
||
68 | renderer.setSeriesPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 250, 29)); |
||
69 | renderer.setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(93,173, 21)); |
||
70 | renderer.setMaximumBarWidth(.2); |
||
1917 | grupo3 | 71 | |
1994 | grupo3 | 72 | //Percentagem dentro das barras |
73 | renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.#'%'"))); |
||
74 | renderer.setBaseItemLabelsVisible(true); |
||
75 | renderer.setBaseItemLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica",1.5.0/docs/api/java/awt/Font.html">Font.PLAIN,25)); |
||
76 | |||
77 | |||
1917 | grupo3 | 78 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
79 | 1.5.0/docs/api/java/lang/String.html">String pathGraficoTiposAlunos = Globals.TMP_DIR + java.io.1.5.0/docs/api/java/io/File.html">File.separator + tempName; |
||
80 | java.io.1.5.0/docs/api/java/io/File.html">File output = new java.io.1.5.0/docs/api/java/io/File.html">File(pathGraficoTiposAlunos); |
||
81 | 1.5.0/docs/api/javax/imageio/ImageIO.html">ImageIO.write(image, "png", new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(output)); |
||
82 | |||
83 | FileUploaded fileUploaded = new FileUploaded(); |
||
84 | fileUploaded.setTmpName(tempName); |
||
85 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
||
86 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
||
87 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
||
88 | fileUploaded.setFileSize(output.length()); |
||
89 | fileUploaded.setExtension("png"); |
||
90 | return fileUploaded; |
||
91 | } |
||
1994 | grupo3 | 92 | } |