Rev 1927 | 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 | |||
1887 | grupo5 | 3 | import jomm.utils.BytesUtils; |
4 | import jomm.utils.MimeTypeGuesser; |
||
5 | import org.jfree.chart.ChartFactory; |
||
6 | import org.jfree.chart.JFreeChart; |
||
7 | import org.jfree.chart.plot.PiePlot; |
||
1927 | grupo5 | 8 | import org.jfree.chart.plot.PlotOrientation; |
1887 | grupo5 | 9 | import org.jfree.chart.plot.RingPlot; |
10 | import org.jfree.data.general.DefaultPieDataset; |
||
11 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
||
12 | import pt.estgp.estgweb.utils.Globals; |
||
13 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
||
14 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
||
1830 | jmachado | 15 | |
1887 | grupo5 | 16 | import javax.imageio.ImageIO; |
17 | import java.awt.*; |
||
18 | import java.awt.image.BufferedImage; |
||
19 | import java.io.FileOutputStream; |
||
20 | import java.io.IOException; |
||
21 | |||
1830 | jmachado | 22 | /** |
23 | * Created by jorgemachado on 31/10/17. |
||
24 | */ |
||
1887 | grupo5 | 25 | public class GlobalLearningResultsChartImg extends ImageComponent |
1830 | jmachado | 26 | { |
1887 | grupo5 | 27 | /** |
28 | * |
||
29 | * @param results |
||
30 | * @return the tmp path for generated chart |
||
31 | * @throws IOException |
||
32 | */ |
||
33 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results,CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
||
34 | { |
||
35 | float aprovados = results.getAprovados(); |
||
36 | float reprovados = results.getReprovados(); |
||
37 | float semElementos = results.getSemElementos(); |
||
38 | double aprovadosPercent = ((int)(results.getAprovadosPercent()*100.0))/100.0; |
||
39 | double reprovadosPercent = ((int)(results.getReprovadosPercent()*100.0))/100.0; |
||
40 | double semElementosPercent = ((int)(results.getSemElementosPercent()*100.0))/100.0; |
||
1830 | jmachado | 41 | |
1887 | grupo5 | 42 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
43 | |||
1974 | grupo5 | 44 | DefaultPieDataset data = new DefaultPieDataset(); |
1887 | grupo5 | 45 | if(reprovados > 0) |
1974 | grupo5 | 46 | data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados)); |
1887 | grupo5 | 47 | if(aprovados > 0) |
1974 | grupo5 | 48 | data.setValue("Aprovados " + aprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados)); |
1887 | grupo5 | 49 | if(semElementos > 0) |
1974 | grupo5 | 50 | data.setValue("Sem Elementos " + semElementosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos)); |
1927 | grupo5 | 51 | |
1974 | grupo5 | 52 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
1887 | grupo5 | 53 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
1974 | grupo5 | 54 | PiePlot plot = (RingPlot) chart.getPlot(); |
55 | plot.setLabelBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 249, 235)); |
||
56 | plot.setLabelPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(88, 88, 90)); |
||
1887 | grupo5 | 57 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
1974 | grupo5 | 58 | |
1887 | grupo5 | 59 | plot.setSectionPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(255, 0, 0)); |
60 | plot.setSectionPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(15, 218, 10)); |
||
61 | plot.setSectionPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
||
1974 | grupo5 | 62 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(240, 240, 240)); |
63 | plot.setOutlineVisible(true); |
||
1887 | grupo5 | 64 | |
1974 | grupo5 | 65 | |
66 | |||
1887 | grupo5 | 67 | plot.setLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font( |
68 | "Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
||
69 | |||
70 | |||
71 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
||
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; |
||
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); |
||
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)); |
||
75 | |||
76 | FileUploaded fileUploaded = new FileUploaded(); |
||
77 | fileUploaded.setTmpName(tempName); |
||
78 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
||
79 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
||
80 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
||
81 | fileUploaded.setFileSize(output.length()); |
||
82 | fileUploaded.setExtension("png"); |
||
83 | return fileUploaded; |
||
84 | } |
||
85 | |||
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 { |
||
1974 | grupo5 | 87 | |
88 | /*float aprovados = 10; |
||
1887 | grupo5 | 89 | float reprovados = 2; |
90 | float semElementos = 4; |
||
91 | double aprovadosPercent = ((int)10/16*100.0)/100.0; |
||
92 | double reprovadosPercent = ((int)2/16*100.0)/100.0; |
||
93 | double semElementosPercent = ((int)4/16*100.0)/100.0; |
||
94 | |||
95 | String tempName = BytesUtils.generateHexKey() + ".png"; |
||
96 | |||
1974 | grupo5 | 97 | DefaultPieDataset data = new DefaultPieDataset(); |
1887 | grupo5 | 98 | if(reprovados > 0) |
1974 | grupo5 | 99 | data.setValue("Reprovados " + reprovadosPercent + "%", new Double(reprovados)); |
1887 | grupo5 | 100 | if(aprovados > 0) |
1974 | grupo5 | 101 | data.setValue("Aprovados " + aprovadosPercent + "%", new Double(aprovados)); |
1887 | grupo5 | 102 | if(semElementos > 0) |
1974 | grupo5 | 103 | data.setValue("Sem Elementos " + semElementosPercent + "%", new Double(semElementos)); |
1927 | grupo5 | 104 | |
1974 | grupo5 | 105 | //Grafico Circulo |
106 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
||
107 | |||
1927 | grupo5 | 108 | //Grafico Barras |
1974 | grupo5 | 109 | //JFreeChart chart = ChartFactory.createBarChart("OLA", null,null,null, PlotOrientation.VERTICAL, true,true,false); |
1927 | grupo5 | 110 | |
1887 | grupo5 | 111 | chart.setBackgroundPaint(new Color(255,255,255)); |
1974 | grupo5 | 112 | PiePlot plot = (RingPlot) chart.getPlot(); |
1887 | grupo5 | 113 | plot.setLabelBackgroundPaint(new Color(255, 249, 235)); |
114 | plot.setLabelPaint(new Color(88, 88, 90)); |
||
115 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
||
116 | |||
117 | plot.setSectionPaint(0, new Color(255, 0, 0)); |
||
118 | plot.setSectionPaint(1, new Color(15, 218, 10)); |
||
119 | plot.setSectionPaint(2, new Color(200, 200, 200)); |
||
120 | plot.setBackgroundPaint(new Color(255, 255, 255)); |
||
121 | plot.setOutlineVisible(false); |
||
122 | |||
123 | |||
124 | |||
125 | plot.setLabelFont(new Font( |
||
126 | "Helvetica", Font.PLAIN, 30)); |
||
127 | |||
1974 | grupo5 | 128 | |
1887 | grupo5 | 129 | BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
130 | String pathGraficoTiposAlunos = Globals.TMP_DIR + java.io.File.separator + tempName; |
||
131 | java.io.File output = new java.io.File(pathGraficoTiposAlunos); |
||
1974 | grupo5 | 132 | ImageIO.write(image, "png", new FileOutputStream(output));*/ |
1887 | grupo5 | 133 | |
134 | } |
||
135 | |||
136 | |||
137 | } |