function grafico($mes = NULL, $anio = NULL) { if (empty($mes) and empty($anio)) { return; } $this->load->library('Graph'); $titulo = $data_1 = $data_2 = $data_3 = $data_tips_1 = $data_tips_2 = $data_tips_3 = array(); $fechai = $anio . str_pad($mes, 2, "0", STR_PAD_LEFT) . '01'; $fechaf = $anio . str_pad($mes, 2, "0", STR_PAD_LEFT) . '31'; $data = $this->_sincrodata($fechai, $fechaf); $om = 1; while ($this->maxval / $om > 100) { $om = $om * 10; } foreach ($data as $row) { $titulo[] = $row['dia']; $data_1[] = $row['contado'] / $om; $data_2[] = $row['credito'] / $om; $data_3[] = $row['cobrado'] / $om; $data_tips_1[] = graph::esc(number_format($row['contado'], 2, ',', '.')); $data_tips_2[] = graph::esc(number_format($row['credito'], 2, ',', '.')); $data_tips_3[] = graph::esc(number_format($row['cobrado'], 2, ',', '.')); } $odata_1 = new bar_fade(50, '0xCC3399'); $odata_1->key('Contado', 10); $odata_1->data = $data_1; $odata_1->tips = $data_tips_1; $odata_2 = new bar_fade(50, '0x80a033'); $odata_2->key('Crédito', 10); $odata_2->data = $data_2; $odata_2->tips = $data_tips_2; $odata_3 = new line_hollow(2, 3, '0x9933CC'); $odata_3->key('Cobranzas a Crédito', 10); $odata_3->data = $data_3; $odata_3->tips = $data_tips_3; $g = new Graph(); if ($this->maxval > 0) { $g->title('Ventas del mes ' . $mes . '/' . $anio, '{font-size:18px; color: #d01f3c}'); $g->set_is_decimal_separator_comma(1); $g->data_sets[] = $odata_3; $g->data_sets[] = $odata_1; $g->data_sets[] = $odata_2; $g->set_y_max(ceil($this->maxval / $om)); $g->y_label_steps(5); $g->set_x_labels($titulo); $ejey = number_format($om, 0, '', '.'); $g->set_y_legend('Venta X ' . $ejey . ' (Bs)', 14, '0x639F45'); $g->set_x_legend('Días del mes ' . $mes, 14, '0x639F45'); $g->set_tool_tip('#key#<br>Día: #x_label# <br>Monto: #tip#'); } else { $g->title('No existen ventas en la Fecha Seleccionada', '{font-size:18px; color: #d01f3c}'); } $g->bg_colour = '#FFFFFF'; //$g->set_bg_image(site_url('/images/ventafon.png'), 'center', 'middle' ); echo utf8_encode($g->render()); }
function grafico($anio = '') { if (empty($anio)) { return; } $this->load->library('Graph'); $titulo = $data_1 = $data_2 = $data_3 = $data_tips_1 = $data_tips_2 = $data_tips_3 = array(); $fechai = $anio . '0101'; $fechaf = $anio . '1231'; $data = $this->_sincrodata($fechai, $fechaf); $om = 1; while ($this->maxval / $om > 100) { $om = $om * 10; } //print_r($data); foreach ($data as $row) { $titulo[] = $row['mes']; $data_1[] = $row['contado'] / $om; $data_2[] = $row['credito'] / $om; $data_3[] = $row['cobrado'] / $om; $data_tips_1[] = graph::esc(number_format($row['contado'], 2, ',', '.')); $data_tips_2[] = graph::esc(number_format($row['credito'], 2, ',', '.')); $data_tips_3[] = graph::esc(number_format($row['cobrado'], 2, ',', '.')); } $odata_1 = new bar_fade(50, '0xCC3399'); $odata_1->key('Contado', 10); $odata_1->data = $data_1; $odata_1->tips = $data_tips_1; $odata_2 = new bar_fade(50, '0x80a033'); $odata_2->key('Crédito', 10); $odata_2->data = $data_2; $odata_2->tips = $data_tips_2; $odata_4 = new line_hollow(2, 3, '0x9933CC'); $odata_4->key('Cobranzas a Crédito', 10); $odata_4->data = $data_3; $odata_4->tips = $data_tips_3; for ($i = 0; $i < count($data_1); $i++) { $mes = $i + 1; $odata_1->links[] = site_url("/hospitalidad/mensuales/index/{$mes}/{$anio}"); $odata_2->links[] = site_url("/hospitalidad/mensuales/index/{$mes}/{$anio}"); $odata_3->links[] = site_url("/hospitalidad/mensuales/index/{$mes}/{$anio}"); } $g = new Graph(); $g->set_is_decimal_separator_comma(1); if ($this->maxval > 0) { $g->title('Ventas en el año ' . $anio, '{font-size:18px; color: #d01f3c}'); $g->data_sets[] = $odata_1; $g->data_sets[] = $odata_2; $g->data_sets[] = $odata_4; $g->set_y_max(ceil($this->maxval / $om)); $g->y_label_steps(5); $g->set_x_labels($titulo); $ejey = number_format($om, 0, '', ' '); $g->set_y_legend('Venta X ' . $ejey . ' (Bs)', 14, '0x639F45'); $g->set_x_legend('Meses', 14, '0x639F45'); $g->set_tool_tip('#key#<br>Mes: #x_label# <br>Monto: #tip#'); } else { $g->title('NO existen ventas en el año seleccionado', '{font-size:18px; color: #d01f3c}'); } $g->bg_colour = '#FFFFFF'; echo utf8_encode($g->render()); }
/** * Método que cria um gráfico de estatisticas de acesso pela classe Graph do pacote * Open Chart Flash http://sourceforge.net/projects/o-flash-chart/ * * @author Deivid Martins * @access public * @param Object $stats * @param Integer $startYear * @param Integer $lastYear * @return Boolean $graficoStatus se o gráfico foi montado ou não **/ function buildGraphicByYearFlash($stats, $startYear, $lastYear) { $graph = new Graph(); $graficoStatus = false; // Se existem ou não estatisticas $dadosRequeridos = array(); // Estatisticas que usuario pediu $maximo = 0; // Maior valor do gráfico // Gabarito de cores para linhas do gráfico $cores = array("#191970", "#FFA500", "#A020F0", "#008B8B", "#CD1076", "#FF0000", "#A0522D", "#66CDAA", "#8B8B7A", "#FFB5C5", "#8B0000", "#006400"); // DarkGreen $stat = $stats->getRequests(); foreach ($stat as $s) { $mes = intval($s->getMonth()); $ano = intval($s->getYear()); if ($s->getNumberOfRequests() == "") { $values[$ano][$mes] = 0; } else { $values[$ano][$mes] = $s->getNumberOfRequests(); } } // Montamos o gráfico //$graph->title( utf8_encode(ARTICLE_ACCESS), 14, '#000000' ); //Estamos montando o titulo no html $graph->bg_colour = '#FFFFFF'; $graph->set_inner_background('#F8F8FF', '#CBD7E6', 90); // Somente monta o gráfico dos anos exigidos pelo usuário for ($i = 0; $i <= $lastYear - $startYear; $i++) { $dadosRequeridos[$i] = range(0, 11); $graficoStatus = true; // entrou no for significa que o gráfico vai ser construido for ($j = 0; $j < 12; $j++) { /* Tem alguns meses que não existem estatisticas e retorna null e o php retorna o array quebrado Ex: ([0] => 5, [1] => 7, [5] => 6) pulando alguns elementos */ if (is_null($values[$startYear + $i][$j + 1])) { $dadosRequeridos[$i][$j] = 'null'; } else { $dadosRequeridos[$i][$j] = $values[$startYear + $i][$j + 1]; } } // Procuramos o maior valor daquele ano $tempMax = max($values[$startYear + $i]); if ($tempMax > $maximo) { $maximo = $tempMax; } // Criamos a linha de um determinado ano $graph->set_data($dadosRequeridos[$i]); $graph->line_hollow(2, 3, $cores[$i], $startYear + $i, 11); $graph->set_tool_tip(ACCESSES . ': #val#'); } // Não existem dados, portanto o gráfico não deve ser montado if ($graficoStatus == false) { return $graficoStatus; } // Dados eixo X $graph->set_x_labels(explode(",", MONTH_LIST)); $graph->set_x_label_style(11, '#333333', 2); // Valor máximo do eixo Y $graph->set_y_max($maximo + 2); $graph->set_y_label_style(11, '#333333'); $graph->y_label_steps(4); // Legendas eixo X e Y $graph->set_x_legend(MONTHS, 12, '#444444'); $graph->set_y_legend(ACCESSES, 12, '#444444'); $graph->set_x_tick_size(10); // Cores da grade $graph->x_axis_colour('#68838B', '#FFFFFF'); $graph->y_axis_colour('#68838B', '#FFFFFF'); // Mostra o gráfico somente se, o ano que o usuario entrou existir estatisticas if ($graficoStatus == true) { echo $graph->render(); } return $graficoStatus; }
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(); }
function departa() { $this->load->library('Graph'); $data = $titu = array(); $mes = $this->uri->segment(4); $anio = $this->uri->segment(5); if (empty($mes) and empty($anio)) { return; } $fechai = $anio . $mes . '01'; $fechaf = $anio . $mes . '31'; //8471.49.00.00 $mSQL = "SELECT f.descrip etiqueta, sum(b.importe) total\n\t\t\tFROM itscst b JOIN scst a ON a.control=b.control \n\t\t\tJOIN sinv c ON b.codigo=c.codigo\n\t\t\tJOIN grup d ON d.grupo=c.grupo\n\t\t\tJOIN line e ON d.linea=e.linea \n\t\t\tJOIN dpto f ON e.depto=f.depto \n\t\t\tWHERE a.tipo_doc IN ('FC', 'NC','NE') AND a.fecha>={$fechai} AND a.fecha<={$fechaf}\n\t\t\tGROUP BY f.depto"; //echo $mSQL; $maxval = 0; $query = $this->db->query($mSQL); foreach ($query->result() as $row) { if ($row->total > $maxval) { $maxval = $row->total; } $data[] = $row->total; $titu[] = $row->etiqueta; } $i = 1; while (1) { if ($maxval / $i <= 100) { break; } $i = $i * 10; } $om = $i; $i = 0; //$om=1; for ($i = 0; $i < count($data); $i++) { $data[$i] = $data[$i] / $om; } $g = new Graph(); if ($maxval > 0) { $g->title('COMPRAS DEL ' . $mes . '/' . $anio, '{font-size:18px; color: #d01f3c}'); $g->set_data($data); $g->bar_glass(55, '#5E83BF', '#424581', 'Compras', 10); $g->set_y_max(ceil($maxval / $om)); $g->y_label_steps(5); $g->set_x_labels($titu); $ejey = number_format($om, 0, '', ' '); $g->set_y_legend('Compras X ' . $ejey . ' (Bs)', 14, '0x639F45'); $g->set_x_legend('Grupos ' . $mes, 14, '0x639F45'); //$g->pie(60,'#505050','#000000'); //$g->pie_values( $data, $titu ); //$g->pie_slice_colours( array('#d01f3c','#356aa0','#C79810','#5E83BF')); $g->set_tool_tip('#key#<br>Departamento: #x_label# <br>Monto: #val# x ' . $ejey); } else { $g->title('NO EXISTEN VENTAS EN LA FECHA SELECCIONADA', '{font-size:18px; color: #d01f3c}'); } $g->bg_colour = '#FFFFFF'; //$g->set_bg_image(site_url('/images/ventafon.png'), 'center', 'middle' ); echo $g->render(); $query->free_result(); }