Sunday, 16 April 2017

Iterations into google chart javascript into jade

I have the following code into jade view:

   script(type='text/javascript').
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(porHoras);
      function porHoras() {
         var data = new google.visualization.DataTable();
         data.addColumn('string', "Hora");
         data.addColumn('number', 'Visitas');
         if (!{registro.length} > 0) {
           data.addRow(['!{registro[0].hora}',!{registro[0].vHora}]);
         } 
         if (!{registro.length} > 1) {
           data.addRow(['!{registro[1].hora}',!{registro[1].vHora}]);
         }
         if (!{registro.length} > 2) {
           data.addRow(['!{registro[2].hora}',!{registro[2].vHora}]);
         } 
         if (!{registro.length} > 3) {
           data.addRow(['!{registro[3].hora}',!{registro[3].vHora}]);
         } 
         if (!{registro.length} > 4) {
           data.addRow(['!{registro[4].hora}',!{registro[4].vHora}]);
         }
         if (!{registro.length} > 5) {
           data.addRow(['!{registro[5].hora}',!{registro[5].vHora}]);
         } 

and in my node.js router

res.render('inicio', {registro: JSON.stringify(datah)});

That is working fine but, How can I do the same with a for loop?

Thanks in advance.



via emanzan

No comments:

Post a Comment