Rev 1927 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1927 | Rev 1974 | ||
---|---|---|---|
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 | import jomm.utils.BytesUtils; |
3 | import jomm.utils.BytesUtils; |
4 | import jomm.utils.MimeTypeGuesser; |
4 | import jomm.utils.MimeTypeGuesser; |
5 | import org.apache.log4j.Category; |
- | |
6 | import org.jfree.chart.ChartFactory; |
5 | import org.jfree.chart.ChartFactory; |
7 | import org.jfree.chart.ChartFrame; |
- | |
8 | import org.jfree.chart.JFreeChart; |
6 | import org.jfree.chart.JFreeChart; |
9 | import org.jfree.chart.axis.ValueAxis; |
- | |
10 | import org.jfree.chart.plot.CategoryPlot; |
- | |
11 | import org.jfree.chart.plot.PiePlot; |
7 | import org.jfree.chart.plot.PiePlot; |
12 | import org.jfree.chart.plot.PlotOrientation; |
8 | import org.jfree.chart.plot.PlotOrientation; |
13 | import org.jfree.chart.plot.RingPlot; |
9 | import org.jfree.chart.plot.RingPlot; |
14 | import org.jfree.data.category.DefaultCategoryDataset; |
- | |
15 | import org.jfree.data.general.DefaultPieDataset; |
10 | import org.jfree.data.general.DefaultPieDataset; |
16 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
11 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
17 | import pt.estgp.estgweb.utils.Globals; |
12 | import pt.estgp.estgweb.utils.Globals; |
18 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
13 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
19 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
14 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
Line 22... | Line 17... | ||
22 | import java.awt.*; |
17 | import java.awt.*; |
23 | import java.awt.image.BufferedImage; |
18 | import java.awt.image.BufferedImage; |
24 | import java.io.FileOutputStream; |
19 | import java.io.FileOutputStream; |
25 | import java.io.IOException; |
20 | import java.io.IOException; |
26 | 21 | ||
27 | - | ||
28 | /** |
22 | /** |
29 | * Created by jorgemachado on 31/10/17. |
23 | * Created by jorgemachado on 31/10/17. |
30 | */ |
24 | */ |
31 | public class GlobalLearningResultsChartImg extends ImageComponent |
25 | public class GlobalLearningResultsChartImg extends ImageComponent |
32 | { |
26 | { |
Line 45... | Line 39... | ||
45 | double reprovadosPercent = ((int)(results.getReprovadosPercent()*100.0))/100.0; |
39 | double reprovadosPercent = ((int)(results.getReprovadosPercent()*100.0))/100.0; |
46 | double semElementosPercent = ((int)(results.getSemElementosPercent()*100.0))/100.0; |
40 | double semElementosPercent = ((int)(results.getSemElementosPercent()*100.0))/100.0; |
47 | 41 | ||
48 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
42 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
49 | 43 | ||
50 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
44 | DefaultPieDataset data = new DefaultPieDataset(); |
51 | if(reprovados > 0) |
45 | if(reprovados > 0) |
52 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados), "Reprovados " + reprovadosPercent + "%","Reprovados " + reprovadosPercent + "%" ); |
46 | data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados)); |
53 | if(aprovados > 0) |
47 | if(aprovados > 0) |
54 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados),"Aprovados " + aprovadosPercent + "%","Aprovados " + aprovadosPercent + "%"); |
48 | data.setValue("Aprovados " + aprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados)); |
55 | if(semElementos > 0) |
49 | if(semElementos > 0) |
56 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos),"Sem Elementos " + semElementosPercent + "%", "Sem Elementos " + semElementosPercent + "%"); |
50 | data.setValue("Sem Elementos " + semElementosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos)); |
57 | - | ||
58 | //Grafico Barras |
- | |
59 | JFreeChart chart = ChartFactory.createBarChart(null, null,null,data, PlotOrientation.VERTICAL, true,true,false); |
- | |
60 | 51 | ||
- | 52 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
|
61 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
53 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
62 | - | ||
63 | CategoryPlot plot = chart.getCategoryPlot(); |
54 | PiePlot plot = (RingPlot) chart.getPlot(); |
64 | - | ||
- | 55 | plot.setLabelBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 249, 235)); |
|
65 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.black); |
56 | plot.setLabelPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(88, 88, 90)); |
66 | - | ||
67 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
57 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
68 | /* |
58 | |
69 | plot.setSectionPaint(0, new Color(255, 0, 0)); |
59 | plot.setSectionPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 0, 0)); |
70 | plot.setSectionPaint(1, new Color(15, 218, 10)); |
60 | plot.setSectionPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(15, 218, 10)); |
71 | plot.setSectionPaint(2, new Color(200, 200, 200)); |
61 | plot.setSectionPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
72 | plot.setBackgroundPaint(new Color(255, 255, 255)); |
62 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(240, 240, 240)); |
73 | plot.setOutlineVisible(false); |
63 | plot.setOutlineVisible(true); |
- | 64 | ||
- | 65 | ||
74 | 66 | ||
75 | plot.setLabelFont(new Font( |
67 | plot.setLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font( |
76 | "Helvetica", Font.PLAIN, 30)); |
68 | "Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
77 | */ |
- | |
78 | 69 | ||
79 | 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)); |
- | |
80 | 70 | ||
81 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
71 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
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; |
72 | 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; |
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); |
73 | 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); |
84 | 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)); |
74 | 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)); |
Line 92... | Line 82... | ||
92 | fileUploaded.setExtension("png"); |
82 | fileUploaded.setExtension("png"); |
93 | return fileUploaded; |
83 | return fileUploaded; |
94 | } |
84 | } |
95 | 85 | ||
96 | 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 { |
86 | 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 { |
- | 87 | ||
97 | float aprovados = 10; |
88 | /*float aprovados = 10; |
98 | float reprovados = 2; |
89 | float reprovados = 2; |
99 | float semElementos = 4; |
90 | float semElementos = 4; |
100 | double aprovadosPercent = ((int)10/16*100.0)/100.0; |
91 | double aprovadosPercent = ((int)10/16*100.0)/100.0; |
101 | double reprovadosPercent = ((int)2/16*100.0)/100.0; |
92 | double reprovadosPercent = ((int)2/16*100.0)/100.0; |
102 | double semElementosPercent = ((int)4/16*100.0)/100.0; |
93 | double semElementosPercent = ((int)4/16*100.0)/100.0; |
103 | 94 | ||
104 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
95 | String tempName = BytesUtils.generateHexKey() + ".png"; |
105 | 96 | ||
106 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
97 | DefaultPieDataset data = new DefaultPieDataset(); |
107 | if(reprovados > 0) |
98 | if(reprovados > 0) |
108 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados), "Reprovados " + reprovadosPercent + "%","Reprovados2 " + reprovadosPercent + "%" ); |
99 | data.setValue("Reprovados " + reprovadosPercent + "%", new Double(reprovados)); |
109 | if(aprovados > 0) |
100 | if(aprovados > 0) |
110 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados),"Aprovados " + aprovadosPercent + "%","Aprovados2 " + aprovadosPercent + "%"); |
101 | data.setValue("Aprovados " + aprovadosPercent + "%", new Double(aprovados)); |
111 | if(semElementos > 0) |
102 | if(semElementos > 0) |
112 | data.setValue(new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos),"Sem Elementos " + semElementosPercent + "%", "Sem Elementos2 " + semElementosPercent + "%"); |
103 | data.setValue("Sem Elementos " + semElementosPercent + "%", new Double(semElementos)); |
- | 104 | ||
- | 105 | //Grafico Circulo |
|
- | 106 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
|
113 | 107 | ||
114 | //Grafico Barras |
108 | //Grafico Barras |
115 | JFreeChart chart = ChartFactory.createBarChart(null, null,null,data, PlotOrientation.VERTICAL, true,true,false); |
109 | //JFreeChart chart = ChartFactory.createBarChart("OLA", null,null,null, PlotOrientation.VERTICAL, true,true,false); |
116 | 110 | ||
117 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
111 | chart.setBackgroundPaint(new Color(255,255,255)); |
118 | - | ||
119 | CategoryPlot plot = chart.getCategoryPlot(); |
112 | PiePlot plot = (RingPlot) chart.getPlot(); |
120 | - | ||
121 | plot.setRangeGridlinePaint(1.5.0/docs/api/java/awt/Color.html">Color.black); |
- | |
122 | - | ||
123 | ChartFrame chatFrm = new ChartFrame("APROVADOS",chart,true); |
- | |
124 | chatFrm.setVisible(true); |
- | |
125 | chatFrm.setSize(500,400); |
- | |
126 | - | ||
127 | /* |
- | |
128 | plot.setLabelBackgroundPaint(new Color(255, 249, 235)); |
113 | plot.setLabelBackgroundPaint(new Color(255, 249, 235)); |
129 | plot.setLabelPaint(new Color(88, 88, 90)); |
114 | plot.setLabelPaint(new Color(88, 88, 90)); |
130 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
115 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
131 | 116 | ||
132 | plot.setSectionPaint(0, new Color(255, 0, 0)); |
117 | plot.setSectionPaint(0, new Color(255, 0, 0)); |
Line 137... | Line 122... | ||
137 | 122 | ||
138 | 123 | ||
139 | 124 | ||
140 | plot.setLabelFont(new Font( |
125 | plot.setLabelFont(new Font( |
141 | "Helvetica", Font.PLAIN, 30)); |
126 | "Helvetica", Font.PLAIN, 30)); |
142 | */ |
127 | |
143 | 128 | ||
144 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
129 | BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
145 | 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; |
130 | String pathGraficoTiposAlunos = Globals.TMP_DIR + java.io.File.separator + tempName; |
146 | 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); |
131 | java.io.File output = new java.io.File(pathGraficoTiposAlunos); |
147 | 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)); |
132 | ImageIO.write(image, "png", new FileOutputStream(output));*/ |
148 | - | ||
149 | 133 | ||
150 | } |
134 | } |
151 | 135 | ||
152 | 136 | ||
153 | } |
137 | } |
154 | 138 |