/** * Runs the phpOpenTracker API call. * * @param array $parameters * @return mixed * @access public */ function run($parameters) { global $locale; $parameters['api_call'] = 'localizer'; $parameters['what'] = 'top_localizer'; $parameters['result_format'] = 'separate_result_arrays'; list($names, $values, $percent, $total) = phpOpenTracker::get($parameters); $title = $locale->get('admin_stat', 'field_top') . ' ' . $parameters['limit'] . ' ' . $locale->get('admin_stat', 'field_countries'); for ($i = 0, $numValues = sizeof($values); $i < $numValues; $i++) { $legend[$i] = sprintf('%s (%s, %s%%%%)', $names[$i], $values[$i], $percent[$i]); } $graph = new PieGraph($parameters['width'], $parameters['height'], 'auto'); $graph->SetShadow(); $graph->title->Set($title); $graph->title->SetFont($parameters['font'], $parameters['font_style'], $parameters['font_size']); $graph->title->SetColor('black'); $graph->legend->Pos(0.1, 0.2); $plot = new PiePlot3d($values); $plot->SetTheme('sand'); $plot->SetCenter(0.4); $plot->SetAngle(30); $plot->value->SetFont($parameters['font'], $parameters['font_style'], $parameters['font_size'] - 2); $plot->SetLegends($legend); $graph->Add($plot); $graph->Stroke(); }
public static function pieChart($data, $legends) { $graph = new PieGraph(900, 550, 'auto'); $graph->SetShadow(); // $graph->title->Set($topic); $graph->title->SetFont(FF_VERDANA, FS_BOLD, 14); $graph->legend->Pos(0.1, 0.2); // Creating a 3D pie graphic $p1 = new PiePlot3d($data); $p1->SetTheme("sand"); $p1->SetLabels($legends); $p1->SetLabelPos(1); $p1->SetLabelType(PIE_VALUE_PER); $p1->value->Show(); $p1->value->SetFont(FF_ARIAL, FS_NORMAL, 20); $p1->value->SetColor('darkgray'); $p1->SetCenter(0.45, 0.5); $p1->SetAngle(45); $p1->ExplodeAll(20); // $p1->value->SetFont(FF_ARIAL, FS_NORMAL, 12); // $p1->SetLegends($legends); $graph->img->SetImgFormat('png'); $graph->Add($p1); // Showing graphic return $graph->Stroke('../graph/3DpieChart.png'); }
function create_pie_graph() { $graph = new PieGraph($this->width, $this->height, "auto"); //instantiate new PieGraph object $graph->SetShadow(); //displayed with shadow $graph->title->Set($this->title); //setup graph title $graph->title->SetFont(FF_VERDANA, FS_BOLD, 10); //set up font porperties $graph->title->SetColor("darkblue"); $p1 = new PiePlot3D($this->data); //define new 3D image for PieGraph $p1->ExplodeAll(); //explode each sector of the pie $p1->SetTheme("sand"); //set up the theme (Colors) $p1->SetCenter(0.45); //display on center $p1->SetLegends($this->label); //set up legend of the graph //$p1->SetLabel($this->label); //set up the labels of each sector of the pie graph // Setup the slice values $p1->value->SetFont(FF_ARIAL, FS_BOLD, 11); $p1->value->SetColor("navy"); $graph->Add($p1); //add 3D pie to PieGraph object $graph->Stroke(); //display grapg }
/** * Runs the phpOpenTracker API call. * * @param array $parameters * @return mixed * @access public */ function run($parameters) { $parameters['api_call'] = 'top'; $parameters['result_format'] = 'separate_result_arrays'; list($names, $values, $percent, $total) = phpOpenTracker::get($parameters); $title = 'Top ' . $parameters['limit'] . ' '; switch ($parameters['what']) { case 'document': $title .= 'Pages'; break; case 'entry_document': $title .= 'Entry Pages'; break; case 'exit_document': $title .= 'Exit Pages'; break; case 'exit_target': $title .= 'Exit Targets'; break; case 'host': $title .= 'Hosts'; break; case 'operating_system': $title .= 'Operating Systems'; break; case 'referer': $title .= 'Referers'; break; case 'user_agent': $title .= 'User Agents'; break; } $title .= " (Total: {$total})"; for ($i = 0, $numValues = sizeof($values); $i < $numValues; $i++) { $legend[$i] = sprintf('%s (%s, %s%%%%)', $names[$i], $values[$i], $percent[$i]); } $graph = new PieGraph($parameters['width'], $parameters['height'], 'auto'); $graph->SetShadow(); $graph->title->Set($title); $graph->title->SetFont($parameters['font'], $parameters['font_style'], $parameters['font_size']); $graph->title->SetColor('black'); $graph->legend->Pos(0.1, 0.2); $plot = new PiePlot3d($values); $plot->SetTheme('sand'); $plot->SetCenter(0.4); $plot->SetAngle(30); $plot->value->SetFont($parameters['font'], $parameters['font_style'], $parameters['font_size'] - 2); $plot->SetLegends($legend); $graph->Add($plot); $graph->Stroke(); }
function generate_image($lang, $idx) { global $LANGUAGES; $up_to_date = get_stats($idx, $lang, 'uptodate'); $up_to_date = $up_to_date[0]; // $outdated = @get_stats($idx, $lang, 'outdated'); $outdated = $outdated[0]; // $missing = get_stats($idx, $lang, 'notrans'); $missing = $missing[0]; // $no_tag = @get_stats($idx, $lang, 'norev'); $no_tag = $no_tag[0]; $data = array($up_to_date, $outdated, $missing, $no_tag); $percent = array(); $total = array_sum($data); // Total ammount in EN manual (to calculate percentage values) $total_files_lang = $total - $missing; // Total ammount of files in translation foreach ($data as $value) { $percent[] = round($value * 100 / $total); } $legend = array($percent[0] . '%% up to date (' . $up_to_date . ')', $percent[1] . '%% outdated (' . $outdated . ')', $percent[2] . '%% missing (' . $missing . ')', $percent[3] . '%% without EN-Revision (' . $no_tag . ')'); $title = 'Details for ' . $LANGUAGES[$lang] . ' PHP Manual'; $graph = new PieGraph(530, 300); $graph->SetShadow(); $graph->title->Set($title); $graph->title->Align('left'); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->legend->Pos(0.02, 0.18, "right", "center"); $graph->subtitle->Set('(Total: ' . $total_files_lang . ' files)'); $graph->subtitle->Align('left'); $graph->subtitle->SetColor('darkred'); $t1 = new Text(date('m/d/Y')); $t1->SetPos(522, 294); $t1->SetFont(FF_FONT1, FS_NORMAL); $t1->Align("right", 'bottom'); $t1->SetColor("black"); $graph->AddText($t1); $p1 = new PiePlot3D($data); $p1->SetSliceColors(array("#68d888", "#ff6347", "#dcdcdc", "#f4a460")); if ($total_files_lang != $up_to_date) { $p1->ExplodeAll(); } $p1->SetCenter(0.35, 0.55); $p1->value->Show(false); $p1->SetLegends($legend); $graph->Add($p1); $graph->Stroke("../www/images/revcheck/info_revcheck_php_{$lang}.png"); }
function PieChart($w, $h, $title, $data, $dataL, $output) { $graph = new PieGraph($w, $h, "auto"); $graph->SetFrame(false); $graph->SetShadow(false); $graph->title->Set($title); $graph->title->SetFont(FF_FONT1, FS_BOLD); $p1 = new PiePlot3D($data); $p1->SetAngle(20); $p1->SetSize(0.5); $p1->SetCenter(0.45); $p1->SetLegends($dataL); $graph->Add($p1); $graph->Stroke($output); }
function graficarPDF() { $solo_registrados = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m01_registrada IS NOT NULL AND pasantia.m02_aceptada IS NULL AND periodo.activo = TRUE"); $solo_aceptadas = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m02_aceptada IS NOT NULL AND pasantia.m03_numero_asignado IS NULL AND periodo.activo = TRUE"); $solo_numero_asignado = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m03_numero_asignado IS NOT NULL AND pasantia.m04_sellada IS NULL AND periodo.activo = TRUE"); $solo_sellada = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m04_sellada IS NOT NULL AND pasantia.m05_entrego_copia IS NULL AND periodo.activo = TRUE"); $solo_entrego_copia = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m05_entrego_copia IS NOT NULL AND pasantia.m06_entrego_borrador IS NULL AND periodo.activo = TRUE"); $solo_entrego_borrador = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m06_entrego_borrador IS NOT NULL AND pasantia.m07_retiro_borrador IS NULL AND periodo.activo = TRUE"); $solo_retiro_borrador = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m07_retiro_borrador IS NOT NULL AND pasantia.m08_entrega_final IS NULL AND periodo.activo = TRUE"); $finalizaron = contar("SELECT COUNT(*) FROM pasantia INNER JOIN periodo ON periodo.id = pasantia.periodo_id WHERE pasantia.m08_entrega_final IS NOT NULL AND periodo.activo = TRUE"); $this->MultiCell(200, 5, utf8_decode("\nRepública Bolivariana de Venezuela\nUniversidad del Zulia\nFacultad Experimental de Ciencias\nDivisión de Programas Especiales\nSistema de Pasantías\n\n\n\nEstadísticas de Hitos"), 0, "C", 0); //GENERAR LA TABLA $this->SetXY(5, 65); $this->SetFont('Arial', 'B', 12); $this->SetWidths(array(27, 25, 25, 25, 25, 25, 25, 25)); $this->SetAligns(array('C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C')); $this->Row(array("Registradas", "Aceptadas", "Numero Asignado", "Selladas", "Entrega Copia", "Entrega Borrador", "Retiro Borrador", "Finalizaron")); $this->SetX(5); $this->SetFont('Arial', '', 12); $this->SetWidths(array(27, 25, 25, 25, 25, 25, 25, 25)); $this->SetAligns(array('C', 'C', 'C', 'C', 'C', 'C', 'C', 'C')); $this->Row(array("{$solo_registrados}", "{$solo_aceptadas}", "{$solo_numero_asignado}", "{$solo_sellada}", "{$solo_entrego_copia}", "{$solo_entrego_borrador}", "{$solo_retiro_borrador}", "{$finalizaron}")); $data = array($solo_registrados, $solo_aceptadas, $solo_numero_asignado, $solo_sellada, $solo_entrego_copia, $solo_entrego_borrador, $solo_retiro_borrador, $finalizaron); //aqui va la cantidad que llevará cada parte del grafico $graph = new PieGraph(640, 480); //tamaño de la letra del titulo y la leyenda $graph->SetShadow(); $db = new PgDB(); //QUERY PARA EL PERIDO ACTIVO $queryPer = "SELECT tipo, anio FROM periodo WHERE activo = TRUE"; $recoPer = pg_query($queryPer); $rowPer = pg_fetch_array($recoPer); $graph->title->Set(utf8_decode("REPORTE TOTAL\n{$rowPer['tipo']} - {$rowPer['anio']}")); $graph->title->SetFont(FF_FONT2, FS_BOLD); $p1 = new PiePlot($data); $p1->value->Show(true); $p1->SetLegends(array("Registradas", "Aceptadas", "Numeros Asignados", "Selladas", "Entrega de Copias", "Entrega de Borrador", "Retiro de Borrador", "Finalizaron")); //la leyenda del gráfico $p1->SetSize(0.3); //el radio del gráfico //$p1->SetAngle(45); //setear el angulo $graph->Add($p1); $graph->Stroke("asd.png"); $this->Image("asd.png", -15, 85, 240, 180); // x, y, ancho, altura. $this->Image("logotipo.jpg", 20, 12, -280); unlink("asd.png"); }
function plot() { $this->_setValues(); // Create the Pie Graph. $graph = new PieGraph(500, 300); $graph->SetShadow(); // Create $p1 = new PiePlot($this->_data); // Set A title for the plot $p1->SetLegends($this->_legends); $p1->SetSize(0.3); $p1->SetCenter(0.28, 0.5); $txt = new Text("Most Visited Titles", 0.15, 0.05); $txt->SetFont(FONT1_BOLD); $graph->Add($p1); $graph->AddText($txt); $graph->Stroke(); }
/** * @@生成三维饼图 * @param string $title * @param array $data * @param int $size * @param int $height * @param int $width * @param array $legend */ static function create3dpie($title, $data = array(), $size = 40, $height = 100, $width = 80, $legend = array(), $slice = 0) { //包含相关的文件 vendor("Jpgraph.jpgraph"); vendor("Jpgraph.jpgraph_pie"); vendor("Jpgraph.jpgraph_pie3d"); // 创建图表 $graph = new PieGraph($width, $height, "auto"); $graph->SetShadow(); // 设置标题 $graph->title->Set(iconv("utf-8", "gb2312", $title)); //$graph->title->SetFont(FF_VERDANA,FS_BOLD,18); $graph->title->SetFont(FF_SIMSUN, FS_BOLD, 18); $graph->title->SetColor("darkblue"); $graph->legend->Pos(0.1, 0.2); $graph->SetFrame(false, '#ffffff', 0); //去掉周围的边框 // Create 3D pie plot $p1 = new PiePlot3d($data); $p1->SetTheme("sand"); $p1->SetCenter(0.4); $p1->SetSize($size); // Adjust projection angle $p1->SetAngle(70); // As a shortcut you can easily explode one numbered slice with if ($slice == 0) { $p1->ExplodeSlice(3); } // Setup the slice values $p1->value->SetFont(FF_ARIAL, FS_BOLD, 10); //$p1->value->SetFont(FF_SIMSUN,FS_BOLD,11); $p1->value->SetColor("navy"); $graph->legend->SetFont(FF_SIMSUN, FS_BOLD, 8); //编码转化 foreach ($legend as $k => $v) { $legend[$k] = iconv('utf-8', 'gb2312', $v); } $p1->SetLegends($legend); $graph->Add($p1); $graph->Stroke(); }
function generate_graph_image() { // Create the graph. // Set up Font Mapping Arrays $fontfamilies = array("Font 0" => FF_FONT0, "Font 1" => FF_FONT1, "Font 2" => FF_FONT2, "Font0" => FF_FONT0, "Font1" => FF_FONT1, "Font2" => FF_FONT2, "Arial" => FF_ARIAL, "Verdana" => FF_VERDANA, "Courier" => FF_COURIER, "Comic" => FF_COMIC, "Times" => FF_TIMES, "Georgia" => FF_GEORGIA, "Trebuchet" => FF_TREBUCHE, "advent_light" => advent_light, "Bedizen" => Bedizen, "Mukti_Narrow" => Mukti_Narrow, "calibri" => calibri, "Forgotte" => Forgotte, "GeosansLight" => GeosansLight, "MankSans" => MankSans, "pf_arma_five" => pf_arma_five, "Silkscreen" => Silkscreen, "verdana" => verdana, "Vera" => FF_VERA); $fontstyles = array("Normal" => FS_NORMAL, "Bold" => FS_BOLD, "Italic" => FS_ITALIC, "Bold+Italic" => FS_BOLDITALIC); $this->apply_defaults(); if (!function_exists("imagecreatefromstring")) { handle_error("Graph Option Not Available. Requires GD2"); return; } if ($this->plot[0]["type"] == "PIE" || $this->plot[0]["type"] == "PIE3D") { $graph = new PieGraph($this->width_actual, $this->height_actual, "auto"); $graph->SetScale("textlin"); $graph->img->SetMargin($this->marginleft_actual, $this->marginright_actual, $this->margintop_actual, $this->marginbottom_actual); $graph->SetMarginColor($this->margincolor_actual); $graph->img->SetAntiAliasing(); $graph->SetColor($this->graphcolor_actual); $graph->SetShadow(); $graph->xaxis->SetTitleMargin($this->marginbottom_actual - 45); $graph->yaxis->SetTitleMargin($this->marginleft_actual - 25); } else { $graph = new Graph($this->width_actual, $this->height_actual, "auto"); $graph->SetScale("textlin"); $graph->img->SetMargin($this->marginleft_actual, $this->marginright_actual, $this->margintop_actual, $this->marginbottom_actual); $graph->SetMarginColor($this->margincolor_actual); $graph->img->SetAntiAliasing(); $graph->SetColor($this->graphcolor_actual); $graph->SetShadow(); $graph->xaxis->SetTitleMargin($this->marginbottom_actual - 45); $graph->yaxis->SetTitleMargin($this->marginleft_actual - 25); } $lplot = array(); $lplotct = 0; foreach ($this->plot as $k => $v) { switch ($v["type"]) { case "PIE": $lplot[$lplotct] = new PiePlot($v["data"]); $lplot[$lplotct]->SetColor($v["linecolor"]); foreach ($xlabels as $k => $v) { $xlabels[$k] = $v . "\n %.1f%%"; } $lplot[$lplotct]->SetLabels($xlabels, 1.0); $graph->Add($lplot[$lplotct]); break; case "PIE3D": $lplot[$lplotct] = new PiePlot3D($v["data"]); $lplot[$lplotct]->SetColor($v["linecolor"]); foreach ($xlabels as $k => $v) { $xlabels[$k] = $v . "\n %.1f%%"; } $lplot[$lplotct]->SetLabels($xlabels, 1.0); $graph->Add($lplot[$lplotct]); break; case "STACKEDBAR": case "BAR": $lplot[$lplotct] = new BarPlot($v["data"]); $lplot[$lplotct]->SetColor($v["linecolor"]); $lplot[$lplotct]->SetWidth(0.8); //$lplot[$lplotct]->SetWeight(5); if ($v["fillcolor"]) { $lplot[$lplotct]->SetFillColor($v["fillcolor"]); } if ($v["legend"]) { $lplot[$lplotct]->SetLegend($v["legend"]); } $graph->Add($lplot[$lplotct]); break; case "LINE": default: if (count($v["data"]) == 1) { $v["data"][] = 0; } $lplot[$lplotct] = new LinePlot($v["data"]); $lplot[$lplotct]->SetColor($v["linecolor"]); //$lplot[$lplotct]->SetWeight(5); if ($v["fillcolor"]) { $lplot[$lplotct]->SetFillColor($v["fillcolor"]); } if ($v["legend"]) { $lplot[$lplotct]->SetLegend($v["legend"]); } $graph->Add($lplot[$lplotct]); break; } $lplotct++; } $graph->title->Set($this->title_actual); $graph->xaxis->title->Set($this->xtitle_actual); $graph->yaxis->title->Set($this->ytitle_actual); $graph->xgrid->SetColor($this->xgridcolor_actual); $graph->ygrid->SetColor($this->ygridcolor_actual); switch ($this->xgriddisplay_actual) { case "all": $graph->xgrid->Show(true, true); break; case "major": $graph->xgrid->Show(true, false); break; case "minor": $graph->xgrid->Show(false, true); break; case "none": default: $graph->xgrid->Show(false, false); break; } switch ($this->ygriddisplay_actual) { case "all": $graph->ygrid->Show(true, true); break; case "major": $graph->ygrid->Show(true, false); break; case "minor": $graph->ygrid->Show(false, true); break; case "none": default: $graph->ygrid->Show(false, false); break; } $graph->title->SetFont($fontfamilies[$this->titlefont_actual], $fontstyles[$this->titlefontstyle_actual], $this->titlefontsize_actual); $graph->title->SetColor($this->titlecolor_actual); $graph->xaxis->SetFont($fontfamilies[$this->xaxisfont_actual], $fontstyles[$this->xaxisfontstyle_actual], $this->xaxisfontsize_actual); $graph->xaxis->SetColor($this->xaxiscolor_actual, $this->xaxisfontcolor_actual); $graph->yaxis->SetFont($fontfamilies[$this->yaxisfont_actual], $fontstyles[$this->yaxisfontstyle_actual], $this->yaxisfontsize_actual); $graph->yaxis->SetColor($this->yaxiscolor_actual, $this->yaxisfontcolor_actual); $graph->xaxis->title->SetFont($fontfamilies[$this->xtitlefont_actual], $fontstyles[$this->xtitlefontstyle_actual], $this->xtitlefontsize_actual); $graph->xaxis->title->SetColor($this->xtitlecolor_actual); $graph->yaxis->title->SetFont($fontfamilies[$this->ytitlefont_actual], $fontstyles[$this->ytitlefontstyle_actual], $this->ytitlefontsize_actual); $graph->yaxis->title->SetColor($this->ytitlecolor_actual); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetLabelMargin(5); $graph->yaxis->SetLabelMargin(5); $graph->xaxis->SetTickLabels($this->xlabels); $graph->xaxis->SetTextLabelInterval($this->xticklabelinterval_actual); $graph->yaxis->SetTextLabelInterval($this->yticklabelinterval_actual); $graph->xaxis->SetTextTickInterval($this->xtickinterval_actual); $graph->yaxis->SetTextTickInterval($this->ytickinterval_actual); $graph->SetFrame(true, 'darkblue', 2); $graph->SetFrameBevel(2, true, 'black'); if ($this->gridpos_actual == "front") { $graph->SetGridDepth(DEPTH_FRONT); } // Display the graph $handle = $graph->Stroke(_IMG_HANDLER); return $handle; }
// content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_pie.php'; require_once 'jpgraph/jpgraph_pie3d.php'; // Some data $data = array(array(80, 18, 15, 17), array(35, 28, 6, 34), array(10, 28, 10, 5), array(22, 22, 10, 17)); $piepos = array(0.2, 0.4, 0.65, 0.28, 0.25, 0.75, 0.8, 0.75); $titles = array('USA', 'Sweden', 'South America', 'Australia'); $n = count($piepos) / 2; // A new graph $graph = new PieGraph(550, 400, 'auto'); // Specify margins since we put the image in the plot area $graph->SetMargin(1, 1, 40, 1); $graph->SetMarginColor('navy'); $graph->SetShadow(false); // Setup background $graph->SetBackgroundImage('worldmap1.jpg', BGIMG_FILLPLOT); // Setup title $graph->title->Set("Pie plots with background image"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 20); $graph->title->SetColor('white'); $p = array(); // Create the plots for ($i = 0; $i < $n; ++$i) { $d = "data{$i}"; $p[] = new PiePlot3D($data[$i]); } // Position the four pies for ($i = 0; $i < $n; ++$i) { $p[$i]->SetCenter($piepos[2 * $i], $piepos[2 * $i + 1]);
public function pie_chart($piedata, $legentdata, $title) { require_once 'Examples/jpgraph/jpgraph.php'; require_once 'Examples/jpgraph/jpgraph_pie.php'; require_once 'Examples/jpgraph/jpgraph_pie3d.php'; $graph = new PieGraph(800, 450); $graph->SetShadow(); $graph->title->SetFont(FF_SIMSUN, FS_BOLD, 12); // 设置中文字体 $graph->title->Set($title . "饼状图"); $graph->SetFrame(false); $p1 = new PiePlot3D($piedata); $p1->SetSize(0.4); $p1->SetCenter(0.3); $p1->SetLegends($legentdata); $p1->SetLabelMargin(10); $graph->legend->SetFont(FF_SIMSUN, FS_NORMAL); $graph->legend->Pos(0.03, 0.18, 'right', 'top'); $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->SetColumns(2); $graph->legend->SetVColMargin(0); $graph->Add($p1); $graph->SetImgFormat('png', 90); $graph->Stroke(); }
public function generateLog($winner = false) { $gameid = strtotime('now'); $template = file_get_contents('data/log.html'); $fp = fopen(sprintf('logs/log_%d.html', $gameid), 'a'); $htplayers = array(); foreach ($this->players as $pl) { $htplayers[] = sprintf('<li>%s</li>', htmlspecialchars(parent::playerName($pl))); } $players = implode("\n", $htplayers); if ($winner) { $data = sprintf("After %d hands played, the player <strong>%s</strong> won the total pot of <strong>\$%0.2f</strong>", $this->game, parent::playerName($winner), $winner->money); } else { $htplayers = array(); foreach ($this->players as $pl) { $htplayers[] = sprintf('<li>%s ($%0.2f)</li>', htmlspecialchars(parent::playerName($pl)), $pl->money); } $htplayers = implode("\n", $htplayers); $data = sprintf("After %d hands no winner was determined a summary of each individual player's money follows:<ol>%s</ol>", $this->game, $htplayers); } $template = str_replace("{players}", $players, $template); $template = str_replace("{gameid}", $gameid, $template); $template = str_replace("{winner}", $data, $template); $template = str_replace("{version}", parent::$version, $template); $template = str_replace("{date}", date('d-m-Y h:i', $gameid), $template); $template = str_replace("{startmoney}", sprintf('%0.2f', $this->playermoney), $template); $template = str_replace("{bigblind}", sprintf('%0.2f', $this->bigblind), $template); $template = str_replace("{smallblind}", sprintf('%0.2f', $this->smallblind), $template); $template = str_replace("{maxgames}", $this->totalgames, $template); $template = str_replace("{winner}", $data, $template, $template); fputs($fp, $template); fclose($fp); require_once 'data/jpgraph.php'; require_once 'data/jpgraph_line.php'; $width = 900; $height = 300; $graph = new Graph($width, $height); $graph->img->SetMargin(40, 40, 40, 40); $graph->SetShadow(); $graph->setScale('intlin'); $graph->title->Set('Amount of money per player, per hand'); $graph->xaxis->title->Set('Hand'); $graph->yaxis->title->Set('Money'); foreach ($this->moneylog as $id => $data) { $p = $this->players[$id]; $lineplot = new LinePlot($data); $lineplot->setweight($id); $lineplot->SetLegend(parent::playerName($p)); $graph->add($lineplot); } $graph->stroke(sprintf('logs/playermoney_%d.jpg', $gameid)); // Pie graph, showing checks, folds, bets, wins, calls and raises require_once "data/jpgraph_pie.php"; // Create the Pie Graph. $height = ceil(count($this->players) / 2) * 440; $graph = new PieGraph($width, $height); $graph->SetShadow(); // Set A title for the plot $graph->title->Set("Moves per user"); // Create plots $size = 0.2; $x = array(0.25, 0.75); $y = 220; $i = 1; $legend = array("Check", "Call", "Bet", "Raise", "Fold"); foreach ($this->players as $id => $player) { $plot = new PiePlot(array($player->checks, $player->calls, $player->bets, $player->raises, $player->folds)); if ($player->id == 1) { $plot->SetLegends($legend); } $plot->SetLabelType(PIE_VALUE_ADJPERCENTAGE); $plot->SetSize($size); $plot->SetCenter($x[$i - 1], $y); if ($i == 2) { $i = 0; $y += 420; } $i++; $plot->title->Set(parent::playerName($player)); $graph->add($plot); } $graph->stroke(sprintf('logs/playermoves_%d.jpg', $gameid)); // Bargraph containing each player's wins $height = 70 * count($this->players); require_once "data/jpgraph_bar.php"; $graph = new Graph($width, $height); $graph->SetScale('textlin'); $graph->SetShadow(); $lbl = array(); $data = array(); foreach ($this->players as $pl) { $lbl[] = parent::PlayerName($pl); $data[] = $pl->wins; } $top = 60; $bottom = 30; $left = 80; $right = 30; $graph->Set90AndMargin($left, $right, $top, $bottom); $graph->xaxis->SetTickLabels($lbl); $graph->xaxis->SetLabelAlign('right', 'center', 'right'); $graph->yaxis->SetLabelAlign('center', 'bottom'); $graph->title->Set('Amount of hands won by individual players'); $bplot = new BarPlot($data); $bplot->SetFillGradient("navy", "lightsteelblue", GRAD_HOR); $bplot->SetWidth(0.5); $bplot->SetYMin(0); $graph->Add($bplot); $graph->Stroke(sprintf('logs/playerwins_%d.jpg', $gameid)); $this->newgame = false; // Remove the clients from the server $this->broadcast("[SERVER] Thank you for playing Texas Hold`em (LIMIT)\n[SERVER] If you want to play another game, just reconnect to the server!"); $this->return = true; foreach ($this->players as $player) { $this->disconnect($player); } $this->return = true; $this->restore(); }
private function createCookieGraph($xdata, $ytitle) { // Create the graph. $graph = new PieGraph($this->width, $this->height, "auto"); $graph->title->SetFont(FF_FONT1, FS_NORMAL, 10); $graph->SetFrame(false); if ($this->shadow) { $graph->SetShadow(); } $p1 = new PiePlot($xdata); // second group negative $p1->SetLegends($this->ydata1); $p1->SetCenter(0.3); $p1->SetTheme("earth"); //color for negative prologiq "#cc00cc" $p1->value->SetFont(FF_FONT1, FS_NORMAL, 10); $graph->title->Set($ytitle); // ... and add it to the graph $graph->Add($p1); return $graph; }
function crearPie($pdf, $verde, $rojo, $ciclos, $alineacion) { $data = array($verde, $rojo); $labels = array("Valores\ndentro de\nnorma\n(%.1f%%)", "Valores\nfuera de\nnorma\n(%.1f%%)"); $graph = new PieGraph(310, 200); $graph->SetShadow(); $graph->title->Set(utf8_decode("Análisis de resultados " . $ciclos)); $graph->title->SetFont(FF_FONT1, FS_BOLD); $p1 = new PiePlot3D($data); $p1->SetSize(0.5); $p1->SetCenter(0.5); $p1->ExplodeAll(15); $p1->SetStartAngle(60); $p1->SetLabels($labels); $p1->SetLabelPos(0); $p1->value->SetColor('black'); $graph->Add($p1); $p1->SetSliceColors(array('green', 'red')); //$graph->Stroke(); $nombreImagen = '' . uniqid() . '.png'; // Display the graph $graph->Stroke($nombreImagen); if ($alineacion === 'C') { $pdf->Image($nombreImagen, 145, 145, 55, 45); } elseif ($alineacion === 'L') { $pdf->Image($nombreImagen, 90, 145, 55, 45); } elseif ($alineacion === 'R') { $pdf->Image($nombreImagen, 195, 145, 55, 45); } elseif ($alineacion === 'C1') { $pdf->Image($nombreImagen, 75, 205, 55, 45); } elseif ($alineacion === 'L1') { $pdf->Image($nombreImagen, 20, 205, 55, 45); } elseif ($alineacion === 'R1') { $pdf->Image($nombreImagen, 125, 205, 55, 45); } elseif ($alineacion === 'C2') { $pdf->Image($nombreImagen, 75, 160, 55, 45); } unlink($nombreImagen); }
function generateGraphplotrev($type) { if ($type == "year") { $start = date("Y-"); $start .= "01-01 00-00-00"; $end = date("Y-"); $end .= "12-31 23-59-59"; } elseif ($type == "month") { $start = date("Y-m-"); $start .= "01 00-00-00"; $end = date("Y-m-"); $end .= "31 23-59-59"; } elseif ($type == "day") { $start = date("Y-m-d"); $start .= " 00-00-00"; $end = date("Y-m-d"); $end .= " 23-59-59"; } elseif ($type == "week") { $date = date("Y-m-d"); } if ($type == "week") { $sql = "SELECT `id` FROM `sales` WHERE week(`created_at`) = week('{$date}') AND `deleted` = '0' "; } else { $sql = "SELECT `id` FROM `sales` WHERE (`created_at` BETWEEN '{$start}' AND '{$end}') AND `deleted` = '0'"; } $sql = DB::select(DB::raw($sql)); foreach ($sql as $row) { $sales_id[] = $row->id; } if (!isset($sales_id)) { $sales_id[] = 0; $sales_id[] = 0; } $ids = join(',', $sales_id); // user groups $sql = "SELECT COUNT(sales_product.id) AS 'Count', item.name AS 'Name' FROM sales_product INNER JOIN item ON item.id = sales_product.product WHERE sales_product.sale_id IN ({$ids}) GROUP BY sales_product.product ORDER BY `Count` DESC"; $sql = DB::select(DB::raw($sql)); foreach ($sql as $row) { $inq[] = $row->Count; $leg[] = $row->Name; } if (!isset($inq)) { $inq[] = 1; $leg[] = "null"; } if (sizeof($inq) > 5) { $c = sizeof($inq) - 1; $other = 0; for ($x = 4; $x <= $c; $x++) { $other = $other + $inq[$x]; unset($inq[$x]); unset($leg[$x]); } $inq[4] = $other; $leg[4] = "other"; } // Some data $data = $inq; // Create the Pie Graph. $graph = new \PieGraph(350, 250); $graph->SetShadow(); $legends = $leg; // $graph->legend->Pos(0.3, 0.85); $theme_class = "DefaultTheme"; // Set A title for the plot $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph->SetBox(true); // Create $p1 = new \PiePlot3d($data); $graph->Add($p1); $p1->ShowBorder(); $p1->SetColor('black'); $p1->SetSliceColors(array('#ADFF2F', '#DC143C', '#9966FF', '#EBB000', '#6EDBFF')); $p1->SetLegends($legends); $p1->ExplodeSlice(2); $p1->SetAngle(30); $p1->SetSize(0.5); $p1->SetCenter(0.5, 0.4); // $graph->legend->SetColumns(3); $graph->legend->SetFrameWeight(1); $graph->legend->SetColumns(3); $gdImgHandler = $graph->Stroke(_IMG_HANDLER); $fileName = "assets/tmp/" . $type . "_pie_rev.png"; $graph->img->Stream($fileName); }
public function generarReportePastel() { $this->load->model('nivel_model'); $alumPorNivel = $this->nivel_model->alumnosPorNivel(); require_once APPPATH . "libraries/jpgraph/jpgraph.php"; require_once APPPATH . "libraries/jpgraph/jpgraph_pie.php"; require_once APPPATH . "libraries/jpgraph/jpgraph_pie3d.php"; // Pasando el nombre de los niveles a un arreglo llamado dato $i = 0; foreach ($alumPorNivel->result() as $a) { $dato[$i] = $a->nombre; $cuenta[] = $a->total; $exp[$i] = 5; $i++; } // Creando el Grafico de Pastel $graph = new PieGraph(550, 400); $graph->SetShadow(); // Estableciendo el titulo $graph->title->Set("Porcentaje de Alumnos por Nivel"); $graph->title->SetFont(FF_VERDANA, FS_BOLD, 18); $graph->title->SetColor("darkblue"); $graph->legend->Pos(0.3, 0.06); // Crear 3D pie plot $p1 = new PiePlot3d($cuenta); $p1->SetTheme("sand"); $p1->SetCenter(0.5); $p1->SetSize(0.5); $p1->SetHeight(20); #Ancho del pastel // Angulo de inclinación $p1->SetAngle(45); // Distancia entre las partes del pastel $p1->Explode($exp); $p1->value->SetFont(FF_ARIAL, FS_NORMAL, 10); $p1->SetLegends($dato); $graph->Add($p1); $gdImgHandler = $graph->Stroke(_IMG_HANDLER); // Guardando imagen como archivo por default es .png $fileName = "assets/img/reportes/reporte.jpg"; $graph->img->Stream($fileName); redirect(base_url('Alumnos/verReportePastel')); }
/** * Método que sirve de reemplazo al mecanismo de paloSantoGraph y paloSantoGraphLib * para generar gráficos a partir de una clase que devuelve datos. * * @param string $module Módulo que contiene la clase fuente de datos * @param string $class Clase a instanciar para obtener fuente de datos * @param string $function Método a llamar en la clase para obtener datos * @param array $arrParameters Lista de parámetros para la invocación * @param string $functionCB */ function displayGraph($G_MODULE, $G_CLASS, $G_FUNCTION, $G_PARAMETERS, $G_FUNCTIONCB = "") { //------- PARAMETROS DEL GRAPH ------- $G_TYPE = null; //tipo de grafica $G_TITLE = null; //titulo $G_COLOR = null; //colores $G_LABEL = array(); //etiquetas $G_SIZE = array(); //tamaño $G_MARGIN = array(); //margen $G_LEYEND_NUM_COLUMN = 1; $G_LEYEND_POS = array(0.05, 0.5); //posicion de las leyendas $_MSJ_ERROR = null; //$_MSJ_ERROR = "Sin mensaje ERROR"; global $_MSJ_NOTHING; //$_MSJ_NOTHING = "Sin mensaje NOTHING"; $G_YDATAS = array(); $G_ARR_COLOR = array(); $G_ARR_FILL_COLOR = array(); $G_ARR_LEYEND = array(); $G_ARR_STEP = array(); $G_SHADOW = false; $G_LABEL_Y = null; //ESTATICOS $G_SCALE = "textlin"; $G_WEIGHT = 1; if ($G_MODULE != '') { require_once "modules/{$G_MODULE}/libs/{$G_CLASS}.class.php"; //lib del modulo require_once "modules/{$G_MODULE}/configs/default.conf.php"; //archivo configuracion del modulo global $arrConfModule; $dsn = isset($arrConfModule["dsn_conn_database"]) ? $arrConfModule["dsn_conn_database"] : ""; } else { require_once "libs/{$G_CLASS}.class.php"; //lib del modulo require_once "configs/default.conf.php"; //archivo configuracion del modulo global $arrConf; $dsn = isset($arrConf["dsn_conn_database"]) ? $arrConf["dsn_conn_database"] : ""; } $oPaloClass = new $G_CLASS($dsn); $arrParam = $G_PARAMETERS; $result = call_user_func_array(array(&$oPaloClass, $G_FUNCTION), $arrParam); global $globalCB; $globalCB = NULL; if ($G_FUNCTIONCB != '') { $globalCB = array($oPaloClass, $G_FUNCTIONCB); } //------------------- CONTRUCCION DEL ARREGLO PARA X & Y ------------------- global $xData; $xData = array(); $yData = array(); if (sizeof($result) != 0) { $isX_array = false; //usado en LINEPLOT, PLOT3D, BARPLOT, LINEPLOT_MULTIAXIS foreach ($result as $att => $arrXY) { //------------------ ATTRIBUTES ------------------ if ($att == 'ATTRIBUTES') { foreach ($arrXY as $key => $values) { //VARIABLES NECESARIAS if ($key == 'LABEL_X') { $G_LABEL[0] = $values; } else { if ($key == 'LABEL_Y') { $G_LABEL[1] = $values; } else { if ($key == 'TITLE') { $G_TITLE = $values; } else { if ($key == 'TYPE') { $G_TYPE = $values; } else { if ($key == 'SIZE') { $G_SIZE = explode(',', $values); } else { if ($key == 'MARGIN') { $G_MARGIN = explode(',', $values); } else { if ($key == 'COLOR') { $G_COLOR = $values; } else { if ($key == 'POS_LEYEND') { $G_LEYEND_POS = explode(',', $values); } else { if ($key == 'NUM_COL_LEYEND') { $G_LEYEND_NUM_COLUMN = $values; } else { if ($key == 'SHADOW') { $G_SHADOW = $values; } } } } } } } } } } } } else { if ($att == 'MESSAGES') { foreach ($arrXY as $key => $values) { if ($key == 'ERROR') { $_MSJ_ERROR = $values; } else { if ($key == 'NOTHING_SHOW') { $_MSJ_NOTHING = $values; } } } } else { if ($att == 'DATA') { foreach ($arrXY as $DAT_N => $MODES) { foreach ($MODES as $key => $values) { /************************************************************/ if ($G_TYPE == 'lineplot' || $G_TYPE == 'barplot' || $G_TYPE == 'lineplot_multiaxis') { if ($key == 'VALUES') { $yData = array(); foreach ($values as $x => $y) { if ($isX_array == false) { $xData[] = $x; } $yData[] = $y; } $isX_array = is_array($xData) ? true : false; $G_YDATAS[] = $yData; } else { if ($key == 'STYLE') { foreach ($values as $x => $y) { if ($x == 'COLOR') { $G_ARR_COLOR[] = $y; } else { if ($x == 'LEYEND') { $G_ARR_LEYEND[] = $y; } else { if ($x == 'STYLE_STEP') { $G_ARR_STEP[] = $y; } else { if ($x == 'FILL_COLOR') { $G_ARR_FILL_COLOR[] = $y; } } } } } } } } else { if ($G_TYPE == 'plot3d' || $G_TYPE == 'plot3d2') { if ($key == 'VALUES') { foreach ($values as $x => $y) { $yData[] = $y; } $G_YDATAS[0] = $yData; } else { if ($key == 'STYLE') { foreach ($values as $x => $y) { if ($x == 'COLOR') { $G_ARR_COLOR[] = $y; } else { if ($x == 'LEYEND') { $xData[] = $y; } } } } } } else { if ($G_TYPE == 'bar' || $G_TYPE == 'gauge') { if ($key == 'VALUES') { foreach ($values as $x => $y) { $G_YDATAS[] = $y; } } } } } } } } } } } } //*****************************************// // ***** ***** ***** ***** * * // // * * * * * * * * * // // * *** ***** ***** ***** ***** // // * * * * * * * * * // // ***** * * * * * * * // //*****************************************// // L I N E P L O T if (sizeof($G_YDATAS) >= 1) { // true no funciona porque cada cadena u otro valor que se retorne es valor "valido o verdadero" // y equivale a true, entonces para diferenciarlo verdaderamente se compara con 'true' $str = checkAttributes($G_TITLE, $G_TYPE, $G_LABEL_Y, $_MSJ_ERROR, $_MSJ_NOTHING); if ($str != 'true') { showError($str, $G_SIZE); return; } if ($G_TYPE == 'lineplot') { $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto"); if ($G_SHADOW) { $graph->SetShadow(); } $graph->SetScale($G_SCALE); $graph->SetMarginColor($G_COLOR); $graph->title->Set($G_TITLE); $graph->SetFrame(true, '#999999'); $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]); $graph->img->SetAntiAliasing(); $graph->xaxis->SetLabelFormatCallback("CallBack"); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->title->Set($G_LABEL[0]); $graph->yaxis->title->Set($G_LABEL[1]); $graph->xgrid->Show(); $graph->legend->SetFillColor("#fafafa"); $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center"); $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN); $graph->legend->SetColor("#444444", "#999999"); $arr_lineplot = array(); foreach ($G_YDATAS as $num => $yDatas) { $lineplot = new LinePlot($yDatas); if ($G_ARR_STEP[$num] == true) { $lineplot->SetStepStyle(); } if ($G_ARR_FILL_COLOR[$num] == true) { $lineplot->SetFillColor($G_ARR_COLOR[$num]); } $lineplot->SetColor($G_ARR_COLOR[$num]); $lineplot->SetWeight($G_WEIGHT); $lineplot->SetLegend($G_ARR_LEYEND[$num]); $arr_lineplot[] = $lineplot; } foreach ($arr_lineplot as $num => $yDatas) { $graph->Add($yDatas); } if (sizeof($xData) > 100) { $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10)); } $graph->Stroke(); } else { if ($G_TYPE == 'plot3d') { $graph = new PieGraph($G_SIZE[0], $G_SIZE[1], "auto"); if ($G_SHADOW) { $graph->SetShadow(); } $dataMarginColor = isset($result["ATTRIBUTES"]["MARGIN_COLOR"]) ? $result["ATTRIBUTES"]["MARGIN_COLOR"] : "#999999"; $dataSizePie = isset($result["ATTRIBUTES"]["SIZE_PIE"]) ? $result["ATTRIBUTES"]["SIZE_PIE"] : "80"; $graph->SetMarginColor($G_COLOR); $graph->SetFrame(true, $dataMarginColor); $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center"); $graph->legend->SetFillColor("#fafafa"); $graph->legend->SetColor("#444444", "#999999"); $graph->legend->SetShadow('gray@0.6', 4); $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN); $graph->title->Set($G_TITLE); $pieplot3d = new PiePlot3d($G_YDATAS[0]); $pieplot3d->SetSliceColors($G_ARR_COLOR); $pieplot3d->SetCenter(0.4); $pieplot3d->SetSize($dataSizePie); $pieplot3d->SetAngle(45); $pieplot3d->SetStartAngle(45); $pieplot3d->value->SetColor('black'); //color a los porcentages $pieplot3d->SetEdge('black'); //da color al contorno y separacion del pastel $pieplot3d->SetLegends($xData); $graph->Add($pieplot3d); $graph->Stroke(); } else { if ($G_TYPE == 'plot3d2') { if (!function_exists('displayGraph_draw_pie3d')) { function displayGraph_draw_pie3d($canvasx, $ydata, $arrcolor) { $canvasy = $canvasx; $escala = $canvasx / 320.0; $iAnchoPastel = 256 * $escala; $iAltoPastel = 155 * $escala; $iPosCentroX = 141 * $escala; $iPosCentroY = 91 * $escala; $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasy * 250 / 320); $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127); imagefill($thumb, 0, 0, $transparent); // Asignar colores de imagen $imgcolor = array(); foreach ($arrcolor as $i => $sHtmlColor) { $r = $g = $b = 0; sscanf($sHtmlColor, "#%02x%02x%02x", $r, $g, $b); $imgcolor[$i] = imagecolorallocate($thumb, $r, $g, $b); } $colorTexto = imagecolorallocate($thumb, 0, 0, 0); // Mostrar el gráfico de pastel if (!function_exists('displayGraph_pie')) { function displayGraph_pie($thumb, $x, $y, $w, $h, $ydata, $G_ARR_COLOR, $colorTexto) { $iTotal = array_sum($ydata); $iFraccion = 0; $etiquetas = array(); for ($i = 0; $i < count($ydata); $i++) { if ($ydata[$i] >= $iTotal) { imagefilledellipse($thumb, $x, $y, $w, $h, $G_ARR_COLOR[$i]); } else { $degInicio = 360 - 45 - (int) (360.0 * ($iFraccion + $ydata[$i]) / $iTotal); $degFinal = 360 - 45 - (int) (360.0 * $iFraccion / $iTotal); imagefilledarc($thumb, $x, $y, $w, $h, $degInicio, $degFinal, $G_ARR_COLOR[$i], IMG_ARC_PIE); } $iFraccion += $ydata[$i]; $degMitad = ($degInicio + $degFinal) / 2; $iPosTextoX = $x + 0.5 * ($w / 2.0) * cos(deg2rad($degMitad)); $iPosTextoY = $y + 0.5 * ($h / 2.0) * sin(deg2rad($degMitad)); $etiquetas[] = array($iPosTextoX, $iPosTextoY, sprintf('%.1f %%', 100.0 * $ydata[$i] / $iTotal)); } /* if (!is_null($colorTexto)) { for ($i = 0; $i < count($ydata); $i++) imagestring($thumb, 5, $etiquetas[$i][0], $etiquetas[$i][1], $etiquetas[$i][2], $colorTexto); } */ } } for ($i = (int) (60 * $escala); $i > 0; $i--) { displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY + $i, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, NULL); } displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, $colorTexto); imagealphablending($thumb, true); imagesavealpha($thumb, true); $source2 = imagecreatefrompng("images/pie_alpha.png"); imagealphablending($source2, true); imagecopyresampled($thumb, $source2, 0, 0, 0, 0, 290 * $escala, 294 * $escala, 290, 294); header("Content-Type: image/png"); imagepng($thumb); } } displayGraph_draw_pie3d($G_SIZE[0], $G_YDATAS[0], $G_ARR_COLOR); } else { if ($G_TYPE == 'barplot') { $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto"); if ($G_SHADOW) { $graph->SetShadow(); } $graph->SetScale($G_SCALE); $graph->SetMarginColor($G_COLOR); $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]); $graph->title->Set($G_TITLE); $graph->xaxis->title->Set($G_LABEL[0]); $graph->xaxis->SetLabelFormatCallback("CallBack"); $graph->xaxis->SetLabelAngle(90); //$graph->xaxis->SetTickLabels($xData); $graph->yaxis->title->Set($G_LABEL[1]); $graph->legend->SetFillColor("#fafafa"); $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center"); $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN); $arr_barplot = array(); foreach ($G_YDATAS as $num => $yDatas) { $barplot = new BarPlot($yDatas); $barplot->SetFillColor($G_ARR_COLOR[$num]); $barplot->SetLegend($G_ARR_LEYEND[$num]); $arr_barplot[] = $barplot; } $gbarplot = new GroupBarPlot($arr_barplot); $gbarplot->SetWidth(0.6); $graph->Add($gbarplot); $graph->Stroke(); } else { if ($G_TYPE == 'lineplot_multiaxis') { $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto"); if ($G_SHADOW) { $graph->SetShadow(); } $inc = sizeof($G_YDATAS); $graph->SetScale($G_SCALE); $graph->SetFrame(true, '#999999'); $graph->title->Set($G_TITLE); $graph->img->SetAntiAliasing(); $graph->xaxis->SetLabelFormatCallback("CallBack"); $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]); $graph->SetMarginColor($G_COLOR); $graph->legend->SetFillColor("#fafafa"); $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center"); $graph->xaxis->SetLabelAngle(90); $graph->legend->SetColor("#444444", "#999999"); $graph->legend->SetShadow('gray@0.6', 4); $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN); foreach ($G_YDATAS as $num => $yData) { $lineplot = new LinePlot($yData); $lineplot->SetWeight($G_WEIGHT); $lineplot->SetLegend($G_ARR_LEYEND[$num]); if ($G_ARR_STEP[$num] == true) { $lineplot->SetStepStyle(); } if ($G_ARR_FILL_COLOR[$num] == true) { $lineplot->SetFillColor($G_ARR_COLOR[$num]); } if ($num == 0) { $lineplot->SetColor($G_ARR_COLOR[$num]); $graph->yaxis->SetColor($G_ARR_COLOR[$num]); $graph->Add($lineplot); } else { $lineplot->SetColor($G_ARR_COLOR[$num]); $graph->SetYScale($num - 1, 'lin'); $graph->ynaxis[$num - 1]->SetColor($G_ARR_COLOR[$num]); $graph->ynaxis[$num - 1]->SetPosAbsDelta($G_MARGIN[1] + 49 * ($num - 1)); //mueve el eje Y $graph->AddY($num - 1, $lineplot); } } if (sizeof($xData) > 100) { //$graph->xaxis->SetTextLabelInterval( (int)(sizeof($xData)/8) ); $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10)); //$graph->xaxis->SetTextTickInterval( 9*(int)(log(sizeof($xData))-1) ); } $graph->Stroke(); } else { if ($G_TYPE == 'bar') { $g = new CanvasGraph(91, 21, 'auto'); $g->SetMargin(0, 0, 0, 0); $g->InitFrame(); $xmax = 20; $ymax = 20; $scale = new CanvasScale($g); $scale->Set(0, $G_SIZE[0], 0, $G_SIZE[1]); //DUBUJA LA BARRA $alto = $G_SIZE[1]; $ancho = $G_SIZE[0]; $coor_x = 0; $coor_y = 0; $porcentage = $G_YDATAS[0]; $valor = 90 * (1 - $porcentage); $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y); $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto); $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto); $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto); for ($i = 0; $i < $alto; $i++) { $g->img->SetColor(array(95 - 3 * $i, 138 - 3 * $i, 203 - 3 * $i)); //para hacerlo 3D, degradacion $g->img->Line($coor_x, $coor_y + $i + 1, $coor_x + $ancho - $valor - 1, $coor_y + $i + 1); } $g->Stroke(); } else { if ($G_TYPE == 'gauge') { if (!function_exists('displayGraph_draw_gauge')) { function displayGraph_draw_gauge($canvasx, $percent) { $escala = $canvasx / 320.0; $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasx * 284 / 320); if ($percent > 100) { $percent = 100.0; } if ($percent < 0) { $percent = 0.0; } $angle = -135.0 + 270 * $percent / 100.0; // COLORES $blanco = imagecolorallocate($thumb, 255, 255, 255); $dred = imagecolorallocate($thumb, 180, 0, 0); $lred = imagecolorallocate($thumb, 100, 0, 0); $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127); imagefill($thumb, 0, 0, $transparent); imagealphablending($thumb, true); imagesavealpha($thumb, true); $source = imagecreatefrompng("images/gauge_base.png"); imagealphablending($source, true); imagecopyresampled($thumb, $source, 0, 0, 0, 0, 285 * $escala, 285 * $escala, 285, 285); $radius = 100 * $escala; $radius_min = 12 * $escala; $centrox = 142 * $escala; $centroy = 141 * $escala; $x1 = $centrox + sin(deg2rad($angle)) * $radius; // x coord farest $x2 = $centrox + sin(deg2rad($angle - 90)) * $radius_min; $x3 = $centrox + sin(deg2rad($angle + 90)) * $radius_min; $y1 = $centroy - cos(deg2rad($angle)) * $radius; $y2 = $centroy - cos(deg2rad($angle - 90)) * $radius_min; $y3 = $centroy - cos(deg2rad($angle + 90)) * $radius_min; $arrTriangle1 = array($centrox, $centroy, $x1, $y1, $x2, $y2); $arrTriangle2 = array($centrox, $centroy, $x1, $y1, $x3, $y3); imagefilledpolygon($thumb, $arrTriangle1, 3, $lred); imagefilledpolygon($thumb, $arrTriangle2, 3, $dred); $source2 = imagecreatefrompng("images/gauge_center.png"); imagealphablending($source2, true); imagecopyresampled($thumb, $source2, 121 * $escala, 120 * $escala, 0, 0, 44 * $escala, 44 * $escala, 44, 44); header("Content-Type: image/png"); imagepng($thumb); } } displayGraph_draw_gauge($G_SIZE[0], $G_YDATAS[0] * 100.0); } else { if ($G_TYPE == 'bar2') { $alto = 20; $ancho = 90; $coor_x = 100; $coor_y = 10; $porcentage = 0.67; $valor = 90 * (1 - $porcentage); $g = new CanvasGraph($G_LEN_X, 40, 'auto'); $g->SetMargin(1, 1, 31, 9); $g->SetMarginColor('#fafafa'); $g->SetColor(array(250, 250, 250)); $g->InitFrame(); $xmax = 20; $ymax = 20; $scale = new CanvasScale($g); $scale->Set(0, $G_LEN_X, 0, $G_LEN_Y); //DUBUJA LA BARRA $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y); $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto); $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto); $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto); for ($i = 0; $i < $alto; $i++) { $g->img->SetColor(array(95 - 4 * $i, 138 - 4 * $i, 203 - 4 * $i)); //para hacerlo 3D, degradacion $g->img->Line($coor_x, $coor_y + $i, $coor_x + $ancho - $valor - 1, $coor_y + $i); } //AGREGA LABEL 1 $txt = "Uso de CPU"; $t = new Text($txt, 10, 12); $t->font_style = FS_BOLD; $t->Stroke($g->img); //AGREGA LABEL 2 $txt = "67.64% used of 2,200.00 MHz"; $t = new Text($txt, 200, 12); $t->font_style = FS_BOLD; $t->Stroke($g->img); $g->Stroke(); } } } } } } } } } else { showError('nothing', $G_SIZE, $G_TITLE); } }
function generategraph($report_id, $result_report) { //to generate the chart $this->load->plugin('jpgraph'); $graph = loadgraph($report_id); switch ($report_id) { case 0: break; case 1: $data = array(); $factorarray = array(); $i = 1; foreach ($result_report->result_array() as $row) { $data[] = $row['deficient_count']; $factorarray[] = $i; $i = $i + 1; } $graph = new PieGraph(520, 320); $graph->SetShadow(); $graph->title->Set("Factor Deficiency Graph"); $p1 = new PiePlot3D($data); $graph->Add($p1); $p1->ExplodeAll(10); $p1->SetAngle(70); $p1->SetLegends($factorarray); $graph_temp_directory = $this->config->item('absolute_path') . 'graphimage'; $graph_file_name = $this->session->userdata('chapter') . '_deficientgraph.png'; $graph_file_location = $graph_temp_directory . '/' . $graph_file_name; if (file_exists($graph_file_location)) { unlink($graph_file_location); } $graph->Stroke($graph_file_location); $returnvalue = $this->config->item('base_url') . 'graphimage/' . $this->session->userdata('chapter') . '_deficientgraph.png'; break; case 2: $data = array(1, 2, 3); $defarray = array(); $i = 1; $row = $result_report->result_array(); $defarray[] = $row[0]['severe']; $defarray[] = $row[0]['modrate']; $defarray[] = $row[0]['mild']; $graph = new PieGraph(520, 320); $graph->SetShadow(); $graph->title->Set("Severity Graph"); $p1 = new PiePlot3D($defarray); $graph->Add($p1); $p1->ExplodeAll(10); $p1->SetAngle(70); $p1->SetLegends($data); $graph_temp_directory = $this->config->item('absolute_path') . 'graphimage'; $graph_file_name = $this->session->userdata('chapter') . '_severitygraph.png'; $graph_file_location = $graph_temp_directory . '/' . $graph_file_name; if (file_exists($graph_file_location)) { unlink($graph_file_location); } $graph->Stroke($graph_file_location); $returnvalue = $this->config->item('base_url') . 'graphimage/' . $this->session->userdata('chapter') . '_severitygraph.png'; break; } return $returnvalue; }
public static function main($argv) { list($type, $id, $cmp_id) = $argv; // General. $o = null; $opts = array('xdim' => SG_DIM_X, 'ydim' => SG_DIM_Y, 'retObj' => true); // Options to pass to mbars(). $count_horiz = SG_CNT_HORIZ; // Number og graphs to place in each horizontal multi graph "row". $graphs = array(); if ($type == SG_T_TEAM) { $o = new Team($_GET['id']); $where = "f_team_id = {$o->team_id}"; } elseif ($type == SG_T_COACH) { $o = new Coach($_GET['id']); $where = "f_coach_id = {$o->coach_id}"; } elseif ($type == SG_T_PLAYER) { $o = new Player($_GET['id']); $where = "f_player_id = {$o->player_id}"; } if ($type != SG_T_LEAGUE && !is_object($o)) { return false; } // Make graphs components for multi graph plot. if ($type == SG_T_LEAGUE) { /* Played matches. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, 1, 0)) AS 'Games_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Games' => 'royalblue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Games played", "Months", "Games", $opts)); /* Active teams */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; array_push($queries, "(SELECT COUNT(DISTINCT(tid)) FROM\n (\n SELECT team1_id AS 'tid', date_played FROM matches WHERE {$range}\n UNION\n SELECT team2_id AS 'tid', date_played FROM matches WHERE {$range}\n ) AS tmptbl) AS 'Active teams_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'\n"); } $query = "SELECT " . implode(', ', $queries); $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Active teams' => 'olivedrab'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Active teams", "Months", "Teams", $opts)); /* Active coaches */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; array_push($queries, "(SELECT COUNT(DISTINCT(cid)) FROM\n (\n SELECT owned_by_coach_id AS 'cid', date_played FROM matches, teams WHERE team1_id = team_id AND {$range}\n UNION\n SELECT owned_by_coach_id AS 'cid', date_played FROM matches, teams WHERE team2_id = team_id AND {$range}\n ) AS tmptbl) AS 'Active coaches_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'\n"); } $query = "SELECT " . implode(', ', $queries); $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Active coaches' => 'darkorange1'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Active coaches", "Months", "Coaches", $opts)); /* Played matches. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH_DAYS) as $i) { # Hack (for display purposes) set month -> year, day -> month $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)))\n AND\n (DAY(date_played) = DAY(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, 1, 0)) AS 'Games_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)) AS 'yr_m{$i}'"); array_push($queries, "DAY(SUBDATE(DATE(NOW()), INTERVAL {$i} DAY)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Games' => 'royalblue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row, SG_MULTIBAR_HIST_LENGTH_DAYS); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Games played", "Days", "Games", $opts)); /* td & cp. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, cp, 0)) AS 'CP_m{$i}'"); array_push($queries, "SUM(IF({$range}, td, 0)) AS 'TD_m{$i}'"); # array_push($queries, "SUM(IF($range, intcpt, 0)) AS 'int_m$i'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('CP' => 'seagreen', 'TD' => 'indianred'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "CP & TD history", "Months", "Amount", $opts)); /* CAS. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, bh+si+ki, 0)) AS 'CAS_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('CAS' => 'firebrick1'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "CAS history", "Months", "Amount", $opts)); /* SMP. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "SUM(IF($range, smp1+smp2, 0)) AS 'smp_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('smp' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Total given sportsmanship points (smp)", "Months", "Points", $opts)); /* Avg. gate per match. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, gate/1000, NULL)) AS 'avg_gate_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_gate' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Average gate per match (kilo)", "Months", "Gate", array_merge($opts, array('scale' => 'textlin')))); /* average absolute score diff. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, ABS(CONVERT(team1_score,SIGNED) - CONVERT(team2_score,SIGNED)), NULL)) AS 'avg_abs_diff_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_abs_diff' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Average absolute score difference history", "Months", "Avg. abs. score diff.", array_merge($opts, array('scale' => 'textlin')))); /* Average deta treasury */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, ((income1+income2)/2)/1000, NULL)) AS 'avg_dtreasury_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_dtreasury' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Avg. change in team's treasury per match (kilo)", "Months", "Average change", array_merge($opts, array('scale' => 'textlin')))); /* Average fans at match. */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, fans, NULL)) AS 'fans_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('fans' => 'blue'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Average fans per match", "Months", "Average fans", array_merge($opts, array('scale' => 'textlin')))); /* Average stars and mercs hirings per match */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "AVG(IF($range, stars, NULL)) AS 'avg_stars_m$i'"); # array_push($queries, "AVG(IF($range, mercs, NULL)) AS 'avg_mercs_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $tableMercs = "( # SELECT f_match_id, SUM(IF(f_player_id = ".ID_MERCS.", 1, 0)) AS mercs FROM match_data GROUP BY f_match_id # ) AS mercsTbl"; # $tableStars = "( # SELECT f_match_id, SUM(IF(f_player_id <= ".ID_STARS_BEGIN.", 1, 0)) AS stars FROM match_data GROUP BY f_match_id # ) AS starsTbl"; # $query = "SELECT ".implode(', ', $queries)." FROM matches, $tableMercs, $tableStars WHERE mercsTbl.f_match_id = matches.match_id AND starsTbl.f_match_id = matches.match_id"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('avg_stars' => 'red', 'avg_mercs' => 'green'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Avg. stars and mercs per match", "Months", "Average hirings", array_merge($opts, array('scale' => 'textlin')))); /* Injuries */ # $queries = array(); # foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { # $range = "( # (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # AND # (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH))) # )"; # # m$i = minus/negative $i months from present month. # array_push($queries, "SUM(IF($range, IF(inj = ".MNG.", 1, 0)+IF(agn1 = ".MNG.", 1, 0)+IF(agn2 = ".MNG.", 1, 0), 0)) AS 'mng_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".NI.", 1, 0)+IF(agn1 = ".NI.", 1, 0)+IF(agn2 = ".NI.", 1, 0), 0)) AS 'ni_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".MA.", 1, 0)+IF(agn1 = ".MA.", 1, 0)+IF(agn2 = ".MA.", 1, 0), 0)) AS 'ma_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".AV.", 1, 0)+IF(agn1 = ".AV.", 1, 0)+IF(agn2 = ".AV.", 1, 0), 0)) AS 'av_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".AG.", 1, 0)+IF(agn1 = ".AG.", 1, 0)+IF(agn2 = ".AG.", 1, 0), 0)) AS 'ag_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".ST.", 1, 0)+IF(agn1 = ".ST.", 1, 0)+IF(agn2 = ".ST.", 1, 0), 0)) AS 'st_m$i'"); # array_push($queries, "SUM(IF($range, IF(inj = ".DEAD.", 1, 0)+IF(agn1 = ".DEAD.", 1, 0)+IF(agn2 = ".DEAD.", 1, 0), 0)) AS 'dead_m$i'"); # array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'yr_m$i'"); # array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL $i MONTH)) AS 'mn_m$i'"); # } # $query = "SELECT ".implode(', ', $queries)." FROM matches, match_data WHERE f_match_id = match_id"; # $result = mysql_query($query); # $row = mysql_fetch_assoc($result); # # $lengends = array('mng' => 'green', 'ni' => 'red', 'ma' => 'blue', 'av' => 'aqua', 'ag' => 'brown', 'st' => 'purple', 'dead' => 'slategray'); # list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); # array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Types of sustained player injuries/statuses", "Months", "Amount", $opts)); /* Race distribution */ # global $raceididx; # $query = "SELECT DISTINCT(f_race_id) AS 'race', COUNT(f_race_id) 'cnt' FROM teams GROUP BY f_race_id"; # $result = mysql_query($query); # $data = array(); # while ($row = mysql_fetch_assoc($result)) { # $data[$raceididx[$row['race']]." ($row[cnt])"] = $row['cnt']; # } # $graph = new PieGraph($opts['xdim'],$opts['ydim'],"auto"); # $graph->SetShadow(); # $graph->title->Set('Current race distribution'); # $graph->title->SetFont(FF_FONT1,FS_BOLD); # $p1 = new PiePlot(array_values($data)); # $p1->SetLegends(array_keys($data)); # $p1->SetCenter(0.4); # $graph->Add($p1); # array_push($graphs, $graph); /* CAS distribution */ # $query = "SELECT SUM(bh) AS 'bh', SUM(si) AS 'si', SUM(ki) AS 'ki' FROM match_data"; # $result = mysql_query($query); # $o = (object) mysql_fetch_assoc($result); # $data = array("BH ($o->bh)" => $o->bh, "SI ($o->si)" => $o->si, "Ki ($o->ki)" => $o->ki); # $graph = new PieGraph($opts['xdim'],$opts['ydim'],"auto"); # $graph->SetShadow(); # $graph->title->Set('Current CAS distribution'); # $graph->title->SetFont(FF_FONT1,FS_BOLD); # $p1 = new PiePlot(array_values($data)); # $p1->SetLegends(array_keys($data)); # $p1->SetCenter(0.4); # $graph->Add($p1); # array_push($graphs, $graph); } else { /******************** * Current CAS ********************/ if (!$cmp_id && $o->mv_cas != 0) { $data = array("BH ({$o->mv_bh})" => $o->mv_bh, "SI ({$o->mv_si})" => $o->mv_si, "Ki ({$o->mv_ki})" => $o->mv_ki); $graph = new PieGraph($opts['xdim'], $opts['ydim'], "auto"); $graph->SetShadow(); $graph->title->Set('Current CAS distribution'); $graph->title->SetFont(FF_FONT1, FS_BOLD); $p1 = new PiePlot(array_values($data)); $p1->SetLegends(array_keys($data)); $p1->SetCenter(0.4); $graph->Add($p1); array_push($graphs, $graph); } /******************** * BH, SI and Ki ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, bh, 0)) AS 'BH_m{$i}'"); array_push($queries, "SUM(IF({$range}, si, 0)) AS 'SI_m{$i}'"); array_push($queries, "SUM(IF({$range}, ki, 0)) AS 'Ki_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id AND {$where}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('BH' => 'forestgreen', 'SI' => 'firebrick', 'Ki' => 'blue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "BH, SI and Ki distribution history", "Months", "Amount", $opts)); /******************** * CP & TD ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, cp, 0)) AS 'CP_m{$i}'"); array_push($queries, "SUM(IF({$range}, td, 0)) AS 'TD_m{$i}'"); # array_push($queries, "SUM(IF($range, intcpt, 0)) AS 'int_m$i'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id AND {$where}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('CP' => 'forestgreen', 'TD' => 'firebrick'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "CP & TD distribution history", "Months", "Amount", $opts)); /******************** * Injuries ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, IF(inj = " . MNG . ", 1, 0)+IF(agn1 = " . MNG . ", 1, 0)+IF(agn2 = " . MNG . ", 1, 0), 0)) AS 'MNG_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . NI . ", 1, 0)+IF(agn1 = " . NI . ", 1, 0)+IF(agn2 = " . NI . ", 1, 0), 0)) AS 'Ni_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . MA . ", 1, 0)+IF(agn1 = " . MA . ", 1, 0)+IF(agn2 = " . MA . ", 1, 0), 0)) AS 'MA_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . AV . ", 1, 0)+IF(agn1 = " . AV . ", 1, 0)+IF(agn2 = " . AV . ", 1, 0), 0)) AS 'AV_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . AG . ", 1, 0)+IF(agn1 = " . AG . ", 1, 0)+IF(agn2 = " . AG . ", 1, 0), 0)) AS 'AG_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . ST . ", 1, 0)+IF(agn1 = " . ST . ", 1, 0)+IF(agn2 = " . ST . ", 1, 0), 0)) AS 'ST_m{$i}'"); array_push($queries, "SUM(IF({$range}, IF(inj = " . DEAD . ", 1, 0)+IF(agn1 = " . DEAD . ", 1, 0)+IF(agn2 = " . DEAD . ", 1, 0), 0)) AS 'Dead_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches, match_data WHERE f_match_id = match_id AND {$where}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('MNG' => 'green', 'Ni' => 'red', 'MA' => 'blue', 'AV' => 'aqua', 'AG' => 'brown', 'ST' => 'purple', 'Dead' => 'slategray'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Types of sustained player injuries/statuses", "Months", "Amount", $opts)); // Only if type = team. if ($type == SG_T_TEAM) { /******************** * Won, lost and draw ********************/ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF((team1_score > team2_score AND team1_id = {$o->team_id} OR team1_score < team2_score AND team2_id = {$o->team_id}) AND {$range}, 1, 0)) AS 'W_m{$i}'"); array_push($queries, "SUM(IF((team1_score < team2_score AND team1_id = {$o->team_id} OR team1_score > team2_score AND team2_id = {$o->team_id}) AND {$range}, 1, 0)) AS 'L_m{$i}'"); array_push($queries, "SUM(IF(team1_score = team2_score AND {$range}, 1, 0)) AS 'D_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches WHERE team1_id = {$o->team_id} OR team2_id = {$o->team_id}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('W' => 'forestgreen', 'L' => 'firebrick', 'D' => 'blue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Won, lost and draw distribution history", "Months", "Matches", $opts)); /* Average deta treasury */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "AVG(IF({$range}, IF(team1_id = {$o->team_id}, income1, income2)/1000, NULL)) AS 'Avg. change_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches WHERE team1_id = {$o->team_id} OR team2_id = {$o->team_id}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('Avg. change' => 'darkolivegreen4'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Avg. change in team's treasury per match (kilo)", "Months", "Average change", array_merge($opts, array('scale' => 'textlin')))); /* SMP. */ $queries = array(); foreach (range(0, SG_MULTIBAR_HIST_LENGTH) as $i) { $range = "(\n (YEAR(date_played) = YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n AND\n (MONTH(date_played) = MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)))\n )"; # m$i = minus/negative $i months from present month. array_push($queries, "SUM(IF({$range}, IF(team1_id = {$o->team_id}, smp1, smp2), 0)) AS 'SMP_m{$i}'"); array_push($queries, "YEAR(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'yr_m{$i}'"); array_push($queries, "MONTH(SUBDATE(DATE(NOW()), INTERVAL {$i} MONTH)) AS 'mn_m{$i}'"); } $query = "SELECT " . implode(', ', $queries) . " FROM matches WHERE team1_id = {$o->team_id} OR team2_id = {$o->team_id}"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $lengends = array('SMP' => 'blue'); list($datasets, $labels) = SGraph::mbarsInputFormatter($lengends, $row); array_push($graphs, SGraph::mbars($datasets, $labels, $lengends, "Total given sportsmanship points (smp)", "Months", "Points", $opts)); } } // Multi plot, baby! $mgraph = new MGraph(); $count = count($graphs); for ($i = $j = 1; $i + ($j - 1) * $count_horiz <= $count; $j += $i == $count_horiz ? 1 : 0, $i = $i == $count_horiz ? 1 : $i + 1) { // i is horiz, j is vert. $mgraph->Add(array_shift($graphs), ($i - 1) * $opts['xdim'], ($j - 1) * $opts['ydim']); } return $mgraph->Stroke(); }
function generateGraphplot($type) { if ($type == "year") { $start = date("Y-"); $start .= "01-01 00-00-00"; $end = date("Y-"); $end .= "12-31 23-59-59"; } elseif ($type == "month") { $start = date("Y-m-"); $start .= "01 00-00-00"; $end = date("Y-m-"); $end .= "31 23-59-59"; } elseif ($type == "day") { $start = date("Y-m-d"); $start .= " 00-00-00"; $end = date("Y-m-d"); $end .= " 23-59-59"; } elseif ($type == "week") { $date = date("Y-m-d"); } // echo $sql; if ($type == "week") { $sql = "SELECT count(*) AS counts FROM `call_log` WHERE YEARWEEK(`created_at`) = YEARWEEK('{$date}') AND `deleted` = '0' AND `call_type` = 'Inquiry' "; $sql2 = "SELECT count(*) AS counts FROM `sales` WHERE YEARWEEK(`created_at`) = YEARWEEK('{$date}') AND `deleted` = '0' "; $sql3 = "SELECT count(*) AS counts FROM `ticket` WHERE YEARWEEK(`created_at`) = YEARWEEK('{$date}') AND `deleted` = '0' "; } else { $sql = "SELECT count(*) AS counts FROM `call_log` WHERE (`created_at` BETWEEN '{$start}' AND '{$end}') AND `deleted` = '0' AND `call_type` = 'Inquiry' "; $sql2 = "SELECT count(*) AS counts FROM `sales` WHERE (`created_at` BETWEEN '{$start}' AND '{$end}' ) AND `deleted` = '0' "; $sql3 = "SELECT count(*) AS counts FROM `ticket` WHERE (`created_at` BETWEEN '{$start}' AND '{$end}' ) AND `deleted` = '0' "; } $sql = DB::select(DB::raw($sql)); $sql2 = DB::select(DB::raw($sql2)); $sql3 = DB::select(DB::raw($sql3)); foreach ($sql as $rowr) { $inq[] = $rowr->counts; $leg[] = "Inquiry"; } foreach ($sql2 as $rowp) { $inq[] = $rowp->counts; $leg[] = "Sales"; } foreach ($sql3 as $rowt) { $inq[] = $rowt->counts; $leg[] = "Tickets"; } if ($inq['0'] == '0' && $inq['1'] == '0' && $inq['2'] == '0') { $inq['0'] = "1"; unset($leg); // unset legends $leg[] = "null"; // set legend null } if (!isset($inq)) { $inq[] = 1; $leg[] = "null"; } // Some data $data = $inq; // Create the Pie Graph. $graph = new \PieGraph(350, 250); $graph->SetShadow(); // $legends = array( // 'Sales', // 'Inquiry', // ); $legends = $leg; $graph->legend->Pos(0.3, 0.9); $theme_class = "DefaultTheme"; //$graph->SetTheme(new $theme_class()); // Set A title for the plot //$graph->title->Set("Call Types"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph->SetBox(true); // Create $p1 = new \PiePlot3d($data); $graph->Add($p1); $p1->ShowBorder(); $p1->SetColor('black'); $p1->SetSliceColors(array('#ADFF2F', '#DC143C', '#9966FF')); $p1->SetLegends($legends); $p1->ExplodeSlice(2); $p1->SetAngle(30); $graph->legend->SetColumns(3); $graph->legend->SetFrameWeight(1); // $graph->Stroke(); $gdImgHandler = $graph->Stroke(_IMG_HANDLER); //$fileName = $type.".png"; $fileName = "assets/tmp/" . $type . ".png"; $graph->img->Stream($fileName); }
function generategraph($report_id, $result_report) { //to generate the chart $this->load->plugin('jpgraph'); $graph = loadgraph($report_id); switch ($report_id) { case 0: // We need some data //build Data Value $datay = array(); foreach ($result_report->result_array() as $row) { $datay[] = $row['pat_count']; } // Setup the graph. $graph = new Graph(520, 350); $graph->SetScale("textlin"); // Add a drop shadow $graph->SetShadow(); // Adjust the margin a bit to make more room for titles $graph->SetMargin(40, 30, 20, 40); // Setup the titles $graph->title->Set('NHR Registry'); $graph->xaxis->title->Set('Chapters'); $graph->yaxis->title->Set('Number PWHs'); // Create the bar pot $bplot = new BarPlot($datay); // Adjust fill color $bplot->SetFillColor('orange'); $graph->Add($bplot); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph_temp_directory = $this->config->item('absolute_path') . 'graphimage'; $graph_file_name = 'adminchaptergraph.png'; $graph_file_location = $graph_temp_directory . '/' . $graph_file_name; if (file_exists($graph_file_location)) { unlink($graph_file_location); } // Finally send the graph to the browser $graph->Stroke($graph_file_location); $returnvalue = $this->config->item('base_url') . 'graphimage/adminchaptergraph.png'; break; case 1: $data = array(); $factorarray = array(); $i = 1; foreach ($result_report->result_array() as $row) { $data[] = $row['deficient_count']; $factorarray[] = $i; $i = $i + 1; } $graph = new PieGraph(520, 320); $graph->SetShadow(); $graph->title->Set("Factor Deficiency Graph"); $p1 = new PiePlot3D($data); $graph->Add($p1); $p1->ExplodeAll(10); $p1->SetAngle(70); $p1->SetLegends($factorarray); $graph_temp_directory = $this->config->item('absolute_path') . 'graphimage'; $graph_file_name = 'admindeficientgraph.png'; $graph_file_location = $graph_temp_directory . '/' . $graph_file_name; if (file_exists($graph_file_location)) { unlink($graph_file_location); } $graph->Stroke($graph_file_location); $returnvalue = $this->config->item('base_url') . 'graphimage/admindeficientgraph.png'; break; case 2: $data = array(1, 2, 3); $defarray = array(); $i = 1; $row = $result_report->result_array(); $defarray[] = $row[0]['severe']; $defarray[] = $row[0]['modrate']; $defarray[] = $row[0]['mild']; $graph = new PieGraph(520, 320); $graph->SetShadow(); $graph->title->Set("Severity Graph"); $p1 = new PiePlot3D($defarray); $graph->Add($p1); $p1->ExplodeAll(10); $p1->SetAngle(70); $p1->SetLegends($data); $graph_temp_directory = $this->config->item('absolute_path') . 'graphimage'; $graph_file_name = 'adminseveritygraph.png'; $graph_file_location = $graph_temp_directory . '/' . $graph_file_name; if (file_exists($graph_file_location)) { unlink($graph_file_location); } $graph->Stroke($graph_file_location); $returnvalue = $this->config->item('base_url') . 'graphimage/adminseveritygraph.png'; break; } return $returnvalue; }
private function piePlot($question, $datax, $datay, $width, $height) { include_once BASE . "jpgraph.php"; include_once BASE . "jpgraph_pie.php"; include_once BASE . "jpgraph_pie3d.php"; // Create the Pie Graph. $graph = new PieGraph($width, $height, "auto"); $graph->SetShadow(); // Set A title for the plot $tFontSize = 11; $graph->title->Set($question); $graph->title->SetFont(FF_VERDANA, FS_BOLD, $tFontSize); $graph->title->SetColor("darkblue"); $graph->SetAntiAliasing(true); $graph->legend->SetPos(0.02, 0.95, 'right', 'bottom'); $graph->legend->SetMarkAbsSize(5); $graph->legend->SetFont(FF_ARIAL, FS_NORMAL, 9); $tWidth = $graph->title->GetWidth($graph->img); //if ($graph->title->GetWidth($graph->img)>$width) $graph->title->SetFont(FF_VERDANA, FS_BOLD, $tFontSize-2); if ($tWidth > $width) { $index = strrpos(substr($question, 0, ($len = strlen($question)) / 2 + 5), ' '); //echo $index; if ($index === false) { $index = $len / 2 - 3; } $question[$index] = "\n"; $graph->title->SetFont(FF_VERDANA, FS_BOLD, $tFontSize -= 2); $graph->title->Set($question); } // Create pie plot $pie = new PiePlot3d($datay); $pie->SetTheme("sand"); $pie->SetCenter(0.5, 0.4); $pie->SetSize(($t = $height * 0.005 / $this->amountOfVariants) > 0.5 ? 0.5 : $t); $pie->SetAngle(30); $pie->ExplodeAll(5); $pie->value->SetFont(FF_ARIAL, FS_NORMAL, 10); $pie->SetLegends($datax); $graph->Add($pie); return $graph->Stroke("images/raporty/{$this->id_pytanie}P.png"); }
public function create_graph($width = 600, $height = 200, $data, $title, $xaxis, $yaxis, $type = "bar") { require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; require_once 'jpgraph/jpgraph_bar.php'; require_once 'jpgraph/jpgraph_pie.php'; // Create a graph instance if ($type == "bar" || $type == "line") { $graph = new Graph($width, $height); } else { if ($type == "pie") { $graph = new PieGraph($width, $height); } } // Specify what scale we want to use, // int = integer scale for the X-axis // int = integer scale for the Y-axis $graph->SetScale('intint'); $graph->SetMarginColor("lightblue:1.1"); $graph->SetShadow(); $graph->SetMargin(60, 20, 10, 40); // Box around plotarea $graph->SetBox(); // No frame around the image $graph->SetFrame(false); // Setup a title for the graph $graph->title->Set($title); $graph->title->SetMargin(8); $graph->title->SetColor("darkred"); // Setup the X and Y grid $graph->ygrid->SetFill(true, '#DDDDDD@0.5', '#BBBBBB@0.5'); $graph->ygrid->SetLineStyle('dashed'); $graph->ygrid->SetColor('gray'); $graph->xgrid->Show(); $graph->xgrid->SetLineStyle('dashed'); $graph->xgrid->SetColor('gray'); // Setup titles and X-axis labels, if it's array, first row is title if (is_array($xaxis)) { $graph->xaxis->title->Set($xaxis[0]); $xaxis = array_slice($xaxis, 1, count($xaxis) - 1); $graph->xaxis->SetTickLabels($xaxis); } else { $graph->xaxis->title->Set($xaxis); } // no array, just show name // Setup Y-axis title $graph->yaxis->title->SetMargin(10); $graph->yaxis->title->Set($yaxis); if ($type == "bar") { $plot = new BarPlot($data); $plot->SetWidth(0.6); $fcol = '#440000'; $tcol = '#FF9090'; $plot->SetFillGradient("navy:0.9", "navy:1.85", GRAD_LEFT_REFLECTION); //$plot->SetColor("black"); // Set line weigth to 0 so that there are no border // around each bar $plot->SetWeight(0); // Add the plot to the graph $graph->Add($plot); } else { if ($type == "line") { $plot = new LinePlot($data); $plot->SetFillColor('skyblue@0.5'); $plot->SetColor('navy@0.7'); $plot->mark->SetType(MARK_SQUARE); $plot->mark->SetColor('blue@0.5'); $plot->mark->SetFillColor('lightblue'); $plot->mark->SetSize(5); // Add the plot to the graph $graph->Add($plot); } else { if ($type == "pie") { $plot = new PiePlot($data); $plot->SetCenter(0.5, 0.55); $plot->SetSize(0.2); // Enable and set policy for guide-lines $plot->SetGuideLines(); $plot->SetGuideLinesAdjust(1.4); // Setup the labels $plot->SetLabelType(PIE_VALUE_PER); $plot->value->Show(); //$plot->value->SetFont(FF_ARIAL,FS_NORMAL,9); $plot->value->SetFormat('%2.1f%%'); $plot->ExplodeSlice(1); $plot->SetGuideLines(true); $graph->SetMarginColor("white"); $plot->SetLegends($xaxis); // Add the plot to the graph $graph->Add($plot); } else { die($type . " is not known graph type"); } } } // Display the graph $fn = strtolower($title); $fn = str_replace(" ", "", $fn); $filename_relative = "site/web_app/images/dynamic/{$fn}.jpg"; $filename_full = __DIR__ . "/" . $filename_relative; $graph->Stroke($filename_full); $imglink = "<img src='{$filename_relative}' title='{$title}' />\n"; return $imglink; }
public static function pieShow($piedata, $piename, $title) { //饼状图生成 $graph = new PieGraph(LENHSIZE, HEISIZE); //设置画布尺寸 $graph->img->SetMargin(LEFT, RIGHT, UP, DOWN); $graph->SetShadow(); $graph->title->set($title); $graph->title->SetFont(FF_SIMSUN, FS_BOLD, GRAGHSIZE); $num = count($piedata); //如果个数大于10则用2D显示,否则用3D显示 if (num < 10) { $pieplot = new PiePlot3D($piedata); } else { $pieplot = new PiePlot($piedata); } $pieplot->setCenter(0.4); $pieplot->SetLegends($piename); $graph->legend->SetColumns(1); $pieplot->value->Show(); $graph->legend->SetPos(0.01, 0.01, 'right', 'right'); //设置图例显示属性 $graph->legend->setFont(FF_SIMSUN, FS_BOLD, GRAGHSIZE - 6); $graph->Add($pieplot); //借出次数最多物品突出显示 $max = max($piedata); foreach ($piedata as $key => $value) { if ($value == $max) { $pieplot->ExplodeSlice($key); } } // $graph->AddText(new text("jhgjhs"),false); // $pieplot->ExplodeSlice( 0 ); $num = rand(0, RAND); // echo var_dump($num); $name = "Histogrm" . $num . ".png"; session_start(); $_SESSION["name"] = $name; // echo var_dump($name); $graph->Stroke($name); return $name; }
if (is_writable(CACHE_DIR)) { // JPGraph include_once "./lib/jpgraph/src/jpgraph.php"; include_once "./lib/jpgraph/src/jpgraph_pie.php"; include_once "./lib/jpgraph/src/jpgraph_pie3d.php"; $result = dbquery($sql); if (!mysql_num_rows($result) > 0) { die("Error: no rows retrieved from database\n"); } while ($row = mysql_fetch_object($result)) { $data[] = $row->count; $data_names[] = $row->from_domain; $data_size[] = round($row->size); } $graph = new PieGraph(800, 385, 0, false); $graph->SetShadow(); $graph->img->SetAntiAliasing(); $graph->title->Set("Top 10 Sender Domains by Volume"); $p1 = new PiePlot3d($data); $p1->SetTheme('sand'); $p1->SetLegends($data_names); $p1->SetCenter(0.73, 0.4); $graph->legend->SetLayout(LEGEND_VERT); $graph->legend->Pos(0.25, 0.2, 'center'); $graph->Add($p1); $graph->Stroke($filename); } // HTML code to display the graph echo "<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"0\" WIDTH=\"100%\">"; echo "<TR>"; echo " <TD ALIGN=\"CENTER\"><IMG SRC=\"" . IMAGES_DIR . "mailscannerlogo.gif\" ALT=\"MailScannr Logo\"></TD>";