Example #1
0
 function grafico()
 {
     $this->load->library('Graph');
     $data = array();
     $dia = array();
     $mSQL = "SELECT if(b.tipo IS NULL,a.tipo,b.nombre) nombre, sum(a.monto*(SUBSTRING(a.numero,1,1)<>'X')) monto\n\t\t\t FROM viepag a LEFT JOIN tarjeta b ON a.tipo=b.tipo\n\t\t\t WHERE fecha BETWEEN 20070101 AND 20070131 \n\t\t\t GROUP BY a.tipo ORDER BY monto DESC";
     $res = $this->db->query($mSQL) or die("Bad SQL 1");
     $total = 0;
     foreach ($res->result() as $row) {
         if ($row->monto < 0) {
             $total += $row->monto * -1;
         } else {
             $total += $row->monto;
         }
     }
     $res->first_row();
     foreach ($res->result() as $row) {
         $titu[] = substr($row->nombre, 0, 20);
         if ($row->monto < 0) {
             $data[] = round($row->monto * 100 / $total * -1, 0);
         } else {
             $data[] = round($row->monto * 100 / $total, 0);
         }
     }
     // use the chart class to build the chart:
     $g = new Graph();
     $g->title('DISTRIBUCION DE LA COBRANZA ', '{font-size:18px; color: #d01f3c}');
     $g->set_data($data);
     $g->bar_filled(80, '#9933CC', '#8010A0', '', 10);
     $g->set_y_max(100);
     $g->bg_colour = '#FFFFFF';
     $g->y_label_steps(5);
     $g->set_x_labels($titu);
     $g->set_y_legend('Porcentaje de Venta', 14, '0x639F45');
     $g->set_x_legend('Forma de Pago', 14, '0x639F45');
     $g->set_bg_image(site_url('/images/ventafon.png'), 'center', 'middle');
     $g->set_tool_tip('#val#%25');
     echo $g->render();
     $res->free_result();
 }