Guest User

Untitled

a guest
Dec 7th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. @WebServlet("/TabelaServlet")
  2. public class TabelaServlet extends HttpServlet {
  3.  
  4. public TabelaServlet() {
  5.  
  6. }
  7.  
  8. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  9. /**
  10. * Handles the HTTP <code>GET</code> method.
  11. *
  12. * @param request servlet request
  13. * @param response servlet response
  14. * @throws ServletException if a servlet-specific error occurs
  15. * @throws IOException if an I/O error occurs
  16. */
  17. @Override
  18. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  19. /*String json_completo = "{";
  20. String json_aberto = "Aberto: ";
  21. String json_fechado;
  22. String json_cancelado;
  23. ArrayList<Submissao> smpp_arr = new ArrayList<>();*/
  24. List<Submissao> smpp_arr_todas = new ArrayList<>();
  25. Integer ano = 0;
  26. Enumeration params = request.getParameterNames();
  27. while (params.hasMoreElements()) {
  28. String paramName = (String) params.nextElement();
  29. ano = Integer.parseInt(request.getParameter(paramName));
  30. }
  31.  
  32. SubmissaoDAO submissaodao = new SubmissaoDAO();
  33. smpp_arr_todas = submissaodao.retornaTodosSMPP();
  34.  
  35. /*for(Submissao item: smpp_arr_todas) {
  36. if(item.getStatus().getCod() == 12) {
  37. json_fechado +=
  38. }
  39. }*/
  40.  
  41. Gson gson = new Gson();
  42. JsonElement element = gson.toJsonTree(smpp_arr_todas, new TypeToken<List<Submissao>>() {
  43. }.getType());
  44.  
  45. JsonArray jsonArray = element.getAsJsonArray();
  46. response.setContentType("application/json");
  47. response.getWriter().print(jsonArray);
  48.  
  49. }}
  50.  
  51. function gerarGrafico(valor) {
  52. var ctx = document.getElementById("grafico");
  53. var mes = [];
  54. var qtdAberto = [];
  55. var qtdFinalizado = [];
  56. var qtdCancelado = [];
  57. var ano = valor;
  58.  
  59. $.ajax({
  60. type: 'GET',
  61. url: '../../GraficoServlet',
  62. data: 'ano=' + ano,
  63. success: function (dados) {
  64.  
  65. $.each(dados, function (key, value) {
  66. mes.push(value['mes']);
  67. qtdAberto.push(value['qtdAberto']);
  68. qtdFinalizado.push(value['qtdFinalizado']);
  69. qtdCancelado.push(value['qtdCancelado']);
  70. });
  71.  
  72. var myChart = new Chart(ctx, {
  73. type: 'bar',
  74. data: {
  75. labels: mes,
  76. datasets: [
  77. {
  78. label: "Aberta",
  79. backgroundColor: "rgba(0, 136, 255, 0.5)",
  80. borderColor: "rgba(0, 136, 255, 0.5)",
  81. data: qtdAberto,
  82. },
  83. {
  84. label: "Finalizada",
  85. backgroundColor: "rgba(0, 170, 0, 0.5)",
  86. borderColor: "rgba(0, 170, 0, 0.5)",
  87. data: qtdFinalizado,
  88. },
  89. {
  90. label: "Cancelada",
  91. backgroundColor: "rgba(170, 0, 0, 0.5)",
  92. borderColor: "rgba(170, 0, 0, 0.5)",
  93. data: qtdCancelado,
  94. }
  95. ]
  96. },
  97. options: {
  98. scales: {
  99. yAxes: [{
  100. ticks: {
  101. beginAtZero: true
  102. }
  103. }]
  104. }
  105. }
  106. });
  107.  
  108. //Inicio Criação Tabela
  109. //////////////////////////////////////////////////////////////////////////////////
  110. //Tabela Aberta
  111. var tbody = document.getElementById('tbAberta');
  112. var json;
  113.  
  114. $.ajax({
  115. type: 'GET',
  116. url: '../../TabelaServlet',
  117. data: 'ano=' + ano,
  118. success: function(data) {
  119. json = data;
  120.  
  121. json.forEach(function (json) {
  122. var tr = document.createElement('tr');
  123. for (var campo in json) {
  124. var td = document.createElement('td');
  125. td.innerHTML = json[campo];
  126. tr.appendChild(td);
  127. };
  128. tbody.appendChild(tr);
  129. });
  130. }
  131. });
  132.  
  133. //Fim tabela Aberta
Add Comment
Please, Sign In to add comment