Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @WebServlet("/TabelaServlet")
- public class TabelaServlet extends HttpServlet {
- public TabelaServlet() {
- }
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /**
- * Handles the HTTP <code>GET</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- /*String json_completo = "{";
- String json_aberto = "Aberto: ";
- String json_fechado;
- String json_cancelado;
- ArrayList<Submissao> smpp_arr = new ArrayList<>();*/
- List<Submissao> smpp_arr_todas = new ArrayList<>();
- Integer ano = 0;
- Enumeration params = request.getParameterNames();
- while (params.hasMoreElements()) {
- String paramName = (String) params.nextElement();
- ano = Integer.parseInt(request.getParameter(paramName));
- }
- SubmissaoDAO submissaodao = new SubmissaoDAO();
- smpp_arr_todas = submissaodao.retornaTodosSMPP();
- /*for(Submissao item: smpp_arr_todas) {
- if(item.getStatus().getCod() == 12) {
- json_fechado +=
- }
- }*/
- Gson gson = new Gson();
- JsonElement element = gson.toJsonTree(smpp_arr_todas, new TypeToken<List<Submissao>>() {
- }.getType());
- JsonArray jsonArray = element.getAsJsonArray();
- response.setContentType("application/json");
- response.getWriter().print(jsonArray);
- }}
- function gerarGrafico(valor) {
- var ctx = document.getElementById("grafico");
- var mes = [];
- var qtdAberto = [];
- var qtdFinalizado = [];
- var qtdCancelado = [];
- var ano = valor;
- $.ajax({
- type: 'GET',
- url: '../../GraficoServlet',
- data: 'ano=' + ano,
- success: function (dados) {
- $.each(dados, function (key, value) {
- mes.push(value['mes']);
- qtdAberto.push(value['qtdAberto']);
- qtdFinalizado.push(value['qtdFinalizado']);
- qtdCancelado.push(value['qtdCancelado']);
- });
- var myChart = new Chart(ctx, {
- type: 'bar',
- data: {
- labels: mes,
- datasets: [
- {
- label: "Aberta",
- backgroundColor: "rgba(0, 136, 255, 0.5)",
- borderColor: "rgba(0, 136, 255, 0.5)",
- data: qtdAberto,
- },
- {
- label: "Finalizada",
- backgroundColor: "rgba(0, 170, 0, 0.5)",
- borderColor: "rgba(0, 170, 0, 0.5)",
- data: qtdFinalizado,
- },
- {
- label: "Cancelada",
- backgroundColor: "rgba(170, 0, 0, 0.5)",
- borderColor: "rgba(170, 0, 0, 0.5)",
- data: qtdCancelado,
- }
- ]
- },
- options: {
- scales: {
- yAxes: [{
- ticks: {
- beginAtZero: true
- }
- }]
- }
- }
- });
- //Inicio Criação Tabela
- //////////////////////////////////////////////////////////////////////////////////
- //Tabela Aberta
- var tbody = document.getElementById('tbAberta');
- var json;
- $.ajax({
- type: 'GET',
- url: '../../TabelaServlet',
- data: 'ano=' + ano,
- success: function(data) {
- json = data;
- json.forEach(function (json) {
- var tr = document.createElement('tr');
- for (var campo in json) {
- var td = document.createElement('td');
- td.innerHTML = json[campo];
- tr.appendChild(td);
- };
- tbody.appendChild(tr);
- });
- }
- });
- //Fim tabela Aberta
Add Comment
Please, Sign In to add comment