/** * Show Horizontal Bar graph */ function ShowHBar(&$legend, &$value) { $height = 50 + count($value) * 18; $width = 500; // Set the basic parameters of the graph $graph = new Graph($width, $height, 'auto'); $graph->SetScale("textlin"); $top = 30; $bottom = 20; $left = 100; $right = 50; $graph->Set90AndMargin($left, $right, $top, $bottom); $graph->xaxis->SetTickLabels($legend); $graph->SetFrame(false); // Label align for X-axis $graph->xaxis->SetLabelAlign('right', 'center', 'right'); // Label align for Y-axis $graph->yaxis->SetLabelAlign('center', 'bottom'); // Create a bar pot $bplot = new BarPlot($value); $bplot->SetFillColor("orange"); $bplot->SetWidth(0.5); // We want to display the value of each bar at the top $graph->yaxis->scale->SetGrace(10); $graph->yaxis->SetLabelAlign('center', 'bottom'); $graph->yaxis->SetLabelFormat('%d'); $bplot->value->Show(); $bplot->value->SetFormat('%.d votes'); // Setup color for gradient fill style $bplot->SetFillGradient("navy", "lightsteelblue", GRAD_MIDVER); $graph->Add($bplot); $graph->Stroke(); }
function makeGraph($x_data, $y_data, $num_results, $title = "Statistics", $graph_type = "bar", $graph_scale = "textint") { // default graph info $width = 600; $height = 500; $top = 60; $bottom = 30; $left = 80; $right = 30; if ($graph_type != 'csv' && $num_results == 0) { header('Content-type: image/png'); readfile($GLOBALS['BASE_DIR'] . '/images/no-calls.png'); exit; } // Set the basic parameters of the graph switch ($graph_type) { case "line": //do line graph here break; // not really a graph, returns comma seperated values // not really a graph, returns comma seperated values case "csv": header("content-type: text/csv"); header('Content-Disposition: attachment; filename="statistics.csv"'); $columns = implode(',', $x_data); $rows = implode(',', $y_data); echo $columns . "\n" . $rows; break; case "bar": default: // bar is default $graph = new Graph($width, 90 + 10 * $num_results, 'auto'); $graph->SetScale($graph_scale); // Nice shadow $graph->SetShadow(); $graph->Set90AndMargin($left, $right, $top, $bottom); // Setup labels $graph->xaxis->SetTickLabels($x_data); // Label align for X-axis $graph->xaxis->SetLabelAlign('right', 'center', 'right'); // Label align for Y-axis $graph->yaxis->SetLabelAlign('center', 'bottom'); // Create a bar pot $bplot = new BarPlot($y_data); $bplot->SetFillColor("#708090"); $bplot->SetWidth(0.5); $bplot->SetYMin(0); //$bplot->SetYMin(1990); $graph->title->Set($title); $graph->Add($bplot); $graph->Stroke(); } }
function render($imgType) { $this->graph->SetImgFormat($imgType); if ($this->chartType == 'piechart') { $plot = new PiePlot3d($this->value_r); $plot->SetTheme("sand"); $plot->SetCenter(0.35); $plot->SetAngle(50); $plot->SetLegends($this->display_r); $plot->SetLabelType(PIE_VALUE_ADJPER); } else { $this->graph->xaxis->SetTickLabels($this->display_r); $plot = new BarPlot($this->value_r); $plot->SetWidth(0.5); $plot->SetFillColor("orange@0.75"); } $this->graph->Add($plot); $this->graph->Stroke(); }
public function executeBarGraph() { //Set the response header to a image JPEG datastream $this->getResponse()->setContent('image/jpeg'); // Change this defines to where Your fonts are stored DEFINE("TTF_DIR", "/usr/share/fonts/truetype/freefont/"); // Change this define to a font file that You know that You have DEFINE("TTF_SANS", "FreeSans.ttf"); $util = new util(); $dataDVDrip = $util->getTotalFormat('DVDrip', 'movies'); $dataHDrip = $util->getTotalFormat('HDrip', 'movies'); $data720p = $util->getTotalFormat('720p', 'movies'); $data1080p = $util->getTotalFormat('1080p', 'movies'); $datay = array($dataDVDrip, $dataHDrip, $data720p, $data1080p); $graph = new Graph(199, 145); $graph->SetScale('textlin'); $graph->SetColor('black'); $graph->SetMarginColor('#393939'); $graph->SetFrame(true, '#393939'); $top = 25; $bottom = 20; $left = 50; $right = 20; $graph->Set90AndMargin($left, $right, $top, $bottom); // Setup labels $lbl = array("DVDrip", "HDrip", "720p", "1080p"); $graph->xaxis->SetTickLabels($lbl); $graph->xaxis->SetColor('white'); $graph->xaxis->SetLabelAlign('right', 'center', 'right'); $graph->yaxis->SetLabelAlign('center', 'bottom'); $graph->yaxis->SetColor('white'); // Create a bar pot $bplot = new BarPlot($datay); $bplot->SetWidth(0.5); $bplot->SetFillGradient(array(250, 2, 2), array(109, 2, 2), GRAD_VERT); $graph->Add($bplot); $graph->Stroke(); return sfView::NONE; }
function generate_image() { global $percent, $legend; // Create the graph. These two calls are always required $graph = new Graph(550, 250); $graph->SetScale("textlin"); $graph->yaxis->scale->SetGrace(20); $graph->xaxis->SetLabelmargin(5); $graph->xaxis->SetTickLabels($legend); $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5'); // Add a drop shadow $graph->SetShadow(); // Adjust the margin a bit to make more room for titles $graph->img->SetMargin(50, 30, 20, 40); // Create a bar pot $bplot = new BarPlot($percent); // Adjust fill color $bplot->SetFillColor('#9999CC'); $bplot->SetShadow(); $bplot->value->Show(); $bplot->value->SetFont(FF_ARIAL, FS_BOLD, 10); $bplot->value->SetAngle(45); $bplot->value->SetFormat('%0.0f'); // Width $bplot->SetWidth(0.6); $graph->Add($bplot); // Setup the titles $graph->title->Set("PHP documentation"); $graph->xaxis->title->Set("Language"); $graph->yaxis->title->Set("Files up to date (%)"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); // Display the graph $graph->Stroke('../www/images/revcheck/info_revcheck_php_all_lang.png'); }
$graph->yaxis->title->Set('(%)'); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->ygrid->SetColor('black'); $graph->yaxis->SetTitleMargin(45); $graph->yaxis->scale->SetGrace(30); // TITRE: texte $graph->title->Set("Pass and Fail rate"); // TITRE: marge et apparence $graph->title->SetFont(FF_FONT1, FS_BOLD, 10); // Couleurs et transparence par histogramme $aColors = array('pink', 'teal', 'navy', 'lightblue', 'red', 'green'); $i = 0; $aGroupBarPlot = array(); foreach ($data1 as $key => $value) { $bplot = new BarPlot($data1[$key]); $bplot->SetFillColor($aColors[$i++]); $bplot->value->Show(); $bplot->value->SetFormat('%01.2f'); $bplot->value->SetColor("black", "darkred"); $bplot->SetLegend($key); $bplot->SetShadow('black'); $bplot->SetWidth(0.2); $aGroupBarPlot[] = $bplot; } // Création de l'objet qui regroupe nos histogrammes $gbarplot = new GroupBarPlot($aGroupBarPlot); $gbarplot->SetWidth(0.5); // Ajouter au graphique $graph->Add($gbarplot); // Afficher $graph->Stroke();
//agregamos los datos al array $datos[] = $row['cantidad']; $labels[] = $row['alias']; } //DEFINIMOS FORMATOS GENERALES $grafico = new Graph(1140, 400, 'auto'); $grafico->SetScale("textint"); $grafico->title->Set("GRAFICO ESTADISTICO DE AREAS"); $grafico->xaxis->title->Set(""); $grafico->xaxis->SetTickLabels($labels); //$grafico->xaxis->SetLabelAngle(50); //$grafico->xaxis->SetLabelAngle(45); $grafico->yaxis->title->set("CANTIDAD DE ATENCIONES"); //INGRESAMOS LOS DATOS AL ARREGLO DE DATOS QUE IRAN EN EL GRAFICO $barplot1 = new BarPlot($datos); //DEFINIMOS FORMATOS ESPECIFICOS // //UNA GRADIENTE HORIZONTAL DE MORADOS $barplot1->SetFillGradient("#BE81F7", "#E3CEF6", GRAD_HOR); //30 PIXELES DE ANCHO PARA CADA BARRA $barplot1->SetWidth(50); //AL GARFICO LE AGREGAMOS LOS DATOS $grafico->Add($barplot1); //SALIDA POR PANTALLA $grafico->Stroke(); //SALIDA ARCHIVO FORMATO PNG //$grafico->Stroke("IMG.png"); ?>
$graph->SetScale("textint"); $graph->SetShadow(); $graph->SetFrame(false); // No border around the graph // Add some grace to the top so that the scale doesn't // end exactly at the max value. $graph->yaxis->scale->SetGrace(100); // Setup X-axis labels $a = $gDateLocale->GetShortMonth(); $graph->xaxis->SetTickLabels($a); $graph->xaxis->SetFont(FF_FONT2); // Setup graph title ands fonts $graph->title->Set("Example of integer Y-scale"); $graph->title->SetFont(FF_FONT2, FS_BOLD); $graph->xaxis->title->Set("Year 2002"); $graph->xaxis->title->SetFont(FF_FONT2, FS_BOLD); // Create a bar pot $bplot = new BarPlot($datay); $bplot->SetFillColor("orange"); $bplot->SetWidth(0.5); $bplot->SetShadow(); // Setup the values that are displayed on top of each bar $bplot->value->Show(); // Must use TTF fonts if we want text at an arbitrary angle $bplot->value->SetFont(FF_ARIAL, FS_BOLD); $bplot->value->SetAngle(45); // Black color for positive values and darkred for negative values $bplot->value->SetColor("black", "darkred"); $graph->Add($bplot); // Finally stroke the graph $graph->Stroke();
function getBarPlot($data, $color) { $b = new BarPlot($data); //parameters hard coded for the moment $b->SetAbsWidth(10); $b->value->Show(true); $b->value->SetColor($this->graph->getMainColor()); $b->value->SetFormat("%d"); $b->value->HideZero(); $b->value->SetMargin(4); $b->value->SetFont($this->graph->getFont(), FS_NORMAL, 7); $b->SetWidth(0.4); $b->SetColor($color . ':0.7'); $b->SetFillColor($color); // end hard coded parameter return $b; }
function graficar_defectos($eje_y, $x_label, $pareto, $titulo_eje_x, $titulo_eje_y, $title, $name) { include "../jpgraph/src/jpgraph.php"; include "../jpgraph/src/jpgraph_line.php"; include "../jpgraph/src/jpgraph_bar.php"; $graph = new Graph(820, 350); $graph->SetScale("textlin"); $graph->SetMarginColor("#FFFFFF"); $graph->img->SetMargin(80, 80, 60, 140); $graph->yaxis->SetTitleMargin(40); $graph->SetBackgroundImage("../imagenes/fondo.jpg", BGIMG_FILLFRAME); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetTickLabels($x_label); $graph->legend->Pos(0.03, 0.3); $graph->title->SetColor("#000000"); $graph->title->Set($title); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); //$graph->yaxis->title->Set($titulo_eje_y); //$graph->xaxis->title->Set($titulo_eje_x); $graph->setcolor("#EEEEEE"); $graph->setshadow("true", 3, "#aaaaaa"); // Crear la gráfica de barras $bplot1 = new BarPlot($eje_y); $bplot1->SetWidth(0.3); $bplot1->SetYMin(0.02); $bplot1->SetFillColor("orange@0.2"); $bplot1->SetShadow('darkgray'); $bplot1->value->SetFormat("%0.1f"); $bplot1->value->SetColor("darkred"); $bplot1->value->Show(); // Crear la gráfica de líneas $lplot = new LinePlot($pareto); $lplot->mark->SetType(MARK_FILLEDCIRCLE); $lplot->mark->SetFillColor("red"); $lplot->mark->SetWidth(3); $lplot->SetColor("blue"); $lplot->SetBarCenter(); $graph->Add($bplot1); $graph->Add($lplot); $graph->Stroke("charts/" . $name); }
public function generateGraphbarrev($type) { // $type= "year"; 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"); } //$this->load->database(); if ($type == "week") { $sql = DB::select(DB::raw("SELECT `id` FROM `sales` WHERE YEARWEEK(`created_at`) = YEARWEEK('{$date}') AND `deleted` = '0' ")); } else { $sql = DB::select(DB::raw("SELECT `id` FROM `sales` WHERE (`created_at` BETWEEN '{$start}' AND '{$end}') AND `deleted` = '0' ")); } foreach ($sql as $row) { $sales_id[] = $row->id; } if (!isset($sales_id)) { $sales_id[] = 0; $sales_id[] = 0; } $ids = join(',', $sales_id); //$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("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")); foreach ($sql as $row) { $inq[] = $row->Count; $leg[] = $row->Name; } if (!isset($inq)) { $inq[] = 0; $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"; } $data1y = $inq; echo public_path('plugins\\streaming\\protected\\start.php'); echo asset('asxcasx\\dsddsd'); // die(); // Create the graph. These two calls are always required $graph = new \Graph(350, 250, 'auto'); $graph->SetScale("textlin"); $theme_class = new \UniversalTheme(); $graph->SetTheme($theme_class); // $graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135)); $graph->SetBox(false); $graph->ygrid->SetFill(false); $graph->xaxis->SetTickLabels($leg); $graph->xaxis->title->Set('Products'); $graph->yaxis->HideLine(false); $graph->yaxis->HideTicks(false, false); $graph->yaxis->title->Set('Sales'); // Create the bar plots $b1plot = new \BarPlot($data1y); // $b2plot = new BarPlot($data2y); // $b3plot = new BarPlot($data3y); // Create the grouped bar plot // $gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot)); $gbplot = new \GroupBarPlot(array($b1plot)); // ...and add it to the graPH $graph->Add($gbplot); $b1plot->SetColor("white"); $b1plot->SetFillColor("#6EDBFF"); $b1plot->SetWidth(45); $gdImgHandler = $graph->Stroke(_IMG_HANDLER); $fileName = "assets/tmp/" . $type . "_bar_rev.png"; $graph->img->Stream($fileName); }
$graph9->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph9->ygrid->SetColor('black'); $graph9->yaxis->SetTitleMargin(45); $graph9->yaxis->scale->SetGrace(30); // TITRE: texte $graph9->title->Set("Mesuring latency Sh process (micro-sec)"); // TITRE: marge et apparence $graph9->title->SetFont(FF_FONT1, FS_BOLD, 11); // Couleurs et transparence par histogramme $bplot9 = new BarPlot($data10); $bplot9->SetFillColor('lightgray'); $bplot9->value->Show(); $bplot9->value->SetFormat('%01.3f'); $bplot9->value->SetColor("black", "darkred"); $bplot9->SetShadow('black'); $bplot9->SetWidth(0.3); $graph9->Add($bplot9); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(10, 10, 10, 10); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetBackgroundImage('../fond.png'); $mgraph->AddMix($graph, 0, 0, 85); $mgraph->AddMix($graph1, 0, 270, 85); $mgraph->AddMix($graph2, 0, 540, 85); $mgraph->AddMix($graph3, 0, 810, 85); $mgraph->AddMix($graph4, 0, 1080, 85); $mgraph->AddMix($graph5, 0, 1350, 85); $mgraph->AddMix($graph6, 0, 1620, 85);
//agregamos los datos al array $datos[] = $row['cantidad']; $labels[] = $row['alias']; } //DEFINIMOS FORMATOS GENERALES $grafico = new Graph(1200, 400, 'auto'); $grafico->SetScale("textint"); $grafico->title->Set("GRAFICO ESTADISTICO"); $grafico->xaxis->title->Set(""); $grafico->xaxis->SetTickLabels($labels); //$grafico->xaxis->SetLabelAngle(50); //$grafico->xaxis->SetLabelAngle(45); $grafico->yaxis->title->set("CANTIDAD DE TICKETS"); //INGRESAMOS LOS DATOS AL ARREGLO DE DATOS QUE IRAN EN EL GRAFICO $barplot1 = new BarPlot($datos); //DEFINIMOS FORMATOS ESPECIFICOS // //UNA GRADIENTE HORIZONTAL DE MORADOS $barplot1->SetFillGradient("#BE81F7", "#E3CEF6", GRAD_HOR); //30 PIXELES DE ANCHO PARA CADA BARRA $barplot1->SetWidth(60); //AL GARFICO LE AGREGAMOS LOS DATOS $grafico->Add($barplot1); //SALIDA POR PANTALLA $grafico->Stroke(); //SALIDA ARCHIVO FORMATO PNG //$grafico->Stroke("IMG.png"); ?>
function parse($input, $parser) { global $jpgraphMarkList; $chart_type = split(",", $this->type); $mark_type = split(",", $this->mark); // retrieving data $i = 0; $max_row_count = -1; foreach (split("\n", $input) as $line) { // skip empty line or comments if (preg_match("/^(\\s*)#.*\$|^(\\s*)\$/", $line)) { continue; } $line_array = split($this->fieldsep, $line); // if first loop => setting label and continue with next loop if ($i == 0) { $this->labels = $line_array; $i++; continue; } // Storing data for ($j = 0; $j < count($line_array); $j++) { $this->datay[$j][] = $line_array[$j]; } // check data integrity if ($max_row_count == -1) { $max_row_count = count($line_array); } if ($max_row_count != count($line_array)) { throw new Exception("Error while parsing '" . implode($this->fieldsep, $line_array) . "' : bad number of row."); } $i++; } $data_start = 0; // if(x, y) curve => set datax with first set of datay if ($this->islinear) { $this->datax = $this->datay[0]; $data_start = 1; if ($this->xistime) { for ($i = 0; $i < count($this->datax); $i++) { $this->datax[$i] = strtotime($this->datax[$i]); } } } // Setting default value for chart type array. by default : line. // If only one type => applying same type for everybody if (count($chart_type) == 0) { $chart_type[0] = "line"; } if (count($chart_type) != $max_row_count) { $tmp_type = $chart_type[0]; $chart_type = array(); for ($i = count($chart_type); $i < $max_row_count; $i++) { $chart_type[$i] = $tmp_type; } } // same thing for mark if (count($mark_type) == 0) { $mark_type[0] = "line"; } if (count($mark_type) != $max_row_count) { $tmp_mark = $mark_type[0]; $mark_type = array(); for ($i = count($mark_type); $i < $max_row_count; $i++) { $mark_type[$i] = $tmp_mark; } } // Possibility to ignore data $disable_row = array(); foreach (split(",", $this->disable) as $elt) { $disable_row[$elt] = true; } // Creating data object for ($i = $data_start; $i < count($this->datay); $i++) { if (array_key_exists($i + 1, $disable_row) && $disable_row[$i + 1]) { continue; } $show_plot = false; switch ($chart_type[$i]) { case "bar": $plot = new BarPlot($this->datay[$i], $this->datax); $plot->SetWidth($this->barwidth); $plot->SetFillColor($this->color_list[$i % count($this->color_list)]); break; case "area": $plot = new LinePlot($this->datay[$i], $this->datax); $plot->SetColor("gray"); $plot->SetFillColor($this->color_list[$i % count($this->color_list)]); $show_plot = true; break; default: case "line": $plot = new LinePlot($this->datay[$i], $this->datax); $show_plot = true; break; } if ($show_plot) { $mark_id = $jpgraphMarkList[$mark_type[$i]]; if (!$mark_id) { throw new JpgraphMWException("Unknown mark type(" . $mark_type[$i] . "). Possible values are: " . implode(", ", array_keys($jpgraphMarkList))); } $plot->mark->SetType($mark_id); $plot->mark->SetFillColor($this->color_list[$i % count($this->color_list)]); } $plot->SetLegend($this->labels[$i]); if ($this->isstacked) { $plot_list[] = $plot; $plot->SetColor("black"); $plot->SetFillColor($this->color_list[$i % count($this->color_list)]); } else { $plot->SetColor($this->color_list[$i % count($this->color_list)]); $this->graph->Add($plot); } } // stacked case if ($this->isstacked) { $point_area = new AccLinePlot($plot_list); $this->graph->Add($point_area); } }
$graph3->yaxis->title->Set('time(us)'); $graph3->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph3->ygrid->SetColor('black'); $graph3->yaxis->SetTitleMargin(45); $graph3->yaxis->scale->SetGrace(30); // TITRE: texte $graph3->title->Set("Pthread kill latency -Mesuring Standard Deviation(us)"); // TITRE: marge et apparence $graph3->title->SetFont(FF_FONT1, FS_BOLD, 11); // Couleurs et transparence par histogramme $bplot3 = new BarPlot($data4); $bplot3->SetFillColor('red'); $bplot3->value->SetFormat('%01.3f'); $bplot3->value->Show(); $bplot3->SetShadow('black'); $bplot3->value->SetColor("black", "darkred"); $bplot3->SetShadow('black'); $bplot3->SetWidth(0.3); $graph3->Add($bplot3); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(10, 10, 10, 10); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetBackgroundImage('../fond.png'); $mgraph->AddMix($graph, 0, 0, 85); $mgraph->AddMix($graph1, 0, 270, 85); $mgraph->AddMix($graph2, 0, 540, 85); $mgraph->AddMix($graph3, 0, 810, 85); $mgraph->Stroke();
function top($VAR) { global $smarty, $C_translate, $C_auth; # Get the period type, default to month if (empty($VAR['period'])) { $p = 'm'; } else { $p = $VAR['period']; } # Load the jpgraph class include PATH_GRAPH . "jpgraph.php"; include PATH_GRAPH . "jpgraph_bar.php"; # check the validation for this function if (!$C_auth->auth_method_by_name($this->module, 'search')) { $error = $C_translate->translate('module_non_auth', '', ''); include PATH_GRAPH . "jpgraph_canvas.php"; $graph = new CanvasGraph(460, 55, "auto"); $t1 = new Text($error); $t1->Pos(0.2, 0.5); $t1->SetOrientation("h"); $t1->SetBox("white", "black", 'gray'); $t1->SetFont(FF_FONT1, FS_NORMAL); $t1->SetColor("black"); $graph->AddText($t1); $graph->Stroke(); exit; } # Get the period start & end switch ($p) { # By Weeks: case 'w': $interval = "1"; $width = ".9"; $title = 'Top Accounts for Last Last Week'; $dow = date('w'); $start_str = mktime(0, 0, 0, date('m'), date('d') - $dow, date('y')); $end_str = mktime(23, 59, 59, date('m'), date('d'), date('y')); break; # By Months: # By Months: case 'm': $interval = "3"; $width = ".6"; $title = 'Top Accounts for Last Last Month'; $start_str = mktime(0, 0, 0, date('m'), 1, date('y')); $end_str = mktime(23, 59, 59, date('m'), date('d'), date('y')); break; # By Years: # By Years: case 'y': $interval = "1"; $width = ".8"; $title = 'Top Accounts for Last Last Year'; $start_str = mktime(0, 0, 0, 1, 1, date('y')); $end_str = mktime(23, 59, 59, date('m'), date('d'), date('y')); break; } ##############################@@@@@@@@ # Get accounts & sales for this period ##############################@@@@@@@@ $db =& DB(); $sql = 'SELECT account_id,total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE date_orig >= ' . $db->qstr($start_str) . ' AND date_orig <= ' . $db->qstr($end_str) . ' AND site_id = ' . $db->qstr(DEFAULT_SITE); $result = $db->Execute($sql); if (@$result->RecordCount() == 0) { $file = fopen(PATH_THEMES . 'default_admin/images/invisible.gif', 'r'); fpassthru($file); exit; } while (!$result->EOF) { $amt = $result->fields['total_amt']; $acct = $result->fields['account_id']; if (!isset($arr[$acct])) { $arr[$acct] = 0; } $arr[$acct] += $amt; $result->MoveNext(); } $i = 0; while (list($key, $var) = each(@$arr)) { # Get the user name $sql = 'SELECT first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account WHERE id = ' . $db->qstr($key) . ' AND site_id = ' . $db->qstr(DEFAULT_SITE); $rs = $db->Execute($sql); $_lbl[] = strtoupper(substr($rs->fields['first_name'], 0, 1)) . ". " . $rs->fields['last_name']; $_datay[] = $var; $i++; } ### Sort the arrays array_multisort($_datay, SORT_DESC, SORT_NUMERIC, $_lbl); ### Limit the results to 10 or less for ($i = 0; $i < count($_lbl); $i++) { $lbl[$i] = $_lbl[$i]; $datay[$i] = $_datay[$i]; if ($i >= 9) { $i = count($_lbl); } } $i = count($lbl); # Get the Currency $sql = 'SELECT symbol FROM ' . AGILE_DB_PREFIX . 'currency WHERE id = ' . $db->qstr(DEFAULT_CURRENCY) . ' AND site_id = ' . $db->qstr(DEFAULT_SITE); $rs = $db->Execute($sql); $currency_iso = $rs->fields['symbol']; // Size of graph $width = 265; $height = 75 + $i * 15; // Set the basic parameters of the graph $graph = new Graph($width, $height, 'auto'); $graph->SetScale("textlin"); $graph->yaxis->scale->SetGrace(50); $graph->SetMarginColor('#F9F9F9'); $graph->SetFrame(true, '#CCCCCC', 1); $graph->SetColor('#FFFFFF'); $top = 45; $bottom = 10; $left = 95; $right = 15; $graph->Set90AndMargin($left, $right, $top, $bottom); // Label align for X-axis $graph->xaxis->SetLabelAlign('right', 'center', 'right'); // Label align for Y-axis $graph->yaxis->SetLabelAlign('center', 'bottom'); $graph->xaxis->SetTickLabels($lbl); // Titles $graph->title->SetFont(FF_FONT1, FS_BOLD, 9.5); $title = $C_translate->translate('graph_top', 'account_admin', ''); $graph->title->Set($title); // Create a bar pot $bplot = new BarPlot($datay); $bplot->SetFillColor("#506DC7"); $bplot->SetWidth(0.2); // Show the values $bplot->value->Show(); $bplot->value->SetFont(FF_FONT1, FS_NORMAL, 8); $bplot->value->SetAlign('center', 'center'); $bplot->value->SetColor("black", "darkred"); $bplot->value->SetFormat($currency_iso . '%.2f'); $graph->Add($bplot); $graph->Stroke(); return; }
function graph_group($p_metrics, $p_title = '', $p_graph_width = 350, $p_graph_height = 400, $p_baseline = 100) { # $p_metrics is an array of three arrays # $p_metrics['open'] = array( 'enum' => value, ...) # $p_metrics['resolved'] # $p_metrics['closed'] $t_graph_font = graph_get_font(); # count up array portions that are set $t_count = 0; foreach (array('open', 'resolved', 'closed') as $t_label) { if (isset($p_metrics[$t_label]) && is_array($p_metrics[$t_label])) { $t_count += array_sum($p_metrics[$t_label]); } } error_check($t_count, $p_title); # calculate totals $total = graph_total_metrics($p_metrics); if (plugin_config_get('eczlibrary') == ON) { $graph = new ezcGraphBarChart(); $graph->title = $p_title; $graph->background->color = '#FFFFFF'; $graph->options->font = $t_graph_font; $graph->options->font->maxFontSize = 12; $graph->legend = false; foreach (array('open', 'resolved', 'closed') as $t_label) { $graph->data[$t_label] = new ezcGraphArrayDataSet($p_metrics[$t_label]); } $graph->data['total'] = new ezcGraphArrayDataSet($total); //$graph->data['total']->displayType = ezcGraph::LINE; //$graph->data['total']->barMargin = -20; $graph->options->fillLines = 210; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = 45; $graph->driver = new ezcGraphGdDriver(); //$graph->driver->options->supersampling = 1; $graph->driver->options->jpegQuality = 100; $graph->driver->options->imageFormat = IMG_JPEG; $graph->renderer->options->syncAxisFonts = false; $graph->renderToOutput($p_graph_width, $p_graph_height); } else { # defines margin according to height $graph = new Graph($p_graph_width, $p_graph_height); $graph->img->SetMargin(45, 35, 35, $p_baseline); if (ON == plugin_config_get('jpgraph_antialias')) { $graph->img->SetAntiAliasing(); } $graph->SetScale('textlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->title->SetFont($t_graph_font, FS_BOLD); $graph->title->Set($p_title); $graph->xaxis->SetTickLabels(array_keys($p_metrics['open'])); if (FF_FONT2 <= $t_graph_font) { $graph->xaxis->SetLabelAngle(60); } else { $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts } $graph->xaxis->SetFont($t_graph_font); $graph->legend->Pos(0.05, 0.08); $graph->legend->SetFont($t_graph_font); $graph->yaxis->scale->ticks->SetDirection(-1); $graph->yaxis->SetFont($t_graph_font); $graph->yscale->SetGrace(10); # adds on the same graph $tot = new BarPlot(array_values($total)); $tot->SetFillColor('lightblue'); $tot->SetWidth(0.7); $tot->SetLegend(plugin_lang_get('legend_total')); $graph->Add($tot); $p1 = new BarPlot(array_values($p_metrics['open'])); $p1->SetFillColor('yellow'); $p1->SetWidth(1); $p1->SetLegend(plugin_lang_get('legend_opened')); $p2 = new BarPlot(array_values($p_metrics['closed'])); $p2->SetFillColor('blue'); $p2->SetWidth(1); $p2->SetLegend(plugin_lang_get('legend_closed')); $p3 = new BarPlot(array_values($p_metrics['resolved'])); $p3->SetFillColor('red'); $p3->SetWidth(1); $p3->SetLegend(plugin_lang_get('legend_resolved')); $gbplot = new GroupBarPlot(array($p1, $p3, $p2)); $graph->Add($gbplot); if (helper_show_query_count()) { $graph->subtitle->Set(db_count_queries() . ' queries (' . db_time_queries() . 'sec)'); $graph->subtitle->SetFont($t_graph_font, FS_NORMAL, 8); } $graph->Stroke(); } }
} $datax[] = $_REQUEST["actual"]; $datay[] = "Prima Actual"; $datax[] = $_REQUEST["provart"]; $datay[] = "Prima Provincia ART"; $graph = new Graph(400, 256, "auto"); $graph->SetScale("textlin", $min, $max); $graph->SetShadow(); $graph->img->SetMargin(40, 30, 20, 40); $graph->xaxis->SetFont(FF_ARIAL, FS_BOLD, 10); $graph->xaxis->SetLabelAlign("center", "bottom"); $graph->xaxis->SetLabelAngle(0); $graph->xaxis->SetLabelMargin(16); $graph->xaxis->SetTickLabels($datay); $graph->yaxis->SetLabelMargin(1); if ($leyenda) { $txt = new Text(" (En miles)"); $txt->SetColor("red"); $graph->AddText($txt); } $bplot = new BarPlot($datax); //$bplot->SetColor("gray"); //$bplot->SetFillColor("orange"); $bplot->SetFillGradient("#00a4e4", "#00a4e4", GRAD_VER); $bplot->SetShadow("black", 8, 4); $bplot->SetValuePos("bottom"); $bplot->SetWidth(0.3); $graph->Add($bplot); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 10); $graph->Stroke(GRAFICO_CARTA_COTIZACION . $_REQUEST["archivo"]); //$graph->Stroke();
$graph7->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph7->ygrid->SetColor('black'); $graph7->yaxis->SetTitleMargin(45); $graph7->yaxis->scale->SetGrace(30); // TITRE: texte $graph7->title->Set("Benchmarking simulated cpu of x in the presence of simulated Memload -Mesuring Deadline met-"); // TITRE: marge et apparence $graph7->title->SetFont(FF_FONT1, FS_BOLD, 11); // Couleurs et transparence par histogramme $bplot7 = new BarPlot($data8); $bplot7->SetFillColor('green'); $bplot7->value->Show(); $bplot7->value->SetFormat('%01.3f'); $bplot7->value->SetColor("black", "darkred"); $bplot7->SetShadow('black'); $bplot7->SetWidth(0.3); $graph7->Add($bplot7); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(10, 10, 10, 10); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetBackgroundImage('../fond.png'); $mgraph->AddMix($graph, 0, 0, 85); $mgraph->AddMix($graph2, 0, 270, 85); $mgraph->AddMix($graph3, 0, 540, 85); $mgraph->AddMix($graph4, 0, 810, 85); $mgraph->AddMix($graph5, 0, 1080, 85); $mgraph->AddMix($graph6, 0, 1350, 85); $mgraph->AddMix($graph7, 0, 1620, 85);
<?php require_once 'jpgraph-3.5.0b1/src/jpgraph.php'; require_once 'jpgraph-3.5.0b1/src/jpgraph_bar.php'; include_once 'classAnalisis.php'; $anio = $_GET['anio']; if (!isset($anio)) { $anio = date('Y'); } $objetoanalisis = new classAnalisis(); $dat = $objetoanalisis->topvendedores($anio); for ($i = 0; $i < count($dat); $i++) { $datos[] = $dat[$i]['comprado']; } for ($i = 0; $i < count($dat); $i++) { $labels[] = $dat[$i]['usuario']; } // Creamos el grafico $grafico = new Graph(400, 400); $grafico->SetScale("textlin"); $grafico->title->Set("Año " . $anio); $grafico->xaxis->title->Set(""); $grafico->xaxis->SetTickLabels($labels); $grafico->yaxis->title->Set(""); $barplot1 = new BarPlot($datos); $barplot1->SetWidth(30); // 30 pixeles de ancho para cada barra $grafico->Add($barplot1); $barplot1->value->Show(); $grafico->Stroke();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; $datay = array(12, 8, 19, 3, 10, 5); // Create the graph. These two calls are always required $graph = new Graph(300, 200); $graph->SetScale("textlin"); // Add a drop shadow $graph->SetShadow(); // Adjust the margin a bit to make more room for titles $graph->img->SetMargin(40, 30, 20, 40); // Create a bar pot $bplot = new BarPlot($datay); // Adjust fill color $bplot->SetFillColor('orange'); $bplot->SetWidth(1.0); $graph->Add($bplot); // Setup the titles $graph->title->Set("Bar graph"); $graph->xaxis->title->Set("X-title"); $graph->yaxis->title->Set("Y-title"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); // Display the graph $graph->Stroke();
function print_graph($g, $pgwidth) { $splines = false; $bandw = false; $percent = false; $show_percent = false; $stacked = false; $h = false; $show_values = false; $hide_grid = false; $hide_y_axis = false; if (isset($g['attr']['TYPE']) && $g['attr']['TYPE']) { $type = strtolower($g['attr']['TYPE']); } if (!in_array($type, array('bar', 'horiz_bar', 'line', 'radar', 'pie', 'pie3d', 'xy', 'scatter'))) { $type = 'bar'; } // Default=bar if (isset($g['attr']['STACKED']) && $g['attr']['STACKED']) { $stacked = true; } // stacked for bar or horiz_bar if (isset($g['attr']['SPLINES']) && $g['attr']['SPLINES'] && $type == 'xy') { $splines = true; } // splines for XY line graphs if (isset($g['attr']['BANDW']) && $g['attr']['BANDW']) { $bandw = true; } // black and white if (isset($g['attr']['LEGEND-OVERLAP']) && $g['attr']['LEGEND-OVERLAP']) { $overlap = true; } // avoid overlap of Legends over graph (line, bar, horiz_bar only) if (isset($g['attr']['PERCENT']) && $g['attr']['PERCENT'] && $type != 'xy' && $type != 'scatter') { $percent = true; } // Show data series as percent of total in series if (isset($g['attr']['SHOW-VALUES']) && $g['attr']['SHOW-VALUES']) { $show_values = true; } // Show the individual data values if (isset($g['attr']['HIDE-GRID']) && $g['attr']['HIDE-GRID']) { $hide_grid = true; } // Hide the y-axis gridlines if (isset($g['attr']['HIDE-Y-AXIS']) && $g['attr']['HIDE-Y-AXIS']) { $hide_y_axis = true; } // Hide the y-axis // Antialias: If true - better quality curves, but graph line will only be 1px even in PDF 300dpi // default=true for most except line and radar if (isset($g['attr']['ANTIALIAS']) && ($g['attr']['ANTIALIAS'] == '' || $g['attr']['ANTIALIAS'] == 0)) { $antialias = false; } else { if (isset($g['attr']['ANTIALIAS']) && $g['attr']['ANTIALIAS'] > 0) { $antialias = true; } else { if ($type == 'line' || $type == 'radar') { $antialias = false; } else { $antialias = true; } } } if ($g['attr']['DPI']) { $dpi = intval($g['attr']['DPI']); } if (!$dpi || $dpi < 50 || $dpi > 2400) { $dpi = 150; } // Default dpi 150 $k = 0.2645 / 25.4 * $dpi; // mPDF 4.5.009 global $JpgUseSVGFormat; if (isset($JpgUseSVGFormat) && $JpgUseSVGFormat) { $img_type = 'svg'; $k = 1; // Overrides as Vector scale does not need DPI } else { $img_type = 'png'; } if (isset($g['attr']['TITLE']) && $g['attr']['TITLE']) { $title = $g['attr']['TITLE']; } if (isset($g['attr']['LABEL-X']) && $g['attr']['LABEL-X']) { $xlabel = $g['attr']['LABEL-X']; } // NOT IMPLEMENTED?????? if (isset($g['attr']['LABEL-Y']) && $g['attr']['LABEL-Y']) { $ylabel = $g['attr']['LABEL-Y']; } if (isset($g['attr']['AXIS-X']) && $g['attr']['AXIS-X']) { $xaxis = strtolower($g['attr']['AXIS-X']); } if (!in_array($xaxis, array('text', 'lin', 'linear', 'log'))) { $xaxis = 'text'; } // Default=text if ($xaxis == 'linear') { $xaxis = 'lin'; } if (isset($g['attr']['AXIS-Y']) && $g['attr']['AXIS-Y']) { $yaxis = strtolower($g['attr']['AXIS-Y']); } if (!in_array($yaxis, array('lin', 'linear', 'log', 'percent'))) { $yaxis = 'lin'; } // Default=lin if ($yaxis == 'percent') { $show_percent = true; $yaxis = 'lin'; } // Show percent sign on scales if ($yaxis == 'linear') { $yaxis = 'lin'; } if ($splines) { $xaxis = 'lin'; } $axes = $xaxis . $yaxis; // e.g.textlin, textlog, loglog, loglin, linlog (XY) // mPDF 4.0 if (isset($g['attr']['cWIDTH']) && $g['attr']['cWIDTH']) { $w = $g['attr']['cWIDTH'] / 0.2645; } // pixels if (isset($g['attr']['cHEIGHT']) && $g['attr']['cHEIGHT']) { $h = $g['attr']['cHEIGHT'] / 0.2645; } if (isset($g['attr']['SERIES']) && strtolower($g['attr']['SERIES']) == 'rows') { $dataseries = 'rows'; } else { $dataseries = 'cols'; } // Defaults - define data $rowbegin = 2; $colbegin = 2; if ($type == 'scatter' || $type == 'xy') { if ($dataseries == 'rows') { $rowbegin = 1; } else { $colbegin = 1; } } $rowend = 0; $colend = 0; if (isset($g['attr']['DATA-ROW-BEGIN']) && ($g['attr']['DATA-ROW-BEGIN'] === '0' || $g['attr']['DATA-ROW-BEGIN'] > 0)) { $rowbegin = $g['attr']['DATA-ROW-BEGIN']; } if (isset($g['attr']['DATA-COL-BEGIN']) && ($g['attr']['DATA-COL-BEGIN'] === '0' || $g['attr']['DATA-COL-BEGIN'] > 0)) { $colbegin = $g['attr']['DATA-COL-BEGIN']; } if (isset($g['attr']['DATA-ROW-END']) && ($g['attr']['DATA-ROW-END'] === '0' || $g['attr']['DATA-ROW-END'] != 0)) { $rowend = $g['attr']['DATA-ROW-END']; } if (isset($g['attr']['DATA-COL-END']) && ($g['attr']['DATA-COL-END'] === '0' || $g['attr']['DATA-COL-END'] != 0)) { $colend = $g['attr']['DATA-COL-END']; } $nr = count($g['data']); $nc = 0; foreach ($g['data'] as $r) { $cc = 0; foreach ($r as $c) { $cc++; } $nc = max($nc, $cc); } if ($colend == 0) { $colend = $nc; } else { if ($colend < 0) { $colend = $nc + $colend; } } if ($rowend == 0) { $rowend = $nr; } else { if ($rowend < 0) { $rowend = $nr + $rowend; } } if ($colend < $colbegin) { $colend = $colbegin; } if ($rowend < $rowbegin) { $rowend = $rowbegin; } // if ($type == 'xy' || $type=='scatter') { $colstart=0; } // Get Data + Totals $data = array(); $totals = array(); for ($r = $rowbegin - 1; $r < $rowend; $r++) { for ($c = $colbegin - 1; $c < $colend; $c++) { if (isset($g['data'][$r][$c])) { $g['data'][$r][$c] = floatval($g['data'][$r][$c]); } else { $g['data'][$r][$c] = 0; } if ($dataseries == 'rows') { $data[$r + 1 - $rowbegin][$c + 1 - $colbegin] = $g['data'][$r][$c]; $totals[$r + 1 - $rowbegin] += $g['data'][$r][$c]; } else { $data[$c + 1 - $colbegin][$r + 1 - $rowbegin] = $g['data'][$r][$c]; if (isset($totals[$c + 1 - $colbegin])) { $totals[$c + 1 - $colbegin] += $g['data'][$r][$c]; } else { $totals[$c + 1 - $colbegin] = $g['data'][$r][$c]; } } } } // PERCENT if ($percent && $type != 'pie' && $type != 'pie3d') { for ($r = 0; $r < count($data); $r++) { for ($c = 0; $c < count($data[$r]); $c++) { $data[$r][$c] = $data[$r][$c] / $totals[$r] * 100; } } } // Get Legends and labels $legends = array(); $labels = array(); $longestlegend = 0; $longestlabel = 0; if ($dataseries == 'cols') { if ($colbegin > 1) { for ($r = $rowbegin - 1; $r < $rowend; $r++) { $legends[$r + 1 - $rowbegin] = $g['data'][$r][0]; $longestlegend = max($longestlegend, strlen($g['data'][$r][0])); } } if ($rowbegin > 1) { for ($c = $colbegin - 1; $c < $colend; $c++) { $labels[$c + 1 - $colbegin] = $g['data'][0][$c]; $longestlabel = max($longestlabel, strlen($g['data'][0][$c])); } } } else { if ($dataseries == 'rows') { if ($colbegin > 1) { for ($r = $rowbegin - 1; $r < $rowend; $r++) { $labels[$r + 1 - $rowbegin] = $g['data'][$r][0]; $longestlabel = max($longestlabel, strlen($g['data'][$r][0])); } } if ($rowbegin > 1) { for ($c = $colbegin - 1; $c < $colend; $c++) { $legends[$c + 1 - $colbegin] = $g['data'][0][$c]; $longestlegend = max($longestlegend, strlen($g['data'][0][$c])); } } } } // Default sizes $defsize = array(); $defsize['pie'] = array('w' => 600, 'h' => 300); $defsize['pie3d'] = array('w' => 600, 'h' => 300); $defsize['radar'] = array('w' => 600, 'h' => 300); $defsize['line'] = array('w' => 600, 'h' => 400); $defsize['xy'] = array('w' => 600, 'h' => 400); $defsize['scatter'] = array('w' => 600, 'h' => 400); $defsize['bar'] = array('w' => 600, 'h' => 400); $defsize['horiz_bar'] = array('w' => 600, 'h' => 500); // Use default ratios if ($w && !$h) { $h = $w * $defsize[$type]['h'] / $defsize[$type]['w']; } if ($h && !$w) { $w = $h * $defsize[$type]['w'] / $defsize[$type]['h']; } if (!$h && !$w) { $w = $defsize[$type]['w']; $h = $defsize[$type]['h']; } if (count($data) > 0 && $type) { $figure_file = "graph_cache/" . rand(11111, 999999999) . "." . $img_type; if ($bandw) { $colours = array('snow1', 'black', 'snow4', 'snow3', 'snow2', 'cadetblue4', 'cadetblue3', 'cadetblue1', 'bisque4', 'bisque2', 'beige'); } else { $colours = array('cyan', 'darkorchid4', 'cadetblue3', 'khaki1', 'darkolivegreen2', 'cadetblue4', 'coral', 'cyan4', 'rosybrown3', 'wheat1'); } $fills = array('navy', 'orange', 'red', 'yellow', 'purple', 'navy', 'orange', 'red', 'yellow', 'purple'); $patterns = array(PATTERN_DIAG1, PATTERN_CROSS1, PATTERN_STRIPE1, PATTERN_DIAG3, PATTERN_CROSS2, PATTERN_DIAG2, PATTERN_DIAG4, PATTERN_CROSS3, PATTERN_CROSS4, PATTERN_STRIPE1); $markers = array(MARK_DIAMOND, MARK_SQUARE, MARK_CIRCLE, MARK_UTRIANGLE, MARK_DTRIANGLE, MARK_FILLEDCIRCLE, MARK_CROSS, MARK_STAR, MARK_X); // LEGENDS if ($type == 'pie' || $type == 'pie3d') { $graph = new PieGraph($w * $k, $h * $k); } else { if ($type == 'radar') { $graph = new RadarGraph($w * $k, $h * $k); } else { $graph = new Graph($w * $k, $h * $k); } } // mPDF 4.5.009 // $graph->img->SetImgFormat($img_type) ; // if (strtoupper($img_type)=='JPEG') { $graph->img->SetQuality(90); } if ($antialias) { $graph->img->SetAntiAliasing(); } $graph->SetShadow(true, 2 * $k); $graph->SetMarginColor("white"); // TITLE $graph->title->Set($title); $graph->title->SetMargin(10 * $k); $graph->title->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); $graph->title->SetColor("black"); $graph->legend->SetLineSpacing(3 * $k); $graph->legend->SetMarkAbsSize(6 * $k); $graph->legend->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); // Set GRAPH IMAGE MARGINS if ($type == 'pie' || $type == 'pie3d') { $psize = 0.3; $pposxabs = $w / 2; $pposy = 0.55; if ($longestlegend) { // if legend showing $pposxabs -= ($longestlegend * 5 + 20) / 2; } $pposx = $pposxabs / $w; $graph->legend->Pos(0.02, 0.5, 'right', 'center'); } else { if ($type == 'radar') { $psize = 0.5; $pposxabs = $w / 2; $pposy = 0.55; if ($longestlabel) { // if legend showing $pposxabs -= ($longestlabel * 5 + 20) / 2; } $pposx = $pposxabs / $w; $graph->legend->Pos(0.02, 0.5, 'right', 'center'); } else { if ($type == 'xy' || $type == 'scatter') { $pml = 50; $pmr = 20; $pmt = 60; $pmb = 50; $xaxislblmargin = $pmb - 30; $yaxislblmargin = $pml - 15; $graph->legend->Pos(0.02, 0.1, 'right', 'top'); } else { if ($type == 'line' || $type == 'bar') { $pml = 50; $pmr = 20; $pmt = 60; $pmb = 50; $xlangle = 0; $ll = $longestlegend * 5; // 45 degrees 8pt fontsize if ($ll > 5 || $ll > 3 && count($data) > 10) { $pmb = max($pmb, $ll + 30); $xlangle = 50; } $xaxislblmargin = $pmb - 30; $yaxislblmargin = $pml - 15; if ($longestlabel && !$overlap) { // if legend showing $pmr = $longestlabel * 5 + 40; } $graph->legend->Pos(0.02, 0.1, 'right', 'top'); } else { if ($type == 'horiz_bar') { $pml = 50; $pmr = 20; $pmt = 50; $pmb = 45; $ll = $longestlegend * 6.5; // 8pt fontsize $pml = max($pml, $ll + 20); $xaxislblmargin = $pml - 20; $yaxislblmargin = $pmb - 15; if ($longestlabel && !$overlap) { // if legend showing $pmr = $longestlabel * 5 + 40; } $graph->legend->Pos(0.02, 0.1, 'right', 'top'); } } } } } // DRAW THE GRAPHS if ($type == 'pie') { $p1 = new PiePlot($data[0]); $p1->SetSliceColors($colours); if ($show_values) { $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent) { $p1->SetLabelType(PIE_VALUE_PERADJ); } else { $p1->SetLabelType(PIE_VALUE_ABS); } if ($percent || $show_percent) { $p1->value->SetFormat("%d%%"); } else { $p1->value->SetFormat("%s"); } // Enable and set policy for guide-lines. Make labels line up vertically $p1->SetGuideLines(true); $p1->SetGuideLinesAdjust(1.5); } else { $p1->value->Show(false); } $p1->SetLegends($legends); $p1->SetSize($psize); $p1->SetCenter($pposx, $pposy); if ($labels[0]) { $graph->subtitle->Set($labels[0]); $graph->subtitle->SetMargin(10 * $k); $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); $graph->subtitle->SetColor("black"); } $graph->Add($p1); } else { if ($type == 'pie3d') { $p1 = new PiePlot3d($data[0]); $p1->SetSliceColors($colours); if ($show_values) { $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent) { $p1->SetLabelType(PIE_VALUE_PERADJ); } else { $p1->SetLabelType(PIE_VALUE_ABS); } if ($percent || $show_percent) { $p1->value->SetFormat("%d%%"); } else { $p1->value->SetFormat("%s"); } } else { $p1->value->Show(false); } $p1->SetLegends($legends); $p1->SetEdge(); $p1->SetSize($psize); $p1->SetCenter($pposx, $pposy); if ($labels[0]) { $graph->subtitle->Set($labels[0]); $graph->subtitle->SetMargin(10 * $k); $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); $graph->subtitle->SetColor("black"); } $graph->Add($p1); } else { if ($type == 'radar') { $graph->SetSize($psize); $graph->SetPos($pposx, $pposy); $graph->SetTitles($legends); // labels each axis $graph->axis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->axis->title->SetMargin(5 * $k); $graph->axis->SetWeight(1 * $k); $graph->axis->HideLabels(); $graph->axis->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k); $graph->HideTickMarks(); $group = array(); foreach ($data as $series => $dat) { $rdata = array(); foreach ($data[$series] as $row) { $rdata[] = $row; } if (count($rdata) < 3) { die("ERROR::Graph::Cannot create a Radar Plot with less than 3 data points."); } // Create the radar plot $bplot = new RadarPlot($rdata); $bplot->mark->SetType($markers[$series]); $bplot->mark->SetFillColor($colours[$series]); $bplot->mark->SetWidth(3 * $k); $bplot->SetColor($colours[$series]); if ($series == 0) { $bplot->SetFillColor('lightred'); } else { $bplot->SetFill(false); } $bplot->SetLineWeight(1 * $k); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } $graph->Add($bplot); } } else { if ($type == 'line') { // Setup the graph. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB $graph->SetScale($axes); $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($ylabel) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitle($ylabel, 'middle'); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); } $graph->yaxis->SetLabelMargin(4 * $k); if ($percent || $show_percent) { $graph->yaxis->SetLabelFormat('%d%%'); } // Percent // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(true); if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelAngle($xlangle); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($xlabel) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitle($xlabel, 'middle'); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); } foreach ($data as $series => $rdata) { $bplot = new LinePlot($rdata); $bplot->mark->SetType($markers[$series]); $bplot->mark->SetFillColor($colours[$series]); $bplot->mark->SetWidth(4 * $k); if ($show_values) { $bplot->value->Show(); // Not if scatter $bplot->value->SetMargin(6 * $k); $bplot->value->SetColor("darkred"); $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent || $show_percent) { $bplot->value->SetFormat('%d%%'); } else { $bplot->value->SetFormat("%s"); } } // Set color for each line $bplot->SetColor($colours[$series]); $bplot->SetWeight(2 * $k); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } // Indent the X-scale so the first and last point doesn't fall on the edges $bplot->SetCenter(); $graph->Add($bplot); } } else { if ($type == 'xy' || $type == 'scatter') { // Setup the graph. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB $graph->SetScale($axes); // Setup font for axis $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); // Y-axis title if ($labels[1]) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); $graph->yaxis->SetTitle($labels[1], 'middle'); } $graph->yaxis->SetLabelMargin(4 * $k); if ($percent || $show_percent) { $graph->yaxis->SetLabelFormat('%d%%'); } // Percent // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(true); // Just let the maximum be autoscaled $graph->yaxis->scale->SetAutoMin(0); if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); // mPDF 2.5 Corrects labelling of x-axis // $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelAngle(50); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($labels[0]) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); $graph->xaxis->SetTitle($labels[0], 'middle'); } // Create the bar plot // SPLINES if ($splines && $type == 'xy') { $spline = new Spline($data[0], $data[1]); list($newx, $newy) = $spline->Get(100); } else { $newx = $data[0]; $newy = $data[1]; } if ($type == 'xy') { // LINE PLOT $bplot = new LinePlot($newy, $newx); // Set color for each line $bplot->SetColor($fills[0]); $bplot->SetWeight(4 * $k); if ($bandw) { $bplot->SetShadow("gray5"); } $graph->Add($bplot); } // SCATTER PLOT $cplot = new ScatterPlot($data[1], $data[0]); $cplot->mark->SetType($markers[0]); $cplot->mark->SetFillColor($fills[0]); $cplot->mark->SetWidth(8 * $k); if ($show_values) { // mPDF 2.5 if ($type == 'xy') { $cplot->value->Show(); } // Not if scatter $cplot->value->SetMargin(8 * $k); $cplot->value->SetColor("darkred"); $cplot->value->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k); if ($percent || $show_percent) { $cplot->value->SetFormat('%d%%'); } else { $cplot->value->SetFormat("%s"); } } // Set color for each line $cplot->SetColor($fills[0]); $cplot->SetWeight(4 * $k); if ($bandw) { $cplot->SetShadow("gray5"); } $graph->Add($cplot); } else { if ($type == 'bar') { // Setup the graph. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB $graph->SetScale($axes); // Setup y-axis $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } $graph->yaxis->SetLabelMargin(4 * $k); if ($ylabel) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitle($ylabel, 'middle'); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); } // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(false); // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelAngle($xlangle); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($xlabel) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitle($xlabel, 'middle'); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); } $group = array(); foreach ($data as $series => $dat) { $rdata = array(); foreach ($data[$series] as $row) { $rdata[] = $row; } // Create the bar plot $bplot = new BarPlot($rdata); $bplot->SetWidth(0.6); // for SINGLE?? // Setup color for gradient fill style if ($bandw) { $bplot->SetPattern($patterns[$series]); } else { $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION); } // Set color for the frame of each bar $bplot->SetColor("darkgray"); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } if ($show_values) { $bplot->value->Show(); $bplot->value->SetMargin(6 * $k); $bplot->value->SetColor("darkred"); $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent || $show_percent) { $bplot->value->SetFormat('%d%%'); } else { $bplot->value->SetFormat("%s"); } } $group[] = $bplot; } if (count($data) == 1) { $graph->Add($group[0]); } else { // Create the grouped bar plot if ($stacked) { $gbplot = new AccBarPlot($group); } else { $gbplot = new GroupBarPlot($group); } $graph->Add($gbplot); } } else { if ($type == 'horiz_bar') { $graph->SetScale($axes); $graph->Set90AndMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB // Setup y-axis $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetLabelMargin(4 * $k); $graph->yaxis->SetPos('max'); // Intersect at top of x-axis i.e. y axis is at bottom // First make the labels look right $graph->yaxis->SetLabelAlign('center', 'top'); if ($percent || $show_percent) { $graph->yaxis->SetLabelFormat('%d%%'); } $graph->yaxis->SetLabelSide(SIDE_RIGHT); $graph->yaxis->scale->SetGrace(10); // sets 10% headroom if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } // The fix the tick marks $graph->yaxis->SetTickSide(SIDE_LEFT); if ($ylabel) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitle($ylabel, 'middle'); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); // Finally setup the title $graph->yaxis->SetTitleSide(SIDE_RIGHT); // To align the title to the right use : $graph->yaxis->title->Align('right'); $graph->yaxis->title->SetAngle(0); } // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(false); // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->title->SetAngle(90); $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($xlabel) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); $graph->xaxis->SetTitle($xlabel, 'middle'); } $group = array(); foreach ($data as $series => $dat) { $rdata = array(); foreach ($data[$series] as $row) { $rdata[] = $row; } // Create the bar pot $bplot = new BarPlot($rdata); $bplot->SetWidth(0.6); // for SINGLE?? // Setup color for gradient fill style if ($bandw) { $bplot->SetPattern($patterns[$series]); } else { $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION); } // Set color for the frame of each bar $bplot->SetColor("darkgray"); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } if ($show_values) { $bplot->value->Show(); $bplot->value->SetMargin(6 * $k); $bplot->value->SetColor("darkred"); $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent || $show_percent) { $bplot->value->SetFormat('%d%%'); } else { $bplot->value->SetFormat("%s"); } } $group[] = $bplot; } if (count($data) == 1) { $graph->Add($group[0]); } else { // Create the grouped bar plot if ($stacked) { $gbplot = new AccBarPlot($group); } else { $gbplot = new GroupBarPlot($group); } $graph->Add($gbplot); } } } } } } } } if ($graph) { $graph->Stroke(_MPDF_PATH . $figure_file); $srcpath = str_replace("\\", "/", dirname(__FILE__)) . "/"; $srcpath .= $figure_file; return array('file' => $srcpath, 'w' => $w, 'h' => $h); } } return false; }
$graph = new Graph($width, 350, "auto"); $graph->SetScale("textlin"); $graph->SetMarginColor($background); $graph->img->SetMargin(40, 30, 20, 160); //Setup Frame $graph->SetFrame(true, "#ffffff"); // Setup graph title //$graph->title->Set($title); //$graph->title->SetFont(FF_FONT1, FS_BOLD); $bar_array = array(); $i = 0; foreach ($final_values as $title => $values) { $i %= count($color_list); $datay = explode(",", $values); $bplot = new BarPlot($datay); $bplot->SetWidth(0.7); $bplot->SetFillColor($color_list[$i] . "@0.5"); $bplot->SetColor($color_list[$i] . "@1"); $bplot->SetLegend($title); $bar_array[] = $bplot; $i++; } // Create the grouped bar plot $gbplot = new AccBarPlot($bar_array); $gbplot->SetShadow($color . "@0.9", 6, 5); $gbplot->SetWidth(0.6); $graph->Add($gbplot); $graph->xaxis->SetTickLabels($labelx); $graph->xaxis->title->Set($titley); $graph->yaxis->title->Set($titlex); // Adjust the legend position
while (list($_1, $_2) = mysql_fetch_array($result)) { $datax[] .= $_1; $datay[] .= $_2; } } } } } // Some data $datay = array(12, 8, 19, 3, 10, 5); $datax = array("Jan", "Feb", "Mar", "Apr", "May", "Jun"); // Create the graph. These two calls are always required $graph = new Graph(310, 200, "auto"); $graph->img->SetMargin(40, 30, 20, 40); $graph->SetScale("textlin"); $graph->SetShadow(); // Create a bar pot $bplot = new BarPlot($datay); $bplot->SetFillColor("orange"); $bplot->SetWidth(1); $graph->Add($bplot); $graph->title->Set("Example 20"); $graph->xaxis->title->Set("X-title"); $graph->yaxis->title->Set("Y-title"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetTickLabels($datax); $graph->xaxis->SetFont(FF_FONT2); // Display the graph $graph->Stroke();
/** * 设置柱状图 */ static function createcolumnar($title, $data = array(), $size = 40, $height = 100, $width = 80, $legend = array()) { //载入文件 vendor("Jpgraph.jpgraph"); vendor("Jpgraph.jpgraph_bar"); // Some data // Create the graph and setup the basic parameters $graph = new Graph($width, $height, 'auto'); $graph->img->SetMargin(40, 30, 40, 40); $graph->SetScale("textint"); $graph->SetShadow(); $graph->SetFrame(false); // No border around the graph // Add some grace to the top so that the scale doesn't // end exactly at the max value. $graph->yaxis->scale->SetGrace(20); // Setup X-axis labels //编码转化 foreach ($legend as $k => $v) { $legend[$k] = iconv('utf-8', 'gb2312', $v); } $graph->xaxis->SetTickLabels($legend); $graph->xaxis->SetFont(FF_SIMSUN); // Setup graph title ands fonts $graph->title->Set(iconv("utf-8", "gb2312", $title)); $graph->title->SetFont(FF_SIMSUN, FS_BOLD, 11); //$graph->xaxis->title->Set("Year 2002"); $graph->xaxis->title->SetFont(FF_FONT2, FS_BOLD); // Create a bar pot $bplot = new BarPlot($data); $bplot->SetFillColor("#0080C0"); $bplot->SetWidth(0.3); //$bplot->SetShadow(); // Setup the values that are displayed on top of each bar $bplot->value->Show(); // Must use TTF fonts if we want text at an arbitrary angle $bplot->value->SetFont(FF_ARIAL, FS_BOLD); $bplot->value->SetAngle(0); // Black color for positive values and darkred for negative values $bplot->value->SetColor("black", "darkred"); $graph->Add($bplot); // Finally stroke the graph $graph->Stroke(); }
function graph_group_pct($p_title = '', $p_graph_width = 350, $p_graph_height = 400) { global $enum_name, $enum_name_count; global $open_bug_count, $closed_bug_count, $resolved_bug_count; error_check($open_bug_count + $closed_bug_count + $resolved_bug_count, $p_title); $graph = new Graph(250, 400); $graph->img->SetMargin(35, 35, 35, 150); if (ON == config_get_global('jpgraph_antialias')) { $graph->img->SetAntiAliasing(); } $graph->SetScale('textlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->title->Set($p_title); $graph->xaxis->SetTickLabels($enum_name); $graph->xaxis->SetLabelAngle(90); $graph->yaxis->scale->ticks->SetDirection(-1); $p1 = new BarPlot($open_bug_count); $p1->SetFillColor('yellow'); $p1->SetWidth(0.8); $p1->SetLegend(lang_get('legend_opened')); $p2 = new BarPlot($closed_bug_count); $p2->SetFillColor('blue'); $p2->SetWidth(0.8); $p2->SetLegend(lang_get('legend_closed')); $p3 = new BarPlot($resolved_bug_count); $p3->SetFillColor('red'); $p3->SetWidth(0.8); $p3->SetLegend(lang_get('legend_resolved')); $gbplot = new GroupBarPlot(array($p1, $p2, $p3)); $graph->Add($gbplot); if (helper_show_queries()) { $graph->subtitle->Set(db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique)'); } $graph->Stroke(); }
// Setup the graph. $graph = new Graph(400, 200); $graph->img->SetMargin(60, 20, 30, 50); $graph->SetScale("textlin"); $graph->SetMarginColor("silver"); $graph->SetShadow(); // Set up the title for the graph $graph->title->Set("Example negative bars"); $graph->title->SetFont(FF_VERDANA, FS_NORMAL, 16); $graph->title->SetColor("darkred"); // Setup font for axis $graph->xaxis->SetFont(FF_VERDANA, FS_NORMAL, 10); $graph->yaxis->SetFont(FF_VERDANA, FS_NORMAL, 10); // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(false); // Setup X-axis labels $graph->xaxis->SetTickLabels($datax); $graph->xaxis->SetLabelAngle(50); // Set X-axis at the minimum value of Y-axis (default will be at 0) $graph->xaxis->SetPos("min"); // "min" will position the x-axis at the minimum value of the Y-axis // Create the bar pot $bplot = new BarPlot($datay); $bplot->SetWidth(0.6); // Setup color for gradient fill style $bplot->SetFillGradient("navy", "steelblue", GRAD_MIDVER); // Set color for the frame of each bar $bplot->SetColor("navy"); $graph->Add($bplot); // Finally send the graph to the browser $graph->Stroke();
function metric_as_graph($result, $xaxis, $metric, $system, $start_date, $end_date) { set_time_limit(900); $myresult = $result; $nrows = 0; $xmax = 0; while ($myresult->fetchInto($row)) { $keys = array_keys($row); foreach ($keys as $key) { $rawdata[$nrows][$key] = $row[$key]; } $nrows++; } if ($xaxis == 'nproc') { for ($i = 0; $i <= nprocs($system); $i++) { $x[$i] = ""; $y[$i] = ""; $min[$i] = ""; $max[$i] = ""; $stddev[$i] = ""; $max[$i] = ""; $ysigma[2 * $i] = ""; $ysigma[2 * $i + 1] = ""; } } if ($metric == 'jobcount') { for ($i = 0; $i < $nrows; $i++) { $x[$i] = $rawdata[$i][0]; if ($xaxis == 'nproc') { if ($x[$i] > $xmax) { $xmax = $x[$i]; } $y[$x[$i]] = $rawdata[$i][1]; } else { $y[$i] = $rawdata[$i][1]; } } } elseif ($metric == 'cpuhours' || $metric == 'xfactor' || $metric == 'users' || $metric == 'groups') { for ($i = 0; $i < $nrows; $i++) { $x[$i] = $rawdata[$i][0]; if ($xaxis == 'nproc') { if ($x[$i] > $xmax) { $xmax = $x[$i]; } $y[$x[$i]] = $rawdata[$i][2]; } else { $y[$i] = $rawdata[$i][2]; } } } elseif ($metric == 'backlog') { for ($i = 0; $i < $nrows; $i++) { $x[$i] = $rawdata[$i][0]; if ($xaxis == 'nproc') { if ($x[$i] > $xmax) { $xmax = $x[$i]; } $y[$x[$i]] = time_to_hrs($rawdata[$i][3]); $max[$x[$i]] = time_to_hrs($rawdata[$i][2]); } else { $y[$i] = time_to_hrs($rawdata[$i][3]); $max[$i] = time_to_hrs($rawdata[$i][2]); } } } else { for ($i = 0; $i < $nrows; $i++) { $x[$i] = $rawdata[$i][0]; if ($xaxis == 'nproc') { if ($x[$i] > $xmax) { $xmax = $x[$i]; } $y[$x[$i]] = $rawdata[$i][4]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $y[$x[$i]])) { $y[$x[$i]] = time_to_hrs($y[$x[$i]]); } $min[$x[$i]] = $rawdata[$i][2]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $min[$x[$i]])) { $min[$x[$i]] = time_to_hrs($min[$x[$i]]); } $max[$x[$i]] = $rawdata[$i][3]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $max[$x[$i]])) { $max[$x[$i]] = time_to_hrs($max[$x[$i]]); } $stddev[$x[$i]] = $rawdata[$i][5]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $stddev[$x[$i]])) { $stddev[$x[$i]] = time_to_hrs($stddev[$x[$i]]); } $ysigma[2 * $x[$i]] = $y[$x[$i]] - $stddev[$x[$i]]; if ($ysigma[2 * $x[$i]] < 0.0) { $ysigma[2 * $x[$i]] = 0.0; } $ysigma[2 * $x[$i] + 1] = $y[$x[$i]] + $stddev[$x[$i]]; } else { $y[$i] = $rawdata[$i][4]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $y[$i])) { $y[$i] = time_to_hrs($y[$i]); } $min[$i] = $rawdata[$i][2]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $min[$i])) { $min[$i] = time_to_hrs($min[$i]); } $max[$i] = $rawdata[$i][3]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $max[$i])) { $max[$i] = time_to_hrs($max[$i]); } $stddev[$i] = $rawdata[$i][5]; if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $stddev[$i])) { $stddev[$i] = time_to_hrs($stddev[$i]); } $ysigma[2 * $i] = $y[$i] - $stddev[$i]; if ($ysigma[2 * $i] < 0.0) { $ysigma[2 * $i] = 0.0; } $ysigma[2 * $i + 1] = $y[$i] + $stddev[$i]; } } } $cache = APACHE_CACHE_DIR; if (!file_exists("/tmp/" . $cache)) { mkdir("/tmp/" . $cache, 0750); } $plot = $system . "-" . $metric . "_vs_" . $xaxis . "-" . $start_date . "-" . $end_date . ".png"; // $graph = new graph(640,480,$plot,2,0); $graph = new graph(800, 600, $plot, 2, 0); $graph->img->SetMargin(75, 30, 30, 75); if ($xaxis == 'nproc') { $graph->SetScale("linlin"); //$graph->xaxis->SetAutoMax(nprocs($system)); } else { $graph->SetScale("textlin"); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetTickLabels($x); } $graph->xaxis->title->Set($xaxis); $graph->yaxis->title->Set($metric . units($metric)); if ($metric == "walltime_acc" || $metric == "cpu_eff") { $graph->yscale->SetAutoMax(1.1); } elseif ($metric == "xfactor") { $graph->yscale->SetAutoMin(1.0); } if ($metric != "jobcount" && $metric != "cpuhours" && $metric != "backlog" && $metric != "xfactor" && $metric != "users" && $metric != "groups") { $maxbar = new BarPlot($max); $maxbar->SetWidth(1.0); $maxbar->SetFillColor("gray"); $maxbar->SetLegend("Maximum"); $graph->Add($maxbar); } else { if ($metric == "backlog") { $maxbar = new BarPlot($max); $maxbar->SetWidth(1.0); $maxbar->SetFillColor("gray"); $maxbar->SetLegend("CPU Hours"); $graph->Add($maxbar); } } $ybar = new BarPlot($y); $ybar->SetWidth(1.0); if ($metric != "jobcount" && $metric != "cpuhours" && $metric != "backlog" && $metric != "xfactor" && $metric != "users" && $metric != "groups") { $ybar->SetLegend("Mean"); } else { if ($metric == "backlog") { $ybar->SetLegend("Queue Hours"); } } $graph->Add($ybar); if ($metric != "jobcount" && $metric != "cpuhours" && $metric != "backlog" && $metric != "xfactor" && $metric != "users" && $metric != "groups") { $minbar = new BarPlot($min); $minbar->SetWidth(1.0); $minbar->SetFillColor("white"); $minbar->SetLegend("Minimum"); $graph->Add($minbar); $errbars = new ErrorPlot($ysigma); $errbars->SetColor("red"); //$errbars->SetCenter(); $errbars->SetWeight(2); $errbars->SetLegend("Std.Dev."); $graph->Add($errbars); } $graph->Stroke(); $imgurl = $cache . rawurlencode($plot); echo "<img src=\"" . $imgurl . "\">\n"; }
$graph4->yaxis->title->Set('time(nano-sec)'); $graph4->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph4->ygrid->SetColor('black'); $graph4->yaxis->SetTitleMargin(45); $graph4->yaxis->scale->SetGrace(30); // TITRE: texte $graph4->title->Set("Mesuring latency Mod operation (nano-sec)"); // TITRE: marge et apparence $graph4->title->SetFont(FF_FONT1, FS_BOLD, 11); // Couleurs et transparence par histogramme $bplot4 = new BarPlot($data5); $bplot4->value->Show(); $bplot4->SetFillColor('blue'); $bplot4->value->SetFormat('%01.3f'); $bplot4->value->SetColor("black", "darkred"); $bplot4->SetShadow('black'); $bplot4->SetWidth(0.3); $graph4->Add($bplot4); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(10, 10, 10, 10); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetBackgroundImage('../fond.png'); $mgraph->AddMix($graph, 0, 0, 85); $mgraph->AddMix($graph1, 0, 270, 85); $mgraph->AddMix($graph2, 0, 540, 85); $mgraph->AddMix($graph3, 0, 810, 85); $mgraph->AddMix($graph4, 0, 1080, 85); $mgraph->Stroke();
$months = $gDateLocale->GetShortMonth(); srand((double) microtime() * 1000000); for ($i = 0; $i < 25; ++$i) { $databary[] = rand(1, 50); $databarx[] = $months[$i % 12]; } // New graph with a drop shadow $graph = new Graph(300, 200, 'auto'); $graph->SetShadow(); // Use a "text" X-scale $graph->SetScale("textlin"); // Specify X-labels $graph->xaxis->SetTickLabels($databarx); $graph->xaxis->SetTextLabelInterval(1); $graph->xaxis->SetTextTickInterval(3); // Set title and subtitle $graph->title->Set("Bar tutorial example 5"); // Use built in font $graph->title->SetFont(FF_FONT1, FS_BOLD); // Create the bar plot $b1 = new BarPlot($databary); $b1->SetLegend("Temperature"); $b1->SetWidth(0.4); // The order the plots are added determines who's ontop $graph->Add($b1); // Finally output the image $graph->Stroke(); ?>