Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. package br.sp.usjt.serverSocket.Model;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.util.Map;
  8.  
  9. public class RelatorioGenerate {
  10.  
  11. String cabecalho =
  12. "<!DOCTYPE html>\n" +
  13. "<html>\n" +
  14. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n" +
  15. " <head>";
  16.  
  17. public RelatorioGenerate(){
  18. }
  19.  
  20. public File mount(String nomeRelatorio, Map<Integer, Integer> map, String relatorioType){
  21. StringBuffer inputBuffer = new StringBuffer();
  22.  
  23. String line;
  24.  
  25. File result = null;
  26.  
  27. inputBuffer.append(cabecalho);
  28.  
  29. line = "<script src=\"https://canvasjs.com/assets/script/canvasjs.min.js\"></script>\n" +
  30. " <script type=\"text/javascript\">\n" +
  31. " window.onload = function() {\n" +
  32. " var chart = new CanvasJS.Chart(\"chartContainer\", {\n" +
  33. " title: {\n" +
  34. " text: \"" + nomeRelatorio + "\"\n" +
  35. " },\n" +
  36. " data: [\n" +
  37. " {\n" +
  38. " type: \"" + relatorioType + "\",\n" +
  39. " dataPoints: [ \n";
  40.  
  41. inputBuffer.append(line);
  42.  
  43. int cont = 1;
  44.  
  45. for(Map.Entry<Integer, Integer> pair : map.entrySet()){
  46. if(cont < map.entrySet().size()) {
  47. inputBuffer.append("{ label: \"HTTP Code: " + pair.getKey() + "\", y: " + pair.getValue() + "},\n");
  48. cont++;
  49. }else{
  50. inputBuffer.append("{ label: \"HTTP Code: " + pair.getKey() + "\", y: " + pair.getValue() + "}\n");
  51. }
  52. }
  53.  
  54. inputBuffer.append("]\n" +
  55. " }\n" +
  56. " ]\n" +
  57. " });\n" +
  58. " chart.render();\n" +
  59. " };\n" +
  60. " </script>");
  61.  
  62.  
  63. inputBuffer.append(" </head>\n" +
  64. " <body>\n" +
  65. " <div id=\"chartContainer\" style=\"height: 300px; width: 100%;\"></div>\n" +
  66. " </body>\n" +
  67. "</html>\n");
  68.  
  69. FileOutputStream fileOut = null;
  70.  
  71. try {
  72. result = new File("Relatorios.html");
  73.  
  74. fileOut = new FileOutputStream(result);
  75. fileOut.write(inputBuffer.toString().getBytes());
  76. fileOut.close();
  77.  
  78. } catch (FileNotFoundException e) {
  79. e.printStackTrace();
  80. }catch(IOException ex){
  81.  
  82. }
  83.  
  84. return result;
  85.  
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement