Rev 1929 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1929 | Rev 1930 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | import org.jfree.data.category.DefaultCategoryDataset; |
14 | import org.jfree.data.category.DefaultCategoryDataset; |
15 | import org.jfree.ui.RectangleInsets; |
15 | import org.jfree.ui.RectangleInsets; |
16 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
16 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
17 | import pt.estgp.estgweb.utils.Globals; |
17 | import pt.estgp.estgweb.utils.Globals; |
18 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
18 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
19 | import pt.estgp.estgweb.utils.documentBuilder.AutoImageWraperComponent; |
- | |
20 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
19 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
21 | 20 | ||
22 | import javax.imageio.ImageIO; |
21 | import javax.imageio.ImageIO; |
23 | import java.awt.*; |
22 | import java.awt.*; |
24 | import java.awt.image.BufferedImage; |
23 | import java.awt.image.BufferedImage; |
25 | import java.io.File; |
- | |
26 | import java.io.FileNotFoundException; |
24 | import java.io.FileNotFoundException; |
27 | import java.io.FileOutputStream; |
25 | import java.io.FileOutputStream; |
28 | import java.io.IOException; |
26 | import java.io.IOException; |
29 | import java.text.DecimalFormat; |
27 | import java.text.DecimalFormat; |
30 | import java.util.List; |
28 | import java.util.List; |
31 | import java.util.Map; |
29 | import java.util.Map; |
32 | import java.util.Random; |
30 | import java.util.Random; |
33 | 31 | ||
34 | - | ||
35 | - | ||
36 | /** |
32 | /** |
37 | * Created by ASUS on 14/01/18. |
33 | * Created by ASUS on 13/01/18. |
38 | */ |
34 | */ |
39 | public class LearningResultsChartSem extends AutoImageWraperComponent |
35 | public class LearningResultsChartSem extends ImageComponent |
40 | { |
36 | { |
41 | 1.5.0/docs/api/java/lang/String.html">String semesterCode; |
37 | 1.5.0/docs/api/java/lang/String.html">String semesterCode; |
42 | 38 | ||
- | 39 | ||
43 | public LearningResultsChartSem() { |
40 | public LearningResultsChartSem() { |
44 | } |
41 | } |
45 | 42 | ||
46 | public LearningResultsChartSem(1.5.0/docs/api/java/lang/String.html">String semesterCode) { |
43 | public LearningResultsChartSem(1.5.0/docs/api/java/lang/String.html">String semesterCode) { |
47 | this.semesterCode = semesterCode; |
44 | this.semesterCode = semesterCode; |
Line 56... | Line 53... | ||
56 | this.semesterCode = semesterCode; |
53 | this.semesterCode = semesterCode; |
57 | } |
54 | } |
58 | 55 | ||
59 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results, CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
56 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results, CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
60 | List<UnitsLearningResultYear> years = results.getYears(); |
57 | List<UnitsLearningResultYear> years = results.getYears(); |
- | 58 | ||
61 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
59 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
62 | 60 | ||
63 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
61 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
64 | for(UnitsLearningResultYear year : years){ |
62 | for (UnitsLearningResultYear year : years) { |
65 | for(UnitsLearningResultSemester semester : year.getSemesters()){ |
63 | for (UnitsLearningResultSemester semester : year.getSemesters()) { |
66 | if(semester.getSemestre().equals(getSemesterCode())){ |
64 | if (semester.getSemestre().equals(getSemesterCode())) { |
67 | for(UnitsLearningResultUc uc : semester.getUcs()){ |
65 | for (UnitsLearningResultUc uc : semester.getUcs()) { |
68 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getSemElementosPercent()), "Sem elementos", uc.getName()); |
66 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getSemElementosPercent()), "Sem elementos", uc.getName()); |
69 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getReprovadosPercent()), "Reprovados", uc.getName()); |
67 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getReprovadosPercent()), "Reprovados", uc.getName()); |
70 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getAprovadosPercent()), "Aprovados", uc.getName()); |
68 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(uc.getAprovadosPercent()), "Aprovados", uc.getName()); |
71 | } |
69 | } |
72 | break; |
70 | break; |
73 | } |
71 | } |
74 | } |
72 | } |
75 | } |
73 | } |
76 | 74 | ||
- | 75 | ||
77 | JFreeChart chart = ChartFactory.createStackedBarChart(null,null,null,data,PlotOrientation.HORIZONTAL,true,false,false); |
76 | JFreeChart chart = ChartFactory.createStackedBarChart( |
- | 77 | null, |
|
- | 78 | null, |
|
- | 79 | null, |
|
- | 80 | data, |
|
- | 81 | PlotOrientation.HORIZONTAL, |
|
- | 82 | true, |
|
- | 83 | false, |
|
- | 84 | false); |
|
- | 85 | ||
78 | chart.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
86 | chart.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
79 | CategoryPlot plot = (CategoryPlot) chart.getPlot(); |
87 | CategoryPlot plot = (CategoryPlot) chart.getPlot(); |
80 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
88 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
81 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.GRAY); |
89 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.GRAY); |
82 | plot.setRangeGridlinesVisible(true); |
90 | plot.setRangeGridlinesVisible(true); |
83 | //plot.setRangeGridlineStroke(new BasicStroke(1.0f)); |
91 | //plot.setRangeGridlineStroke(new BasicStroke(1.0f)); |
84 | 92 | ||
85 | RectangleInsets chartRectangle = new RectangleInsets(0,0,30F,0); |
93 | RectangleInsets chartRectangle = new RectangleInsets(0,0,30F,0); |
86 | chart.setPadding(chartRectangle); |
94 | chart.setPadding(chartRectangle); |
87 | 95 | ||
88 | 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)); |
96 | 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)); |
89 | 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,25)); |
97 | 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, 25)); |
90 | 98 | ||
91 | StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); |
99 | StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); |
92 | // Remover gradiente das barras |
100 | // Remover gradiente das barras |
93 | renderer.setBarPainter(new StandardBarPainter()); |
101 | renderer.setBarPainter(new StandardBarPainter()); |
94 | renderer.setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(237,127,32)); |
102 | renderer.setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(237,127,32)); |
95 | renderer.setSeriesPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(255,198,0)); |
103 | renderer.setSeriesPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(255,198,0)); |
96 | renderer.setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(122,173,38)); |
104 | renderer.setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(122,173,38)); |
97 | renderer.setMaximumBarWidth(0.2); |
105 | renderer.setMaximumBarWidth(0.1); |
98 | 106 | ||
99 | renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.##'%'"))); |
107 | renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.##'%'"))); |
100 | renderer.setBaseItemLabelsVisible(true); |
108 | renderer.setBaseItemLabelsVisible(true); |
101 | 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)); |
109 | 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)); |
102 | 110 | ||
103 | LegendTitle legend = chart.getLegend(); |
111 | LegendTitle legend = chart.getLegend(); |
104 | legend.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)); |
112 | legend.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)); |
105 | legend.setFrame(BlockBorder.NONE); |
113 | legend.setFrame(BlockBorder.NONE); |
106 | 114 | ||
- | 115 | ||
107 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage(300*4, 200*4); |
116 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 400*4); |
108 | 1.5.0/docs/api/java/lang/String.html">String pathGraficoTiposAlunos = Globals.TMP_DIR + 1.5.0/docs/api/java/io/File.html">File.separator + tempName; |
117 | 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; |
109 | 1.5.0/docs/api/java/io/File.html">File output = new 1.5.0/docs/api/java/io/File.html">File(pathGraficoTiposAlunos); |
118 | 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); |
110 | 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)); |
119 | 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)); |
111 | 120 | ||
112 | FileUploaded fileUploaded = new FileUploaded(); |
121 | FileUploaded fileUploaded = new FileUploaded(); |
113 | fileUploaded.setTmpName(tempName); |
122 | fileUploaded.setTmpName(tempName); |
114 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
123 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
115 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
124 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
Line 118... | Line 127... | ||
118 | fileUploaded.setExtension("png"); |
127 | fileUploaded.setExtension("png"); |
119 | 128 | ||
120 | return fileUploaded; |
129 | return fileUploaded; |
121 | } |
130 | } |
122 | 131 | ||
123 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException{ |
132 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException { |
124 | 1.5.0/docs/api/java/lang/String.html">String tempName = "test.png"; |
133 | 1.5.0/docs/api/java/lang/String.html">String tempName = "test.png"; |
125 | 134 | ||
126 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
135 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
127 | 136 | ||
128 | for (int i=0; i<16; i++){ |
137 | for (int i = 0; i < 16; i++) { |
129 | int s = new 1.5.0/docs/api/java/util/Random.html">Random().nextInt(75); |
138 | int s = new 1.5.0/docs/api/java/util/Random.html">Random().nextInt(75); |
130 | int r = new 1.5.0/docs/api/java/util/Random.html">Random().nextInt((101 - s)); |
139 | int r = new 1.5.0/docs/api/java/util/Random.html">Random().nextInt((101 - s)); |
131 | int a = (100 - s - r); |
140 | int a = (100 - s - r); |
132 | - | ||
133 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(s), "Sem elementos", "Engenharia de Software " + i); |
141 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(s), "Sem elementos", "Engenharia de Software " + i); |
134 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(r), "Reprovados", "Engenharia de Software " + i); |
142 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(r), "Reprovados", "Engenharia de Software " + i); |
135 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(a), "Aprovados", "Engenharia de Software " + i); |
143 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double(a), "Aprovados", "Engenharia de Software " + i); |
136 | } |
144 | } |
137 | 145 | ||
- | 146 | ||
138 | JFreeChart chart = ChartFactory.createStackedBarChart(null,null,null,data,PlotOrientation.HORIZONTAL, true, false, false); |
147 | JFreeChart chart = ChartFactory.createStackedBarChart( |
- | 148 | null, |
|
- | 149 | null, |
|
- | 150 | null, |
|
- | 151 | data, |
|
- | 152 | PlotOrientation.HORIZONTAL, |
|
- | 153 | true, |
|
- | 154 | false, |
|
- | 155 | false); |
|
- | 156 | ||
139 | chart.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
157 | chart.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
140 | CategoryPlot plot = (CategoryPlot) chart.getPlot(); |
158 | CategoryPlot plot = (CategoryPlot) chart.getPlot(); |
141 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
159 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
142 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.GRAY); |
160 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.GRAY); |
143 | plot.setRangeGridlinesVisible(true); |
161 | plot.setRangeGridlinesVisible(true); |
144 | //plot.setRangeGridlineStroke(new BasicStroke(1.0f)); |
162 | //plot.setRangeGridlineStroke(new BasicStroke(1.0f)); |
145 | 163 | ||
146 | RectangleInsets chartRectangle = new RectangleInsets(0,0,30F,0); |
164 | RectangleInsets chartRectangle = new RectangleInsets(0,0,30F,0); |
147 | chart.setPadding(chartRectangle); |
165 | chart.setPadding(chartRectangle); |
148 | 166 | ||
149 | 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)); |
167 | 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)); |
150 | 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,25)); |
168 | 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, 25)); |
151 | 169 | ||
152 | StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); |
170 | StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); |
153 | // Remover gradiente das barras |
171 | // Remover gradiente das barras |
154 | renderer.setBarPainter(new StandardBarPainter()); |
172 | renderer.setBarPainter(new StandardBarPainter()); |
155 | renderer.setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(237,127,32)); |
173 | renderer.setSeriesPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(237,127,32)); |
Line 157... | Line 175... | ||
157 | renderer.setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(122,173,38)); |
175 | renderer.setSeriesPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(122,173,38)); |
158 | renderer.setMaximumBarWidth(0.1); |
176 | renderer.setMaximumBarWidth(0.1); |
159 | 177 | ||
160 | renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.##'%'"))); |
178 | renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", new 1.5.0/docs/api/java/text/DecimalFormat.html">DecimalFormat("#.##'%'"))); |
161 | renderer.setBaseItemLabelsVisible(true); |
179 | renderer.setBaseItemLabelsVisible(true); |
162 | 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)); |
180 | 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)); |
163 | 181 | ||
164 | LegendTitle legend = chart.getLegend(); |
182 | LegendTitle legend = chart.getLegend(); |
165 | legend.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)); |
183 | legend.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)); |
166 | legend.setFrame(BlockBorder.NONE); |
184 | legend.setFrame(BlockBorder.NONE); |
167 | 185 | ||
- | 186 | ||
- | 187 | ||
168 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 400*4); |
188 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 400*4); |
169 | 1.5.0/docs/api/java/lang/String.html">String pathGraficoTiposAlunos = Globals.TMP_DIR + 1.5.0/docs/api/java/io/File.html">File.separator + tempName; |
189 | 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; |
170 | 1.5.0/docs/api/java/io/File.html">File output = new 1.5.0/docs/api/java/io/File.html">File(pathGraficoTiposAlunos); |
190 | 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); |
171 | 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)); |
191 | 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)); |
172 | - | ||
173 | } |
192 | } |
174 | - | ||
175 | } |
193 | } |
176 | 194 |