Rev 1993 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1993 | Rev 1995 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | import org.jfree.chart.ChartFrame; |
9 | import org.jfree.chart.ChartFrame; |
10 | import org.jfree.chart.JFreeChart; |
10 | import org.jfree.chart.JFreeChart; |
11 | import org.jfree.chart.axis.NumberAxis; |
11 | import org.jfree.chart.axis.NumberAxis; |
12 | import org.jfree.chart.axis.ValueAxis; |
12 | import org.jfree.chart.axis.ValueAxis; |
13 | import org.jfree.chart.plot.CategoryPlot; |
13 | import org.jfree.chart.plot.CategoryPlot; |
- | 14 | import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; |
|
14 | import org.jfree.chart.plot.PiePlot; |
15 | import org.jfree.chart.plot.PiePlot; |
15 | import org.jfree.chart.plot.PlotOrientation; |
16 | import org.jfree.chart.plot.PlotOrientation; |
16 | import org.jfree.chart.plot.RingPlot; |
17 | import org.jfree.chart.plot.RingPlot; |
17 | import org.jfree.data.category.DefaultCategoryDataset; |
18 | import org.jfree.data.category.DefaultCategoryDataset; |
18 | import org.jfree.data.general.DefaultPieDataset; |
19 | import org.jfree.data.general.DefaultPieDataset; |
- | 20 | import org.jfree.ui.RectangleInsets; |
|
19 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
21 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
20 | import pt.estgp.estgweb.utils.Globals; |
22 | import pt.estgp.estgweb.utils.Globals; |
21 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
23 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
22 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
24 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
23 | 25 | ||
24 | import javax.imageio.ImageIO; |
26 | import javax.imageio.ImageIO; |
25 | import java.awt.*; |
27 | import java.awt.*; |
26 | import java.awt.image.BufferedImage; |
28 | import java.awt.image.BufferedImage; |
- | 29 | import java.text.DecimalFormat; |
|
27 | import java.io.FileOutputStream; |
30 | import java.io.FileOutputStream; |
28 | import java.io.IOException; |
31 | import java.io.IOException; |
- | 32 | import java.util.List; |
|
29 | 33 | ||
30 | /** |
34 | /** |
31 | * Created by jorgemachado on 31/10/17. |
35 | * Created by jorgemachado on 31/10/17. |
32 | */ |
36 | */ |
33 | public class LearningResultsChartSem extends ImageComponent |
37 | public class LearningResultsChartSem extends ImageComponent |
Line 50... | Line 54... | ||
50 | this.semesterCode = semesterCode; |
54 | this.semesterCode = semesterCode; |
51 | } |
55 | } |
52 | 56 | ||
53 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results,CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
57 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results,CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
54 | { |
58 | { |
55 | float aprovados1013 = results.getAprovados(); |
- | |
56 | float aprovados1416 = results.getAprovados(); |
- | |
57 | float aprovados1720 = results.getAprovados(); |
- | |
- | 59 | ||
58 | double aprovadosPercent1013 = results.getAprovados(); |
60 | 5+0%2Fdocs%2Fapi+List">List <UnitsLearningResultYear> years = results.getYears(); |
59 | double aprovadosPercent1416 = results.getAprovados(); |
61 | List<UnitsLearningResultSemester> semester = years.get(0).semesters; |
60 | double aprovadosPercent1720 = results.getAprovados(); |
62 | List<UnitsLearningResultUc> uc; |
61 | 63 | ||
62 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
64 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
- | 65 | ||
- | 66 | // Ano que não consta no Plano |
|
- | 67 | uc = semester.get(0).ucs; |
|
63 | for (int i = 0; i < 3; i++) |
68 | for(int k = 0; k < uc.size(); k++) |
- | 69 | { |
|
- | 70 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getAprovadosPercent()), "Aprovados " , uc.get(k).getName()); |
|
- | 71 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getSemElementosPercent()), "SemElementos " , uc.get(k).getName()); |
|
- | 72 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getReprovadosPercent()), "Reprovados " , uc.get(k).getName()); |
|
- | 73 | } |
|
- | 74 | uc = semester.get(1).ucs; |
|
- | 75 | for(int k = 0; k < uc.size(); k++) |
|
64 | { |
76 | { |
65 | UnitsLearningResult ola = results.years.get(i); |
77 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getAprovadosPercent()), "Aprovados " , uc.get(k).getName()); |
- | 78 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getSemElementosPercent()), "SemElementos " , uc.get(k).getName()); |
|
- | 79 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getReprovadosPercent()), "Reprovados " , uc.get(k).getName()); |
|
- | 80 | } |
|
- | 81 | ||
66 | 82 | ||
67 | aprovados1013 = ola.getAprovados1013(); |
83 | for(int i = 1; i < 6; i++) //Years(between 1 and 5) |
- | 84 | { |
|
68 | aprovados1416 = ola.getAprovados1416(); |
85 | for(int j = 0; j < years.size(); j++) //Years existent on array (between 0 and X) |
- | 86 | { |
|
69 | aprovados1720 = ola.getAprovados1720(); |
87 | if(results.years.get(j).getAno() == i) |
- | 88 | { |
|
70 | aprovadosPercent1013 = ((int)(ola.getAprovados1013Percent()*100.0))/100.0; |
89 | semester = years.get(j).semesters; |
- | 90 | ||
71 | aprovadosPercent1416 = ((int)(ola.getAprovados1416Percent()*100.0))/100.0; |
91 | for(int h = 0; h < semester.size(); h++) //Semesters (between 1 and 2) |
- | 92 | { |
|
72 | aprovadosPercent1720 = ((int)(ola.getAprovados1720Percent()*100.0))/100.0; |
93 | uc = semester.get(h).ucs; |
73 | 94 | ||
- | 95 | for(int k = 0; k < uc.size(); k++) |
|
74 | //if (aprovados1013> 0) |
96 | { |
75 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(aprovadosPercent1013), "Aprovados1013 " ,(i + 1) + "º Ano " ); |
97 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getAprovadosPercent()), "Aprovados " , uc.get(k).getName()); |
76 | //if (aprovados1416> 0) |
98 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getSemElementosPercent()), "SemElementos " , uc.get(k).getName()); |
77 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(aprovadosPercent1416), "Aprovados1416 " ,(i + 1) + "º Ano " ); |
99 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.get(k).getReprovadosPercent()), "Reprovados " , uc.get(k).getName()); |
78 | //if (aprovados1720> 0) |
100 | } |
79 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(aprovadosPercent1720), "Aprovados1720 " ,(i + 1) + "º Ano " ); |
101 | } |
- | 102 | } |
|
- | 103 | } |
|
80 | } |
104 | } |
- | 105 | ||
81 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
106 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
82 | 107 | ||
83 | //Grafico Barras |
- | |
84 | JFreeChart chart = ChartFactory.createStackedBarChart(null, null,null,data, PlotOrientation.VERTICAL, true,true,false); |
108 | JFreeChart chart = ChartFactory.createStackedBarChart(null, null,null,data, PlotOrientation.HORIZONTAL, true,true,false); |
- | 109 | ||
- | 110 | RectangleInsets rectangleInsets = new RectangleInsets(0,0,30F,0); |
|
- | 111 | chart.setPadding(rectangleInsets); |
|
85 | 112 | ||
86 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 231, 242)); |
113 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 231, 242)); |
87 | 114 | ||
88 | CategoryPlot plot = chart.getCategoryPlot(); |
115 | CategoryPlot plot = chart.getCategoryPlot(); |
89 | 116 | ||
90 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.black); |
117 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.black); |
91 | 118 | ||
92 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
- | |
93 | /* |
- | |
94 | plot.setSectionPaint(0, new Color(255, 0, 0)); |
- | |
95 | plot.setSectionPaint(1, new Color(15, 218, 10)); |
- | |
96 | plot.setSectionPaint(2, new Color(200, 200, 200)); |
- | |
97 | plot.setBackgroundPaint(new Color(255, 255, 255)); |
- | |
98 | plot.setOutlineVisible(false); |
- | |
99 | - | ||
100 | plot.setLabelFont(new Font( |
- | |
101 | "Helvetica", Font.PLAIN, 30)); |
- | |
102 | */ |
- | |
103 | 119 | ||
104 | 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, 25)); |
120 | 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, 25)); |
105 | 121 | ||
- | 122 | ||
106 | plot.getRenderer().setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 171, 28)); |
123 | plot.getRenderer().setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(0, 255, 0)); |
107 | plot.getRenderer().setSeriesPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 253, 44)); |
124 | plot.getRenderer().setSeriesPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
108 | plot.getRenderer().setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(0, 255, 0)); |
125 | plot.getRenderer().setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 0, 0)); |
109 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(249, 231, 236)); |
126 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(249, 231, 236)); |
110 | 127 | ||
- | 128 | plot.getRenderer().setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.#'%'"))); |
|
- | 129 | plot.getRenderer().setBaseItemLabelsVisible(true); |
|
- | 130 | plot.getRenderer().setBaseItemLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font("Helvetica",1.5.0/docs/api/java/awt/Font.html">Font.PLAIN,35)); |
|
- | 131 | 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,25)); //Letra Legenda |
|
- | 132 | ||
111 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*3, 200*3); |
133 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
112 | 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; |
134 | 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; |
113 | 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); |
135 | 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); |
114 | 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)); |
136 | 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)); |
115 | 137 | ||
116 | FileUploaded fileUploaded = new FileUploaded(); |
138 | FileUploaded fileUploaded = new FileUploaded(); |
Line 120... | Line 142... | ||
120 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
142 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
121 | fileUploaded.setFileSize(output.length()); |
143 | fileUploaded.setFileSize(output.length()); |
122 | fileUploaded.setExtension("png"); |
144 | fileUploaded.setExtension("png"); |
123 | return fileUploaded; |
145 | return fileUploaded; |
124 | } |
146 | } |
125 | - | ||
126 | - | ||
127 | } |
147 | } |