Rev 1862 | Rev 1907 | 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 | |||
1906 | grupo6 | 3 | import com.orsoncharts.legend.StandardLegendBuilder; |
4 | import jomm.utils.BytesUtils; |
||
5 | import jomm.utils.MimeTypeGuesser; |
||
6 | import org.jfree.chart.ChartFactory; |
||
7 | import org.jfree.chart.ChartPanel; |
||
8 | import org.jfree.chart.JFreeChart; |
||
9 | import org.jfree.chart.axis.CategoryAxis; |
||
10 | import org.jfree.chart.axis.ValueAxis; |
||
11 | import org.jfree.chart.plot.*; |
||
12 | import org.jfree.chart.renderer.category.BarRenderer; |
||
13 | import org.jfree.chart.renderer.category.CategoryItemRenderer; |
||
14 | import org.jfree.chart.renderer.category.GroupedStackedBarRenderer; |
||
15 | import org.jfree.data.KeyToGroupMap; |
||
16 | import org.jfree.data.category.CategoryRangeInfo; |
||
17 | import org.jfree.data.category.DefaultCategoryDataset; |
||
18 | import org.jfree.data.general.DefaultPieDataset; |
||
19 | import org.jfree.ui.GradientPaintTransformType; |
||
20 | import org.jfree.ui.RectangleInsets; |
||
21 | import org.jfree.ui.StandardGradientPaintTransformer; |
||
22 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument; |
||
23 | import pt.estgp.estgweb.utils.Globals; |
||
1830 | jmachado | 24 | import pt.estgp.estgweb.utils.documentBuilder.AutoImageWraperComponent; |
1906 | grupo6 | 25 | import pt.estgp.estgweb.utils.documentBuilder.ImageComponent; |
26 | import pt.estgp.estgweb.web.controllers.utils.FileUploaded; |
||
1830 | jmachado | 27 | |
1906 | grupo6 | 28 | import javax.imageio.ImageIO; |
29 | import java.awt.*; |
||
30 | import java.awt.image.BufferedImage; |
||
31 | import java.io.FileOutputStream; |
||
32 | import java.io.IOException; |
||
33 | import java.util.List; |
||
34 | |||
1830 | jmachado | 35 | /** |
36 | * Created by jorgemachado on 31/10/17. |
||
37 | */ |
||
1906 | grupo6 | 38 | public class GlobalLearningResultsChartYearImg extends ImageComponent |
1830 | jmachado | 39 | { |
1906 | grupo6 | 40 | /** |
41 | * |
||
42 | * @param results |
||
43 | * @return the tmp path for generated chart |
||
44 | * @throws IOException |
||
45 | */ |
||
46 | public FileUploaded generateChart2tmp(UnitsLearningResultsTable results, CourseReportDocument courseReportDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException |
||
47 | { |
||
48 | List<UnitsLearningResultYear> unitsLearningResultYearList = results.getYears(); |
||
49 | |||
50 | |||
51 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
||
52 | |||
53 | DefaultCategoryDataset data = new DefaultCategoryDataset(); |
||
54 | |||
55 | for(UnitsLearningResultYear temp: unitsLearningResultYearList) { |
||
56 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double((int)(temp.getAprovados1013Percent()*100)/100),"Aprovados 10-13",""+temp.ano + "º Ano"); |
||
57 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double((int)(temp.getAprovados1416Percent()*100)/100),"Aprovados 14-16",""+temp.ano + "º Ano"); |
||
58 | data.addValue(new 1.5.0/docs/api/java/lang/Double.html">Double((int)(temp.getAprovados1720Percent()*100)/100),"Aprovados 17-20",""+temp.ano + "º Ano"); |
||
59 | } |
||
60 | |||
61 | JFreeChart chart = ChartFactory.createStackedBarChart(null,null,null,data, PlotOrientation.VERTICAL,true,false,false); |
||
62 | |||
63 | CategoryPlot plot = chart.getCategoryPlot(); |
||
64 | RectangleInsets chartRectangle = new RectangleInsets(0,0,30F,0); |
||
65 | chart.setPadding(chartRectangle); |
||
66 | plot.setBackgroundPaint(1.5.0/docs/api/java/awt/Color.html">Color.WHITE); |
||
67 | CategoryAxis axis = plot.getDomainAxis(); |
||
68 | ValueAxis axis2 = plot.getRangeAxis(); |
||
69 | axis.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)); |
||
70 | axis2.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)); |
||
71 | BarRenderer renderer = (BarRenderer) plot.getRenderer(); |
||
72 | renderer.setSeriesPaint(0, 1.5.0/docs/api/java/awt/Color.html">Color.ORANGE); |
||
73 | renderer.setSeriesPaint(1, 1.5.0/docs/api/java/awt/Color.html">Color.YELLOW); |
||
74 | renderer.setSeriesPaint(2, 1.5.0/docs/api/java/awt/Color.html">Color.GREEN); |
||
75 | renderer.setMaximumBarWidth(.35); |
||
76 | |||
77 | 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)); |
||
78 | |||
79 | |||
80 | 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/lang/String.html">String pathGraficoTiposAlunos = Globals.TMP_DIR + java.io.1.5.0/docs/api/java/io/File.html">File.separator + tempName; |
||
82 | 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 | 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)); |
||
84 | |||
85 | FileUploaded fileUploaded = new FileUploaded(); |
||
86 | fileUploaded.setTmpName(tempName); |
||
87 | fileUploaded.setTitle("Taxa global de aproveitamento"); |
||
88 | fileUploaded.setDescription("Curso: " + courseReportDocument.getCourseName() + " (" + courseReportDocument.getCourseCode()+ ") ano " + courseReportDocument.getYear()); |
||
89 | fileUploaded.setContentType(MimeTypeGuesser.getInstance().guessMimeType(output)); |
||
90 | fileUploaded.setFileSize(output.length()); |
||
91 | fileUploaded.setExtension("png"); |
||
92 | return fileUploaded; |
||
93 | } |
||
94 | |||
95 | 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 { |
||
96 | float aprovados = 10; |
||
97 | float reprovados = 2; |
||
98 | float semElementos = 4; |
||
99 | double aprovadosPercent = ((int)10/16*100.0)/100.0; |
||
100 | double reprovadosPercent = ((int)2/16*100.0)/100.0; |
||
101 | double semElementosPercent = ((int)4/16*100.0)/100.0; |
||
102 | |||
103 | 1.5.0/docs/api/java/lang/String.html">String tempName = BytesUtils.generateHexKey() + ".png"; |
||
104 | |||
105 | DefaultPieDataset data = new DefaultPieDataset(); |
||
106 | if(reprovados > 0) |
||
107 | data.setValue("Reprovados " + reprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(reprovados)); |
||
108 | if(aprovados > 0) |
||
109 | data.setValue("Aprovados " + aprovadosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(aprovados)); |
||
110 | if(semElementos > 0) |
||
111 | data.setValue("Sem Elementos " + semElementosPercent + "%", new 1.5.0/docs/api/java/lang/Double.html">Double(semElementos)); |
||
112 | JFreeChart chart = ChartFactory.createRingChart(null, data, false, true, false); |
||
113 | chart.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255,255,255)); |
||
114 | PiePlot plot = (RingPlot) chart.getPlot(); |
||
115 | plot.setLabelBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 249, 235)); |
||
116 | plot.setLabelPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(88, 88, 90)); |
||
117 | //plot.setDrawingSupplier(new ChartBuilderUtil.ChartDrawingSupplier()); |
||
118 | |||
119 | plot.setSectionPaint(0, new 1.5.0/docs/api/java/awt/Color.html">Color(47, 35, 255)); |
||
120 | plot.setSectionPaint(1, new 1.5.0/docs/api/java/awt/Color.html">Color(15, 218, 10)); |
||
121 | plot.setSectionPaint(2, new 1.5.0/docs/api/java/awt/Color.html">Color(200, 200, 200)); |
||
122 | plot.setBackgroundPaint(new 1.5.0/docs/api/java/awt/Color.html">Color(255, 255, 255)); |
||
123 | plot.setOutlineVisible(false); |
||
124 | |||
125 | |||
126 | |||
127 | plot.setLabelFont(new 1.5.0/docs/api/java/awt/Font.html">Font( |
||
128 | "Helvetica", 1.5.0/docs/api/java/awt/Font.html">Font.PLAIN, 30)); |
||
129 | |||
130 | |||
131 | 1.5.0/docs/api/java/awt/image/BufferedImage.html">BufferedImage image = chart.createBufferedImage( 300*4, 200*4); |
||
132 | 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; |
||
133 | 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); |
||
134 | 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)); |
||
135 | |||
136 | |||
137 | } |
||
1830 | jmachado | 138 | } |