Advertisement
yesamarcos

Como iterar dados e codes??

Sep 18th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             $.ajax({
  2.                 url: CAMINHO+'relatorios/getAllPesqComData',
  3.                 type: 'POST', dataType: 'json',
  4.                 data: {aData:aData, idPesq:idPesq},
  5.                 success: function(ret){
  6.                     var codes = ret;
  7.                     $.ajax({
  8.                         url: CAMINHO+'relatorios/getAllPesqComDataEDados',
  9.                         type: 'POST', dataType: 'json',
  10.                         data: {aData:aData, idPesq:idPesq, codes:codes},
  11.                         success: function(retorno){
  12.                             // ...
  13.                             var dados = retorno;
  14.                             // ...
  15.                             function drawChart(){
  16.  
  17.                                 console.log(codes);
  18.                                 console.log(dados);
  19.  
  20.                                 $.each(codes, function(index, el) {
  21.  
  22.                                     /** Criando e imprimindo a quantidade de gráficos carregados ... */
  23.                                     var bloco = "PierChart"+codes[index]+"";
  24.                                     $("#estatisticas").append("<div id='"+bloco+"'></div>");
  25.  
  26.                                     // Create the data table.
  27.                                     var data = new google.visualization.DataTable();
  28.                                     data.addColumn('string', 'Topping');
  29.                                     data.addColumn('number', 'Slices');
  30.  
  31.                                     // O RPOBLEMA É AQUI ...
  32.                                     // Esse é um loop, eu precisar iterar sob cada codes[index] puxando os dados referente
  33.                                     // a cada um dos "ids" presentes na aplicação, algo parecido com >>> dados[codes[index]] ...
  34.  
  35.                                     data.addRows([
  36.                                         ['Mushrooms', 3],
  37.                                         ['Onions', 1],
  38.                                         ['Olives', 1],
  39.                                         ['Zucchini', 1],
  40.                                         ['Pepperoni', 2]
  41.                                     ]);
  42.                                     // Set chart options
  43.                                     var options = {
  44.                                         'title':'How Much Pizza I Ate Last Night',
  45.                                         'width'     :900,
  46.                                         'height'    :400
  47.                                     };
  48.                                     // Instantiate and draw our chart, passing in some options.
  49.                                     var chart = new google.visualization.PieChart(document.getElementById(bloco));
  50.                                     chart.draw(data, options);
  51.                                 });
  52.                             }
  53.                             /*
  54.                              * Load the Visualization API and the corechart package.
  55.                              * Set a callback to run when the Google Visualization API is loaded.
  56.                             */
  57.                             google.charts.load('current', {'packages':['corechart']});
  58.                             google.charts.setOnLoadCallback(drawChart);
  59.                         }
  60.                     });
  61.                 }
  62.             });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement