/** * 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(); }
public function renderGraph() { require_once 'libs/jpgraph/jpgraph.php'; require_once 'libs/jpgraph/jpgraph_bar.php'; $graph = new Graph($this->_controllerAction->getRequest()->getParam('type') == 'month' ? 400 : 300, 200, 'auto'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->SetScale("textlin"); $graph->img->SetMargin(0, 30, 20, 40); $graph->yaxis->scale->SetGrace(20); $graph->yaxis->HideLabels(); $graph->yaxis->HideTicks(); $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5'); $labelsy = array(); $datay = array(); switch ($this->_controllerAction->getRequest()->getParam('type')) { case 'month': $this->_populateMonthData($labelsy, $datay); break; case 'year': $this->_populateYearData($labelsy, $datay); break; default: $this->_populateWeekData($labelsy, $datay); } $graph->xaxis->SetTickLabels($labelsy); $bplot = new BarPlot($datay); $bplot->SetFillGradient("navy", "lightsteelblue", GRAD_WIDE_MIDVER); $bplot->value->Show(); $bplot->value->SetFormat('%d'); $graph->Add($bplot); $graph->Stroke(); }
public function renderGraph() { require_once 'libs/jpgraph/jpgraph.php'; require_once 'libs/jpgraph/jpgraph_bar.php'; require_once 'libs/jpgraph/jpgraph_line.php'; $graph = new Graph(300, 200, 'auto'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->SetScale("textlin"); $graph->SetY2Scale("lin"); $graph->img->SetMargin(0, 30, 20, 65); $graph->yaxis->HideLabels(); $graph->yaxis->HideTicks(); $graph->yaxis->scale->SetGrace(20); $graph->y2axis->SetColor("black", "red"); $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5'); $labelsy = array(); $datay = array(); $datay2 = array(); switch ($this->_controllerAction->getRequest()->getParam('type')) { case 'year': $this->_populateYearData($labelsy, $datay, $datay2); break; default: $this->_populateWeekData($labelsy, $datay, $datay2); } $graph->xaxis->SetTickLabels($labelsy); $locale = Zend_Registry::get('Zend_Locale'); if ($locale == 'ja') { // the ttf file for FF_MINCHO is already encoded in utf-8 $legend1 = $this->view->translate('Trusted sites'); $legend2 = $this->view->translate('Sites per user'); } else { // default ttf files are latin-1 encoded $legend1 = utf8_decode($this->view->translate('Trusted sites')); $legend2 = utf8_decode($this->view->translate('Sites per user')); } $bplot = new BarPlot($datay); $bplot->setLegend($legend1); $bplot->SetFillGradient("navy", "lightsteelblue", GRAD_WIDE_MIDVER); $bplot->value->Show(); $bplot->value->SetFormat('%d'); $p1 = new LinePlot($datay2); $p1->SetColor("red"); $p1->SetLegend($legend2); $graph->Add($bplot); $graph->AddY2($p1); $graph->legend->SetLayout(LEGEND_HOR); if ($locale == 'ja') { $graph->legend->setFont(FF_MINCHO, FS_NORMAL); } $graph->legend->Pos(0.5, 0.99, "center", "bottom"); $graph->Stroke(); }
function LineGraph($w, $h, $title, $data1, $data2, $datax, $output) { // Create the graph. These two calls are always required $graph = new Graph($w, $h, "auto"); $graph->SetScale("textlin"); $graph->SetMarginColor('white'); $graph->SetFrame(true); // Adjust the margin $graph->img->SetMargin(40, 100, 20, 40); $graph->SetShadow(false); // Create the linear plot $lineplot = new LinePlot($data1); $lineplot->SetWeight(2); $lineplot->SetColor("blue"); $lineplot->mark->SetType(MARK_DIAMOND); $lineplot->mark->SetWidth(5); $lineplot->mark->SetFillColor('blue'); $lineplot->value->SetMargin(-20); $lineplot->value->show(); $lineplot->value->SetColor('blue'); $lineplot->value->SetFormat('%0.0f'); $lineplot->SetLegend($_SESSION[Tahun1]); $lineplot2 = new LinePlot($data2); $lineplot2->SetColor("green"); $lineplot2->SetWeight(2); $lineplot2->mark->SetType(MARK_FILLEDCIRCLE); $lineplot2->mark->SetWidth(3); $lineplot2->mark->SetFillColor('green'); $lineplot2->value->show(); $lineplot2->value->SetColor('darkgreen'); $lineplot2->value->SetFormat('%0.0f'); $lineplot2->SetLegend($_SESSION[Tahun2]); // Add the plot to the graph $graph->Add($lineplot); $graph->xaxis->SetTickLabels($datax); $graph->title->Set($title); $graph->xaxis->title->Set(""); $graph->yaxis->title->Set(""); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->Add($lineplot2); $graph->legend->SetShadow(false); $graph->legend->SetFillColor('white'); $graph->legend->SetPos(0.01, 0.88, 'right', 'center'); // Display the graph $graph->Stroke($output); }
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; }
} } // require_once 'ossim_conf.inc'; $conf = $GLOBALS["CONF"]; $jpgraph = $conf->get_conf("jpgraph_path"); require_once "{$jpgraph}/jpgraph.php"; require_once "{$jpgraph}/jpgraph_line.php"; // Setup the graph. $graph = new Graph(600, 300, "auto"); $graph->SetScale("textlin"); $graph->SetMargin(100, 10, 20, 86); $graph->SetMarginColor("#fafafa"); $graph->xaxis->SetTickLabels(array(_("Ene"), _("Feb"), _("Mar"), _("Apr"), _("May"), _("Jun"), _("Jul"), _("Ago"), _("Sep"), _("Oct"), _("Nov"), _("Dic"))); $graph->SetColor("#fafafa"); $graph->SetFrame(true, '#fafafa', 0); $dplot[0] = new LinePLot($data1['value']); $dplot[1] = new LinePLot($data2['value']); $dplot[2] = new LinePLot($data3['value']); $dplot[3] = new LinePLot($data4['value']); $dplot[4] = new LinePLot($data5['value']); $dplot[0]->SetColor(COLOR1); $dplot[0]->SetLegend('QoS-Impact'); $dplot[0]->mark->SetType(MARK_SQUARE); $dplot[0]->mark->SetColor(COLOR1); $dplot[0]->mark->SetFillColor(COLOR1); // $dplot[1]->SetColor(COLOR2); $dplot[1]->SetLegend('Information-Leak-Impact'); $dplot[1]->mark->SetType(MARK_UTRIANGLE); $dplot[1]->mark->SetColor(COLOR2);
/** * 横柱图 * */ function createhorizoncolumnar($title, $subtitle, $data = array(), $size = 40, $height = 100, $width = 80, $legend = array()) { vendor("Jpgraph.jpgraph"); vendor("Jpgraph.jpgraph_bar"); $datay = $data; $datax = $legend; //编码转化 foreach ($datax as $k => $v) { $datax[$k] = iconv('utf-8', 'gb2312', $v); } // Size of graph $count = count($datay); $addheight = 0; if ($count > 10) { $addheight = ($count - 10) * 20; } $height = $height + $addheight; // Set the basic parameters of the graph $graph = new Graph($width, $height, 'auto'); $graph->SetScale("textlin"); // No frame around the image $graph->SetFrame(false); $graph->SetFrame(false, '#ffffff', 0); //去掉周围的边框 // Rotate graph 90 degrees and set margin $graph->Set90AndMargin(70, 10, 50, 30); // Set white margin color $graph->SetMarginColor('white'); // Use a box around the plot area $graph->SetBox(); // Use a gradient to fill the plot area $graph->SetBackgroundGradient('white', 'white', GRAD_HOR, BGRAD_PLOT); // Setup title $graph->title->Set(iconv('utf-8', 'gb2312', "{$title}")); $graph->title->SetFont(FF_SIMSUN, FS_BOLD, 12); $graph->subtitle->Set("(" . iconv('utf-8', 'gb2312', $subtitle) . ")"); $graph->subtitle->SetFont(FF_SIMSUN, FS_NORMAL, 10); // Setup X-axis $graph->xaxis->SetTickLabels($datax); $graph->xaxis->SetFont(FF_SIMSUN, FS_NORMAL, 10); // Some extra margin looks nicer $graph->xaxis->SetLabelMargin(10); // Label align for X-axis $graph->xaxis->SetLabelAlign('right', 'center'); // Add some grace to y-axis so the bars doesn't go // all the way to the end of the plot area $graph->yaxis->scale->SetGrace(10); // We don't want to display Y-axis $graph->yaxis->Hide(); // Now create a bar pot $bplot = new BarPlot($datay); //$bplot->SetShadow(); //You can change the width of the bars if you like //$bplot->SetWidth(0.5); // Set gradient fill for bars $bplot->SetFillGradient('blue', '#0080C0', GRAD_HOR); // We want to display the value of each bar at the top $bplot->value->Show(); $bplot->value->SetFont(FF_ARIAL, FS_NORMAL, 7); $bplot->value->SetAlign('left', 'center'); $bplot->value->SetColor("black"); $bplot->value->SetFormat('%.0f'); //$bplot->SetValuePos('max'); // Add the bar to the graph $graph->Add($bplot); // Add some explanation text $txt = new Text(''); $txt->SetPos(130, 399, 'center', 'bottom'); $txt->SetFont(FF_COMIC, FS_NORMAL, 8); $graph->Add($txt); // .. and stroke the graph $graph->Stroke(); }
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; // Some data $datay = array(7, 19, 11, 4, 20); // Create the graph and setup the basic parameters $graph = new Graph(300, 200, 'auto'); $graph->img->SetMargin(40, 30, 40, 50); $graph->SetScale("textint"); $graph->SetFrame(true, 'blue', 1); $graph->SetColor('lightblue'); $graph->SetMarginColor('lightblue'); // Setup X-axis labels $a = $gDateLocale->GetShortMonth(); $graph->xaxis->SetTickLabels($a); $graph->xaxis->SetFont(FF_FONT1); $graph->xaxis->SetColor('darkblue', 'black'); // Setup "hidden" y-axis by given it the same color // as the background (this could also be done by setting the weight // to zero) $graph->yaxis->SetColor('lightblue', 'darkblue'); $graph->ygrid->SetColor('white'); // Setup graph title ands fonts $graph->title->Set('Using grace = 50%'); $graph->title->SetFont(FF_FONT2, FS_BOLD); $graph->xaxis->SetTitle('Year 2002', 'center'); $graph->xaxis->SetTitleMargin(10); $graph->xaxis->title->SetFont(FF_FONT2, FS_BOLD); // Add some grace to the top so that the scale doesn't
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; }
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; }
*/ // Setup font for axis $graph->xaxis->SetFont(FF_FONT1, FS_NORMAL, 8); $graph->yaxis->SetFont(FF_FONT1, FS_NORMAL, 11); // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(false); // Setup X-axis labels $graph->xaxis->SetTickLabels($datax); if ($gorientation == "v") { $graph->img->SetAngle(90); $graph->Set90AndMargin(120, 40, 40, 40); } else { $graph->xaxis->SetLabelAngle(90); } //Setup Frame $graph->SetFrame(true, "#fafafa"); //$graph->SetFrame(false); // Create the bar pot $bplot = new BarPlot($datay); $bplot->SetWidth(0.6); // Setup color for gradient fill style $bplot->SetFillColor($color . "@0.3"); //$bplot->SetShadow($color."@0.7",5,5); // Set color for the frame of each bar $bplot->SetColor($color . "@1"); $graph->Add($bplot); // Finally send the graph to the browser $graph->Stroke(); unset($graph); $geoloc->close(); ?>
/** * Runs the phpOpenTracker API call. * * @param array $parameters * @return mixed * @access public */ function run($parameters) { global $c; $parameters['interval'] = isset($parameters['interval']) ? $parameters['interval'] : false; $parameters['month_names'] = isset($parameters['month_names']) ? $parameters['month_names'] : false; if (!$parameters['month_names']) { $parameters['month_names'] = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); } $timestamp = time(); $steps = array('hour' => 3600, 'day' => 86400, 'week' => 604800, 'month' => 2592000, 'year' => 31536000); $starttitle = ''; $endtitle = ''; switch ($parameters['interval']) { case 'hour': $starthour = $hour = date('H', $parameters['start']); $endhour = date('H', $parameters['end']); $starttitle .= $starthour . ':00h '; $endtitle .= $endhour . ':59h '; case 'day': $startday = $day = date('d', $parameters['start']); $endday = date('d', $parameters['end']); $starttitle .= $startday . '. '; $endtitle .= $endday . '. '; case 'week': $week = date('W', $parameters['start']) + 2; case 'month': $startmonth = $month = date('m', $parameters['start']); $endmonth = date('m', $parameters['end']); $starttitle .= $parameters['month_names'][$startmonth - 1] . ' '; $endtitle .= $parameters['month_names'][$endmonth - 1] . ' '; case 'year': $startyear = $year = date('Y', $parameters['start']); $endyear = date('Y', $parameters['end']); $starttitle .= $startyear; $endtitle .= $endyear; } $title = $starttitle . ' - ' . $endtitle . ' in ' . $parameters['interval'] . "s."; $disp = true; $correct = 0; if ($parameters['interval'] == 'week') { $correct = 86400; } for ($start = $parameters['start']; $start < $parameters['end']; $start += $steps[$parameters['interval']]) { if ($parameters['interval'] == 'month') { $steps['month'] = $steps['day'] * date('t', $_start); } $end = $start + $steps[$parameters['interval']] - 1; if ($start <= $timestamp) { $apiCallParameters = array('client_id' => $parameters['client_id'], 'start' => $start + $correct, 'end' => $end + $correct, 'constraints' => $parameters['constraints'], 'interval' => ''); for ($j = 0; $j < count($parameters["what"]); $j++) { $y[$j][] = phpOpenTracker::get(array_merge(array('api_call' => $parameters["what"][$j]), $apiCallParameters)); } } else { for ($j = 0; $j < count($parameters["what"]); $j++) { $y[$j][] = 0; } } switch ($parameters['interval']) { case 'hour': $x_label[] = date('H', mktime($hour, 0, 0, $startmonth, $startday, $startyear)) . ':00'; $disp = !$disp; $hour++; break; case 'week': $x_label[] = date('W', mktime(0, 0, 0, 1, ($week - 2) * 7, $startyear)); $week++; break; case 'day': $x_label[] = date('d', mktime(0, 0, 0, $startmonth, $day, $startyear)); $day++; break; case 'month': $x_label[] = date('m', mktime(0, 0, 0, $month, 1, $startyear)); $month++; break; case 'year': $x_label[] = date('Y', mktime(0, 0, 0, 1, 1, $year)); $year++; break; } } if ($y == null) { $apiCallParameters = array('client_id' => $parameters['client_id'], 'start' => $start, 'end' => $end, 'constraints' => $parameters['constraints']); for ($j = 0; $j < count($parameters["what"]); $j++) { $y[$j][] = phpOpenTracker::get(array_merge(array('api_call' => $parameters["what"][$j]), $apiCallParameters)); } $x_label[] = ''; $title = "Total"; } if ($parameters['interval'] == 'hour') { $angle = 50; } else { $angle = 0; } $x_label = $this->clearLabels($x_label, $parameters); $graph = new Graph($parameters['width'], $parameters['height'], 'auto'); $graph->img->SetMargin(40, 10, 20, 10); $graph->SetScale('textlin'); $graph->SetMarginColor('white'); $graph->SetFrame(0); $graph->xgrid->Show(); for ($j = 0; $j < count($parameters["what"]); $j++) { $plot[$j] = new BarPlot($y[$j]); $plot[$j]->SetFillColor($parameters["whatcolors"][$j]); $plot[$j]->SetShadow(); $plot[$j]->SetWeight(0); } $gbarplot = new GroupBarPlot($plot); $gbarplot->SetWidth(0.6); $graph->add($gbarplot); $graph->xaxis->SetTickLabels($x_label); if ($c["usettf"]) { $graph->xaxis->SetLabelAngle($angle); } if ($c["usettf"]) { $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); } if ($c["usettf"]) { $graph->xaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8); } $graph->yaxis->SetColor('black'); if ($c["usettf"]) { $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); } if ($c["usettf"]) { $graph->yaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8); } $graph->title->Set($title); if ($c["usettf"]) { $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 8); } $graph->img->SetAntiAliasing("white"); $graph->Stroke(); }
<?php require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; $data1y = array(47, 80, 40, 116); $graph = new Graph(400, 300, 'auto'); $graph->SetScale('textlin'); $theme_class = new AquaTheme(); $graph->SetTheme($theme_class); // after setting theme, you can change details as you want $graph->SetFrame(true, 'lightgray'); // set frame visible $graph->xaxis->SetTickLabels(array('A', 'B', 'C', 'D')); // change xaxis lagels $graph->title->Set("Theme Example"); // add title // add barplot $bplot = new BarPlot($data1y); $graph->Add($bplot); // you can change properties of the plot only after calling Add() $bplot->SetWeight(0); $bplot->SetFillGradient('#FFAAAA:0.7', '#FFAAAA:1.2', GRAD_VER); $graph->Stroke();
public static function lineGraph_1($level_data, $level_name, $title, $project_id) { require_once '../app/classes/jpgraph/jpgraph.php'; require_once '../app/classes/jpgraph/jpgraph_line.php'; // Setup the graph $graph = new Graph(1500, 500); $graph->SetMarginColor('white'); $graph->SetScale("textlin"); $graph->SetFrame(false); $graph->SetMargin(30, 50, 30, 30); $graph->title->Set($title); $graph->title->SetFont(FF_CHINESE, FS_NORMAL, 11); $graph->yaxis->HideZeroLabel(); $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5'); $graph->xgrid->Show(); $graph->xaxis->SetTickLabels(array_keys($level_data[0])); $i = 0; foreach ($level_data as $data) { $p1 = new LinePlot(array_values($data)); $p1->SetLegend($level_name[$i++]); $graph->Add($p1); } $graph->legend->SetShadow('gray@0.4', 5); $graph->legend->SetPos(0.1, 0.1, 'right', 'top'); // Output line $date = date('H_i_s'); $stamp = rand(100, 900); $fileName = './tmp/' . $project_id . $date . '_' . $stamp . '.jpeg'; $graph->Stroke($fileName); return $fileName; }
function graph_cumulative_bydate($p_metrics, $p_graph_width = 300, $p_graph_height = 380) { $t_graph_font = graph_get_font(); error_check(is_array($p_metrics) ? count($p_metrics) : 0, lang_get('cumulative') . ' ' . lang_get('by_date')); foreach ($p_metrics as $i => $vals) { if ($i > 0) { $plot_date[] = $i; $reported_plot[] = $p_metrics[$i][0]; $resolved_plot[] = $p_metrics[$i][1]; $still_open_plot[] = $p_metrics[$i][2]; } } $graph = new Graph($p_graph_width, $p_graph_height); $graph->img->SetMargin(40, 40, 40, 170); $graph->img->SetAntiAliasing(); $graph->SetScale('linlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->title->Set(lang_get('cumulative') . ' ' . lang_get('by_date')); $graph->title->SetFont($t_graph_font, FS_BOLD); $graph->legend->Pos(0.05, 0.9, 'right', 'bottom'); $graph->legend->SetShadow(false); $graph->legend->SetFillColor('white'); $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->SetFont($t_graph_font); $graph->yaxis->scale->ticks->SetDirection(-1); $graph->yaxis->SetFont($t_graph_font); if (FF_FONT2 <= $t_graph_font) { $graph->xaxis->SetLabelAngle(60); } else { $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts } $graph->xaxis->SetLabelFormatCallback('graph_date_format'); $graph->xaxis->SetFont($t_graph_font); $p1 = new LinePlot($reported_plot, $plot_date); $p1->SetColor('blue'); $p1->SetCenter(); $p1->SetLegend(lang_get('legend_reported')); $graph->Add($p1); $p3 = new LinePlot($still_open_plot, $plot_date); $p3->SetColor('red'); $p3->SetCenter(); $p3->SetLegend(lang_get('legend_still_open')); $graph->Add($p3); $p2 = new LinePlot($resolved_plot, $plot_date); $p2->SetColor('black'); $p2->SetCenter(); $p2->SetLegend(lang_get('legend_resolved')); $graph->Add($p2); if (ON == config_get('show_queries_count')) { $graph->subtitle->Set(db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)'); $graph->subtitle->SetFont($t_graph_font, FS_NORMAL, 8); } $graph->Stroke(); }
$graph2->yaxis->SetColor('red'); $graph2->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph2->yaxis->SetLabelMargin(0); $graph2->yaxis->scale->SetAutoMin(0); $line2 = new LinePlot($data_windspeed, $xdata); $line2->SetStepStyle(); $line2->SetColor('red'); $graph2->Add($line2); //------------------------------------------------------------------ // Setup the wind temp graph //------------------------------------------------------------------ $graph3 = new Graph(WIND_WIDTH - 30, WIND_HEIGHT); $graph3->SetScale('datlin'); $graph3->Set90AndMargin(5, 20, 70, 30); $graph3->SetMarginColor(BKG_COLOR); $graph3->SetFrame(true, 'white', 0); $graph3->SetBox(); $graph3->title->Set('Temperature'); $graph3->title->SetColor('black'); $graph3->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph3->title->SetMargin(5); $graph3->xaxis->HideLabels(); $graph3->xgrid->Show(); $graph3->yaxis->SetLabelAngle(90); $graph3->yaxis->SetColor('black'); $graph3->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph3->yaxis->SetLabelMargin(0); $graph3->yaxis->scale->SetAutoMin(-10); $line3 = new LinePlot($data_windtemp, $xdata); $line3->SetStepStyle(); $line3->SetColor('black');
function graph_bydate($p_metrics, $p_labels, $p_title, $p_graph_width = 300, $p_graph_height = 380) { $t_graph_font = graph_get_font(); error_check(is_array($p_metrics) ? count($p_metrics) : 0, lang_get('by_date')); $graph = new Graph($p_graph_width, $p_graph_height); $graph->img->SetMargin(40, 140, 40, 100); if (ON == config_get_global('jpgraph_antialias')) { $graph->img->SetAntiAliasing(); } $graph->SetScale('linlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->title->Set($p_title . ' ' . lang_get('by_date')); $graph->title->SetFont($t_graph_font, FS_BOLD); $graph->legend->Pos(0.01, 0.05, 'right', 'top'); $graph->legend->SetShadow(false); $graph->legend->SetFillColor('white'); $graph->legend->SetLayout(LEGEND_VERT); $graph->legend->SetFont($t_graph_font); $graph->yaxis->scale->ticks->SetDirection(-1); $graph->yaxis->SetFont($t_graph_font); $graph->yaxis->scale->SetAutoMin(0); if (FF_FONT2 <= $t_graph_font) { $graph->xaxis->SetLabelAngle(60); } else { $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts } $graph->xaxis->SetLabelFormatCallback('graph_date_format'); $graph->xaxis->SetFont($t_graph_font); $t_line_colours = config_get('graph_colors'); $t_count_colours = count($t_line_colours); $t_lines = count($p_metrics) - 1; $t_line = array(); for ($i = 1; $i <= $t_lines; $i++) { $t_line[$i] = new LinePlot($p_metrics[$i], $p_metrics[0]); $t_line[$i]->SetColor($t_line_colours[$i % $t_count_colours]); $t_line[$i]->SetCenter(); $t_line[$i]->SetLegend(lang_get_defaulted($p_labels[$i])); $graph->Add($t_line[$i]); } if (helper_show_queries()) { $graph->subtitle->Set(db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)'); $graph->subtitle->SetFont($t_graph_font, FS_NORMAL, 8); } $graph->Stroke(); }
private function createBarGraph($xdata, $data1, $ytitle) { // Create the graph. $graph = new Graph($this->width, $this->height, "auto"); $graph->SetScale("textlin"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->SetFrame(false); if ($this->shadow) { $graph->SetShadow(); } // Create the bar plot $arrPos = array(); $arrNeg = array(); foreach ($data1 as &$value) { if ($value >= 0) { array_push($arrPos, $value); array_push($arrNeg, 0); } else { array_push($arrPos, 0); array_push($arrNeg, $value); } } $bplotPos = new BarPlot($arrPos); // First group positive $bplotPos->SetFillColor('#ababab'); // color for positive '#ababab' Kulturplanner #8aa571 $bplotNeg = new BarPlot($arrNeg); // second group negative $bplotNeg->SetFillColor("#cc00cc"); //color for negative prologiq "#cc00cc" $gbplot = new AccBarPlot(array($bplotPos, $bplotNeg)); $gbplot->value->Show(); $gbplot->value->SetFormat('%d'); $gbplot->value->SetColor("black"); $gbplot->SetValuePos('center'); //$gbplot->SetLegend(Prado::localize($this->legend)); // ... and add it to the graph $graph->Add($gbplot); $graph->xaxis->title->Set($this->title); $graph->xaxis->SetTickLabels($xdata); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->Set($ytitle); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->SetLabelMargin(5); $graph->yaxis->scale->SetGrace(10); $graph->yaxis->HideZeroLabel(); $graph->ygrid->SetFill(true, '#f2f2f2@0.6', '#cacaca@0.6'); return $graph; }
$dataJum = array(); $dataTh = array(); $tahun = $_POST['tahun']; $query = "SELECT count(*) AS jumlah, monthname(tgl_pemeriksaan) as tahun FROM t_kimiaklinik where year(tgl_pemeriksaan)='{$tahun}' group by month(tgl_pemeriksaan)"; $hasil = mysql_query($query); while ($data = mysql_fetch_array($hasil)) { array_unshift($dataJum, $data['jumlah']); array_unshift($dataTh, $data['tahun']); } $graph = new Graph(500, 300, "auto"); $graph->SetScale("textlin"); // menampilkan plot batang dari data $bplot = new BarPlot($dataJum); $bplot->value->show(); $bplot->value->SetFormat('%d'); $bplot->SetValuePos('max'); $graph->Add($bplot); // menampilkan plot garis dari data $lineplot = new LinePlot($dataJum); $graph->Add($lineplot); $graph->SetFrame(true); $graph->img->SetMargin(50, 20, 20, 50); $graph->title->Set("Grafik Jumlah Lab Kimia Klinik"); $graph->xaxis->title->Set("Bulan"); $graph->yaxis->title->Set("Jumlah"); $graph->xaxis->SetTickLabels($dataTh); $graph->title->SetFont(FF_FONT1, FS_BOLD); $lineplot->SetColor("red"); $bplot->SetFillColor("blue"); $graph->SetShadow(); $graph->Stroke();
function graphHistogram($pDB, $smarty, $module_name, $local_templates_dir) { include "libs/jpgraph/jpgraph.php"; include "libs/jpgraph/jpgraph_line.php"; // Tipo de llamada Entrante o Saliente if (!isset($_GET['tipo'])) { return ''; } $sTipoLlamada = $_GET['tipo']; if (!in_array($sTipoLlamada, array('E', 'S'))) { return ''; } // Fechas inicial y final del rango if (!isset($_GET['fecha_ini'])) { return ''; } if (!isset($_GET['fecha_fin'])) { return ''; } $sFechaInicial = $_GET['fecha_ini']; $sFechaFinal = $_GET['fecha_fin']; $sFormatoFecha = '^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}$'; if (!ereg($sFormatoFecha, $sFechaInicial)) { return ''; } if (!ereg($sFormatoFecha, $sFechaFinal)) { return ''; } // Recuperar la lista de llamadas $arrCalls = array(); $oCalls = new paloSantoCallsHour($pDB); $arrCalls['todas'] = $oCalls->getCalls($sTipoLlamada, 'T', $sFechaInicial, $sFechaFinal); if (!is_array($arrCalls['todas'])) { return $oCalls->errMsg; } $arrCalls['exitosas'] = $oCalls->getCalls($sTipoLlamada, 'E', $sFechaInicial, $sFechaFinal); if (!is_array($arrCalls['exitosas'])) { return $oCalls->errMsg; } $arrCalls['abandonadas'] = $oCalls->getCalls($sTipoLlamada, 'A', $sFechaInicial, $sFechaFinal); if (!is_array($arrCalls['abandonadas'])) { return $oCalls->errMsg; } // Validación de la cola graficada $sQueue = ''; if (isset($_GET['queue'])) { $sQueue = $_GET['queue']; } if (!in_array($sQueue, array_keys($arrCalls['todas']))) { $sQueue = ''; } $listaVacia = array_fill(0, 24, 0); $graphdata = array(); if ($sQueue != '') { $graphdata['todas'] = $arrCalls['todas'][$sQueue]; // Por definición, siempre existe $graphdata['exitosas'] = isset($arrCalls['exitosas'][$sQueue]) ? $arrCalls['exitosas'][$sQueue] : $listaVacia; $graphdata['abandonadas'] = isset($arrCalls['abandonadas'][$sQueue]) ? $arrCalls['abandonadas'][$sQueue] : $listaVacia; } else { $graphdata['todas'] = $listaVacia; $graphdata['exitosas'] = $listaVacia; $graphdata['abandonadas'] = $listaVacia; foreach (array('todas', 'exitosas', 'abandonadas') as $k) { foreach ($arrCalls[$k] as $sQueue => $hist) { $graphdata[$k] = array_map('sumar', $graphdata[$k], $hist); } } } // Labels $datahours = array(); for ($i = 0; $i < 24; $i++) { $datahours[] = sprintf('%02d', $i); } // Setup the graph $graph = new Graph(800, 500); $graph->SetMarginColor('white'); $graph->SetScale("textlin"); $graph->SetFrame(true); $graph->SetMargin(60, 50, 30, 30); $graph->title->Set(_tr('Calls')); $graph->yaxis->HideZeroLabel(); $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5'); $graph->xgrid->Show(); $graph->xaxis->SetTickLabels($datahours); // Create the first line $p1 = new LinePlot($graphdata['todas']); $p1->SetColor("navy"); $p1->SetLegend(_tr('All')); $p1->SetWeight(7); $graph->Add($p1); // Create the second line $p2 = new LinePlot($graphdata['exitosas']); $p2->SetColor("red"); $p2->SetLegend(_tr('Completed')); $p2->SetWeight(3); $graph->Add($p2); // Create the third line $p3 = new LinePlot($graphdata['abandonadas']); $p3->SetColor("orange"); $p3->SetLegend(_tr('Abandoned')); $p3->SetWeight(3); $graph->Add($p3); $graph->legend->SetShadow('gray@0.4', 5); $graph->legend->SetPos(0.1, 0.1, 'right', 'top'); // Output line $graph->Stroke(); }
function graph_bydate($p_metrics, $p_labels, $p_title, $p_graph_width = 300, $p_graph_height = 380) { $t_graph_font = graph_get_font(); error_check(is_array($p_metrics) ? count($p_metrics) : 0, lang_get('by_date')); if (plugin_config_get('eczlibrary') == ON) { $t_metrics = array(); $t_dates = array_shift($p_metrics); //[0]; $t_cnt = count($p_metrics); foreach ($t_dates as $i => $val) { //$t_metrics[$val] for ($j = 0; $j < $t_cnt; $j++) { $t_metrics[$j][$val] = $p_metrics[$j][$i]; } } $graph = new ezcGraphLineChart(); $graph->background->color = '#FFFFFF'; $graph->xAxis = new ezcGraphChartElementNumericAxis(); for ($k = 0; $k < $t_cnt; $k++) { $graph->data[$k] = new ezcGraphArrayDataSet($t_metrics[$k]); $graph->data[$k]->label = $p_labels[$k + 1]; } $graph->xAxis->labelCallback = 'graph_date_format'; $graph->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedLabelRenderer(); $graph->xAxis->axisLabelRenderer->angle = -45; $graph->legend->position = ezcGraph::BOTTOM; $graph->legend->background = '#FFFFFF80'; $graph->driver = new ezcGraphGdDriver(); //$graph->driver->options->supersampling = 1; $graph->driver->options->jpegQuality = 100; $graph->driver->options->imageFormat = IMG_JPEG; $graph->title = $p_title . ' ' . lang_get('by_date'); $graph->options->font = $t_graph_font; $graph->renderToOutput($p_graph_width, $p_graph_height); } else { $graph = new Graph($p_graph_width, $p_graph_height); $graph->img->SetMargin(40, 140, 40, 100); if (ON == plugin_config_get('jpgraph_antialias')) { $graph->img->SetAntiAliasing(); } $graph->SetScale('linlin'); $graph->SetMarginColor('white'); $graph->SetFrame(false); $graph->title->Set($p_title . ' ' . lang_get('by_date')); $graph->title->SetFont($t_graph_font, FS_BOLD); $graph->legend->Pos(0.01, 0.05, 'right', 'top'); $graph->legend->SetShadow(false); $graph->legend->SetFillColor('white'); $graph->legend->SetLayout(LEGEND_VERT); $graph->legend->SetFont($t_graph_font); $graph->yaxis->scale->ticks->SetDirection(-1); $graph->yaxis->SetFont($t_graph_font); $graph->yaxis->scale->SetAutoMin(0); if (FF_FONT2 <= $t_graph_font) { $graph->xaxis->SetLabelAngle(60); } else { $graph->xaxis->SetLabelAngle(90); # can't rotate non truetype fonts } $graph->xaxis->SetLabelFormatCallback('graph_date_format'); $graph->xaxis->SetFont($t_graph_font); /* $t_line_colours = plugin_config_get( 'jpgraph_colors' ); $t_count_colours = count( $t_line_colours );*/ $t_lines = count($p_metrics) - 1; $t_line = array(); for ($i = 1; $i <= $t_lines; $i++) { $t_line[$i] = new LinePlot($p_metrics[$i], $p_metrics[0]); //$t_line[$i]->SetColor( $t_line_colours[$i % $t_count_colours] ); $t_line[$i]->SetCenter(); $t_line[$i]->SetLegend($p_labels[$i]); $graph->Add($t_line[$i]); } 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(); } }
function BAR_graph($module, $type, $start, $extra_fields) { global $C_translate, $C_auth; include_once PATH_CORE . 'validate.inc.php'; $dt = new CORE_validate(); include PATH_GRAPH . "jpgraph.php"; #################################################################### ### Check if 'search' is authorized for this account #################################################################### # check the validation for this function if ($C_auth->auth_method_by_name($module, 'search')) { # validate this file exists, and include it. if (file_exists(PATH_MODULES . '/' . $module . '/' . $module . '.inc.php')) { include_once PATH_MODULES . '/' . $module . '/' . $module . '.inc.php'; } else { ### Not exist! $error = $C_translate->translate('module_non_existant', '', ''); } } else { ### Not auth $error = $C_translate->translate('module_non_auth', '', ''); } if (isset($error)) { include PATH_GRAPH . "jpgraph_canvas.php"; // Create the graph. $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; } #################################################################### ### BY WEEK #################################################################### if ($type == 'week') { $FONT_SIZE = 7; $AbsWidth = 12; $interval = 4; $type = $C_translate->translate('week', '', ''); if ($start == "" || $start <= 12) { ## Get the beginning/end of this week $start_str = mktime(24, 0, 0, 12, 31, date("Y") - 1); $start = date(UNIX_DATE_FORMAT, $start_str); $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str)); $end = date(UNIX_DATE_FORMAT, $end_str); } else { ## Get the beginning/end of the specified week $start_str = mktime(24, 0, 0, 12, 31, date("{$start}") - 1); $start = date(UNIX_DATE_FORMAT, $start_str); $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str)); $end = date(UNIX_DATE_FORMAT, $end_str); } ### Set the constraint array: $curr_str = $start_str; while ($curr_str <= $end_str) { $new_curr_str = mktime(0, 0, 0, date("m", $curr_str), date("d", $curr_str) + 7, date("Y", $curr_str)); $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str); $curr_str = $new_curr_str; $default_array[] = 0; } } else { if ($type == 'month') { $FONT_SIZE = 10; $AbsWidth = 12; $TickLables = $gDateLocale->GetShortMonth(); $interval = 1; $type = $C_translate->translate('month', '', ''); if ($start == "" || $start < 12) { ## Get the beginning/end of this week $start_str = mktime(24, 0, 0, 12, 31, date("Y") - 1); $start = date(UNIX_DATE_FORMAT, $start_str); $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str)); $end = date(UNIX_DATE_FORMAT, $end_str); } else { ## Get the beginning/end of the specified week ## Get the beginning/end of this week $start_str = mktime(24, 0, 0, 12, 31, date("{$start}") - 1); $start = date(UNIX_DATE_FORMAT, $start_str); $end_str = mktime(24, 0, 0, 12, 30, date("Y", $start_str)); $end = date(UNIX_DATE_FORMAT, $end_str); } ### Set the constraint array: $curr_str = $start_str; while ($curr_str <= $end_str) { $new_curr_str = mktime(0, 0, 0, date("m", $curr_str) + 1, date("d", $curr_str), date("Y", $curr_str)); $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str); $curr_str = $new_curr_str; $default_array[] = 0; } } else { if ($type == 'year') { $FONT_SIZE = 10; $interval = 1; $AbsWidth = 13; $type = $C_translate->translate('year', '', ''); ## Get the beginning/end of this year - 10 $start_str = mktime(0, 0, 0, 1, 1, date("Y") - 9); $start = date(UNIX_DATE_FORMAT, $start_str); $end_str = mktime(0, 0, 0, 12, 30, date("Y", $start_str) + 9); $end = date(UNIX_DATE_FORMAT, $end_str); ### Set the constraint array: $curr_str = $start_str; while ($curr_str <= $end_str) { $new_curr_str = mktime(0, 0, 0, date("m", $curr_str), date("d", $curr_str), date("Y", $curr_str) + 1); $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str); $TickLables[] = date("Y", $curr_str); $curr_str = $new_curr_str; $default_array[] = 0; } } else { $FONT_SIZE = 8; $interval = 3; $AbsWidth = 4; $type = $C_translate->translate('day', '', ''); if ($start == "" || $start > 12 || $start < 1) { ## Get the beginning/end of this week $start_str = mktime(0, 0, 0, date("m"), 1, date("Y")); $start = date(UNIX_DATE_FORMAT, $start_str); $end_str = mktime(0, 0, 0, date("m", $start_str) + 1, 1, date("Y", $start_str)); $end = date(UNIX_DATE_FORMAT, $end_str); } else { ## Get the beginning/end of the specified week $start_str = mktime(0, 0, 0, date("{$start}"), 1, date("Y")); $start = date(UNIX_DATE_FORMAT, $start_str); $end_str = mktime(0, 0, 0, date("m", $start_str) + 1, 1, date("Y", $start_str)); $end = date(UNIX_DATE_FORMAT, $end_str); } ### Set the constraint array: $curr_str = $start_str; while ($curr_str < $end_str) { $new_curr_str = mktime(0, 0, 0, date("m", $curr_str), date("d", $curr_str) + 1, date("Y", $curr_str)); $constraint_array[] = array('start' => $curr_str, 'end' => $new_curr_str); $TickLables[] = date("j", $curr_str); $curr_str = $new_curr_str; $default_array[] = 0; } } } } # initialize the module, if it has not already been initialized $eval = '$' . $module . ' = new ' . $module . '; '; $eval .= '$this_Obj = $' . $module . ';'; eval($eval); # run the function $array = call_user_func(array($module, "graph"), $start_str, $end_str, $constraint_array, $default_array, $extra_fields); include PATH_GRAPH . "jpgraph_bar.php"; $datay = $array['results']; // Create the graph. These two calls are always required $graph = new Graph(550, 200, "auto"); $graph->SetScale("textlin"); $graph->yaxis->scale->SetGrace(25); $graph->SetMarginColor('#F9F9F9'); $graph->SetFrame(true, 'darkgreen', 0); $graph->SetColor('#FFFFFF'); #$graph->SetFrame(false); // Adjust the margin a bit to make more room for titles $graph->img->SetMargin(45, 10, 15, 25); // Create a bar pot $bplot = new BarPlot($datay); // Set the X if (isset($TickLables)) { $graph->xaxis->SetTickLabels($TickLables); } $graph->xaxis->SetTextLabelInterval($interval); $graph->xaxis->SetColor("navy"); $graph->yaxis->SetColor("navy"); // Adjust fill color $bplot->SetFillColor('#506DC7'); $bplot->value->Show(); $bplot->value->SetFont(FF_FONT1, FS_NORMAL, $FONT_SIZE); $bplot->value->SetAngle(90); $bplot->value->SetFormat('%0.0f'); $bplot->value->SetColor("darkblue"); $graph->Add($bplot); // Setup the titles $title = $array['title']; $graph->title->Set($title . " {$start} - {$end}"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->title->SetColor("black"); // Display the graph $graph->Stroke(); }
/** * 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); } }
/** * Runs the phpOpenTracker API call. * * @param array $parameters * @return mixed * @access public */ function run($parameters) { global $lang, $c; $parameters['result_format'] = 'separate_result_arrays'; // hour or weeday analysis $apc = "weekdays"; if ($parameters['api_call'] == "nxhours") { $apc = "hours"; } $apicall = array('api_call' => $apc, 'what' => $parameters["what"], 'start' => $parameters["start"], 'end' => $parameters["end"]); $queryValues = phpOpenTracker::get($apicall); for ($i = 0; $i < count($queryValues); $i++) { $y[$i] = $queryValues[$i]["value"]; } $title = 'Analyse '; switch ($parameters['what']) { case 'visits': $title .= 'Visits'; break; case 'pi': $title .= 'Page Impressions'; break; case 'avg_clickstream': $title .= 'Average Clickstream'; break; case 'avg_time': $title .= 'Average Online Time'; break; } if ($apc == "hours") { for ($i = 0; $i < 24; $i++) { $x_label[$i] = sprintf("%02d", $i); } $angle = 50; } else { $x_label = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); $angle = 30; } $graph = new Graph($parameters['width'], $parameters['height'], 'auto'); $graph->img->SetMargin(40, 10, 20, 50); $graph->SetScale('textlin'); $graph->SetMarginColor('white'); $graph->SetFrame(0); $graph->xgrid->Show(); $plot[0] = new BarPlot($y); $plot[0]->SetFillColor(__RED); $plot[0]->SetShadow(); $plot[0]->SetWeight(0); $gbarplot = new GroupBarPlot($plot); $gbarplot->SetWidth(0.6); $graph->add($gbarplot); $graph->xaxis->SetTickLabels($x_label); if ($c["usettf"]) { $graph->xaxis->SetLabelAngle($angle); } if ($c["usettf"]) { $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); } if ($c["usettf"]) { $graph->xaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8); } $graph->yaxis->SetColor('black'); if ($c["usettf"]) { $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); } if ($c["usettf"]) { $graph->yaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8); } $graph->title->Set($title); if ($c["usettf"]) { $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 8); } $graph->img->SetAntiAliasing("white"); $graph->Stroke(); }
} $labelx = array_keys($ticket_by_type_per_month[$event_types[0]]); $final_values = array_slice($final_values, 0, 18); } else { die(_("Invalid Graph")); } $background = "white"; $color = "navy"; $color2 = "navy"; // Setup graph $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++;
public function curve_chart($total, $previousyear, $previousmonth, $xdata, $title) { require_once 'Examples/jpgraph/jpgraph.php'; require_once 'Examples/jpgraph/jpgraph_line.php'; require_once 'Examples/jpgraph/jpgraph_bar.php'; $datax = array('1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'); // Create the graph. $graph = new Graph(1000, 400); $graph->SetScale("textlin"); $graph->SetMarginColor('white'); $graph->title->SetFont(FF_SIMSUN, FS_BOLD); // 设置中文字体 $graph->subtitle->SetFont(FF_SIMSUN); $graph->subsubtitle->SetFont(FF_SIMSUN); // Adjust the margin slightly so that we use the // entire area (since we don't use a frame) $graph->SetMargin(20, 1, 20, 90); // Box around plotarea $graph->SetBox(); // No frame around the image $graph->SetFrame(false); // Setup the tab title $graph->tabtitle->Set($title); $graph->tabtitle->SetFont(FF_SIMSUN, FS_BOLD, 10); // 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'); $graph->xaxis->SetLabelAngle(35); $graph->legend->SetFont(FF_SIMSUN, FS_NORMAL); $graph->legend->SetPos(0.01, 0.01); // Setup month as labels on the X-axis $graph->xaxis->SetTickLabels($xdata); $graph->xaxis->SetFont(FF_SIMSUN, FS_NORMAL, 8); // Create the linear error plot $l1plot = new LinePlot($previousyear); $l1plot->SetColor('red'); $l1plot->SetWeight(2); $l1plot->SetLegend('环比'); // Create the linear error plot $l2plot = new LinePlot($previousmonth); $l2plot->SetColor('yellow'); $l2plot->SetWeight(2); $l2plot->SetLegend('同比'); // Create the bar plot $bplot = new LinePlot($total); $bplot->SetColor('orange'); $bplot->SetWeight(2); $bplot->SetLegend('总量'); // Add the plots to t'he graph $graph->Add($bplot); $graph->Add($l1plot); $graph->Add($l2plot); // $graph->title->Set('Adding a line plot to a bar graph v1'); // $graph->xaxis->title->Set('X-title'); $graph->yaxis->title->Set('月份'); $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->SetTextTickInterval(2); // Display the graph $graph->Stroke(); }
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $datay1 = array(20, 15, 23, 15); $datay2 = array(12, 9, 42, 8); $datay3 = array(5, 17, 32, 24); // Setup the graph $graph = new Graph(300, 200); $graph->SetMarginColor('white'); $graph->SetScale("textlin"); $graph->SetFrame(false); $graph->SetMargin(30, 50, 30, 30); $graph->title->Set('Filled Y-grid'); $graph->yaxis->HideZeroLabel(); $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5'); $graph->xgrid->Show(); $graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth()); // Create the first line $p1 = new LinePlot($datay1); $p1->SetColor("navy"); $p1->SetLegend('Line 1'); $graph->Add($p1); // Create the second line $p2 = new LinePlot($datay2); $p2->SetColor("red"); $p2->SetLegend('Line 2'); $graph->Add($p2); // Create the third line $p3 = new LinePlot($datay3);
break; case "none": default: $graph->ygrid->Show(false, false); break; } $graph->title->SetFont($fontfamilies[$titlefont], $fontstyles[$titlefontstyle], $titlefontsize); $graph->title->SetColor($titlecolor); $graph->xaxis->SetFont($fontfamilies[$xaxisfont], $fontstyles[$xaxisfontstyle], $xaxisfontsize); $graph->xaxis->SetColor($xaxiscolor, $xaxisfontcolor); $graph->yaxis->SetFont($fontfamilies[$yaxisfont], $fontstyles[$yaxisfontstyle], $yaxisfontsize); $graph->yaxis->SetColor($yaxiscolor, $yaxisfontcolor); $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont], $fontstyles[$xtitlefontstyle], $xtitlefontsize); $graph->xaxis->title->SetColor($xtitlecolor); $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont], $fontstyles[$ytitlefontstyle], $ytitlefontsize); $graph->yaxis->title->SetColor($ytitlecolor); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetLabelMargin(15); $graph->yaxis->SetLabelMargin(15); $graph->xaxis->SetTickLabels($xlabels); $graph->xaxis->SetTextLabelInterval($xticklabint); $graph->yaxis->SetTextLabelInterval($yticklabint); $graph->xaxis->SetTextTickInterval($xtickinterval); $graph->yaxis->SetTextTickInterval($ytickinterval); $graph->SetFrame(true, 'darkblue', 2); $graph->SetFrameBevel(2, true, 'black'); if ($gridpos == "front") { $graph->SetGridDepth(DEPTH_FRONT); } // Display the graph $graph->Stroke();
function create_graph_barplot($text, $datay, $width, $height) { $margex = 140; $graph = new Graph($width, $height); $tab_txt = explode('|', $text); $txt = new Text($tab_txt[0]); $txt->SetPos(0, $height - 40); $txt->SetColor('red'); $txtb = new Text($tab_txt[1] . ' ' . $tab_txt[2] . ' ' . $tab_txt[3]); $txtb->SetPos(0, $height / 2); $graph->AddText($txt); $graph->AddText($txtb); $graph->SetScale('textlin', 0, max($datay)); $graph->SetBox(); $graph->xaxis->HideLabels(); $graph->yaxis->HideLabels(); $graph->yaxis->SetPos('max'); $graph->yaxis->SetTitle(max($datay), 'high'); $graph->yaxis->SetTitleMargin(15); $graph->yaxis->SetTitleSide(SIDE_RIGHT); $graph->xgrid->Show(); $graph->img->SetMargin($margex, 15, 1, 1); $graph->SetFrame(true, 'black', 0); $graph->ygrid->SetWeight(0, 0); $graph->ygrid->SetFill(false); $graph->xaxis->SetTextTickInterval(12, 0); $bplot = new BarPlot($datay); $graph->Add($bplot); return $graph; }
<?php // content="text/plain; charset=utf-8" require_once "jpgraph/jpgraph.php"; require_once "jpgraph/jpgraph_line.php"; $datay1 = array(4, 26, 12, 18, 8, 22); $datay2 = array(12, 9, 42, 8, 20, 19); // Setup the graph $graph = new Graph(300, 200); $graph->SetMarginColor('white'); $graph->SetScale("textlin", 0, 50); $graph->SetMargin(30, 50, 30, 30); // We must have the frame enabled to get the gradient // However, we don't want the frame line so we set it to // white color which makes it invisible. $graph->SetFrame(true, 'white'); // Setup a background gradient image $graph->SetBackgroundGradient('blue', 'navy:0.5', GRAD_HOR, BGRAD_PLOT); // Setup the tab title $graph->tabtitle->Set(' 3rd Division '); $graph->tabtitle->SetFont(FF_ARIAL, FS_BOLD, 13); // Setup x,Y grid $graph->xgrid->Show(); $graph->xgrid->SetColor('gray@0.5'); $graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth()); $graph->ygrid->SetColor('gray@0.5'); // Setup color for axis and labels on axis $graph->xaxis->SetColor('orange', 'black'); $graph->yaxis->SetColor('orange', 'black'); // Ticks on the outsid $graph->xaxis->SetTickSide(SIDE_DOWN);