Rev 1990 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1990 | Rev 1994 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components; |
1 | package pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components; |
2 | 2 | ||
- | 3 | ||
3 | import jomm.utils.BytesUtils; |
4 | import jomm.utils.BytesUtils; |
4 | import jomm.utils.MimeTypeGuesser; |
5 | import jomm.utils.MimeTypeGuesser; |
5 | import org.jfree.chart.ChartFactory; |
6 | import org.jfree.chart.ChartFactory; |
6 | import org.jfree.chart.JFreeChart; |
7 | import org.jfree.chart.JFreeChart; |
- | 8 | import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; |
|
7 | import org.jfree.chart.plot.PiePlot; |
9 | import org.jfree.chart.plot.CategoryPlot; |
8 | import org.jfree.chart.plot.RingPlot; |
10 | import org.jfree.chart.plot.PlotOrientation; |
- | 11 | import org.jfree.chart.renderer.category.StackedBarRenderer; |
|
9 | import org.jfree.data.general.DefaultPieDataset; |
12 | import org.jfree.data.category.DefaultCategoryDataset; |
- | 13 | ||
10 | import org.jfree.data.xy.XYDataset; |
14 | import org.jfree.ui.RectangleInsets; |
11 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
15 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
12 | import pt.estgp.estgweb.utils.Globals; |
16 | import pt.estgp.estgweb.utils.Globals; |
13 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
17 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
14 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
18 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
15 | 19 | ||
16 | import javax.imageio.ImageIO; |
20 | import javax.imageio.ImageIO; |
17 | import java.awt.*; |
21 | import java.awt.*; |
18 | import java.awt.image.BufferedImage; |
22 | import java.awt.image.BufferedImage; |
19 | import java.io.FileOutputStream; |
23 | import java.io.FileOutputStream; |
20 | import java.io.IOException; |
24 | import java.io.IOException; |
- | 25 | import java.text.DecimalFormat; |
|
- | 26 | import java.util.List; |
|
21 | 27 | ||
22 | /** |
28 | /** |
23 | * Created by jorgemachado on 31/10/17. |
29 | * Created by jorgemachado on 31/10/17. |
24 | */ |
30 | */ |
25 | public class GlobalLearningResultsChartYearImg extends ImageComponent |
31 | public class GlobalLearningResultsChartYearImg extends ImageComponent |
26 | { |
32 | { |
27 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results,CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
33 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results, CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
28 | { |
- | |
29 | float aprovados = results.getAprovados(); |
- | |
30 | float reprovados = results.getReprovados(); |
34 | List<UnitsLearningResultYear> years = results.getYears(); |
31 | float semElementos = results.getSemElementos(); |
- | |
32 | double aprovadosPercent = ((int)(results.getAprovadosPercent()*100.0))/100.0; |
- | |
33 | double reprovadosPercent = ((int)(results.getReprovadosPercent()*100.0))/100.0; |
- | |
34 | double semElementosPercent = ((int)(results.getSemElementosPercent()*100.0))/100.0; |
- | |
35 | 35 | ||
36 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
36 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
37 | 37 | ||
38 | DefaultPieDataset data = new DefaultPieDataset(); |
38 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
39 | if(reprovados > 0) |
- | |
40 | data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados)); |
- | |
41 | if(aprovados > 0) |
- | |
42 | data.setValue("Aprovados " + aprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados)); |
- | |
43 | if(semElementos > 0) |
- | |
44 | data.setValue("Sem Elementos " + semElementosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos)); |
- | |
45 | - | ||
46 | - | ||
47 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
- | |
48 | - | ||
49 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
- | |
50 | PiePlot plot = (RingPlot) chart.getPlot(); |
- | |
51 | plot.setLabelBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 249, 235)); |
- | |
52 | plot.setLabelPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(88, 88, 90)); |
- | |
53 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
- | |
54 | 39 | ||
- | 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 | } |
|
- | 45 | ||
- | 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"); |
|
- | 50 | ||
- | 51 | JFreeChart chart = ChartFactory.createStackedBarChart(null,null,null, data, PlotOrientation.VERTICAL,true, false, false); |
|
- | 52 | ||
55 | plot.setSectionPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 0, 0)); |
53 | chart.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
- | 54 | // Legenda |
|
56 | plot.setSectionPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(15, 218, 10)); |
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)); |
- | 56 | ||
- | 57 | CategoryPlot plot = (CategoryPlot) chart.getPlot(); |
|
57 | plot.setSectionPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
58 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
58 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 255, 255)); |
59 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.GRAY); |
59 | plot.setOutlineVisible(false); |
60 | plot.setRangeGridlinesVisible(true); |
- | 61 | plot.setRangeGridlineStroke(new 1.5.0/docs/api/java/awt/BasicStroke.html">BasicStroke(1.0f)); |
|
- | 62 | 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)); |
|
- | 63 | 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)); |
|
- | 64 | ||
60 | 65 | ||
- | 66 | RectangleInsets chartRectangle = new RectangleInsets(0,0,30F,0); |
|
- | 67 | chart.setPadding(chartRectangle); |
|
61 | 68 | ||
- | 69 | StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); |
|
- | 70 | renderer.setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(237, 132, 0)); |
|
- | 71 | renderer.setSeriesPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 250, 29)); |
|
- | 72 | renderer.setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(93,173, 21)); |
|
- | 73 | renderer.setMaximumBarWidth(.2); |
|
62 | 74 | ||
63 | plot.setLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font( |
75 | //Percentagem dentro das barras |
- | 76 | renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.#'%'"))); |
|
- | 77 | renderer.setBaseItemLabelsVisible(true); |
|
64 | "Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
78 | 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)); |
65 | 79 | ||
66 | 80 | ||
67 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
81 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
68 | 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; |
82 | 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; |
69 | 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); |
83 | 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); |
Line 76... | Line 90... | ||
76 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
90 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
77 | fileUploaded.setFileSize(output.length()); |
91 | fileUploaded.setFileSize(output.length()); |
78 | fileUploaded.setExtension("png"); |
92 | fileUploaded.setExtension("png"); |
79 | return fileUploaded; |
93 | return fileUploaded; |
80 | } |
94 | } |
81 | - | ||
82 | } |
95 | } |
83 | 96 |