// 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); $graph->Add($bplot); // Create and add a new text $txt = new Text("This is a text\nwith many\nand even\nmore\nlines of text"); $txt->SetPos(0.5, 0.5, 'center', 'center'); $txt->SetFont(FF_FONT2, FS_BOLD); $txt->ParagraphAlign('center'); $txt->SetBox('yellow', 'navy', 'gray'); $txt->SetColor('red'); $graph->AddText($txt); // Setup the titles $graph->title->Set("A simple 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 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; }
function AddText($aTxt, $aToY2 = false) { parent::AddText($aTxt); }
function AddText(&$aTxt) { parent::AddText($aTxt); }
$l2datay = array(23, 12, 5, 19, 17, 10, 15); $datax = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"); // Create the graph. $graph = new Graph(350, 200, "auto"); $graph->img->SetMargin(40, 70, 20, 40); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->SetColor(array(250, 250, 250)); $graph->img->SetTransparent("white"); $t1 = new Text("This is a text"); $t1->SetPos(0.5, 0.5); $t1->SetOrientation("h"); $t1->SetFont(FF_FONT1, FS_BOLD); $t1->SetBox("white", "black", "gray"); $t1->SetColor("black"); $graph->AddText($t1); // Create the linear error plot $l1plot = new LinePlot($l1datay); $l1plot->SetColor("blue"); $l1plot->SetWeight(2); $l1plot->SetLegend("Prediction"); // Create the bar plot $l2plot = new BarPlot($l2datay); $l2plot->SetFillColor("orange"); $l2plot->SetLegend("Result"); // Add the plots to the graph $graph->Add($l1plot); $graph->Add($l2plot); $graph->title->Set("Example 16.3"); $graph->xaxis->title->Set("Month"); $graph->yaxis->title->Set("x10,000 US\$");
} $pays[$i]->mark->SetSize(10); $graph->Add($pays[$i]); $i++; } $legende25 = new ScatterPlot(array(90), array(50)); $legende25->mark->SetType(MARK_FILLEDCIRCLE); $legende25->mark->SetColor("yellow@0.5"); $legende25->mark->SetFillColor("yellow@0.4"); $legende25->mark->SetSize(10); $graph->Add($legende25); $legtext25 = new Text(" < 25%"); $legtext25->SetPos(70, 597); $legtext25->SetColor("black"); $legtext25->SetFont(FF_FONT1, FS_BOLD, 16); $graph->AddText($legtext25); $legende50 = new ScatterPlot(array(120), array(50)); $legende50->mark->SetType(MARK_FILLEDCIRCLE); $legende50->mark->SetColor("orange@0.5"); $legende50->mark->SetFillColor("orange@0.4"); $legende50->mark->SetSize(10); $graph->Add($legende50); $legtext50 = new Text(" < 50%"); $legtext50->SetPos(70, 567); $legtext50->SetColor("black"); $legtext50->SetFont(FF_FONT1, FS_BOLD, 16); $graph->AddText($legtext50); $legende100 = new ScatterPlot(array(150), array(50)); $legende100->mark->SetType(MARK_FILLEDCIRCLE); $legende100->mark->SetColor("red@0.5"); $legende100->mark->SetFillColor("red@0.4");
function setupGraph($XUnits = "hours", $startTime, $count, $options = array()) { global $conf; $graph = new Graph($conf['graph']['width'], $conf['graph']['height'], "auto"); $graph->SetScale("intlin"); //$graph->SetScale("linlin",$mintemp,$maxtemp,$mintime, $maxtime); //$graph->SetShadow(); $rightMargin = 20; if (isset($options['showMargin']) && $options['showMargin'] == 1) { $rightMargin = 110; } $graph->img->SetMargin(50, $rightMargin, 20, 40); $graph->SetBox(true, 'black', 2); $graph->SetColor($conf['graph']['bgcolor']); $graph->SetMarginColor($conf['html']['bgcolor']); //$graph->title->Set("Digitemp Activity"); $graph->title->Set("Digitemp Activity starting " . date("H:i:s m/d/Y", $startTime)); /** $txt =new Text("Starting ".date("H:i:s m/d/Y", $startTime)); $txt->Pos( 0.59,0.01); $txt->SetColor( "blue"); $graph->AddText( $txt); **/ //junk: $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->xgrid->Show(); $graph->legend->Pos(0.02, 0.02, "right", "top"); /* $graph->yaxis->SetPos(0); $graph->yaxis->SetWeight(2); $graph->yaxis->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->SetColor('black','darkblue'); */ $graph->xaxis->SetWeight(2); $graph->xaxis->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetColor('black', 'darkblue'); // echo "Setting limits to $mintime, $maxtime, $mintemp, $maxtemp"; //$graph->SetScale("linlin",$mintemp,$maxtemp,$mintime, $maxtime); $graph->xaxis->title->Set("Time ({$XUnits})"); $graph->yaxis->title->Set('Temperature (' . $options['units'] . ')'); $txt2 = new Text("Measurements shown: {$count}"); $txt2->Pos(0.02, 0.96); $txt2->SetColor("blue"); $graph->AddText($txt2); return $graph; }
private function templateGraph() { $sites2 = $this->getSites2(); // echo 'User1'; // var_dump($this->user1->displayUsername()); // if ($this->user2 !== false) { // echo 'User2'; // var_dump($this->user2->displayUsername()); // } // echo 'Sites'; // var_dump($sites2); // var_dump(sprintf('%d_%d_%d', Common::getGet('y'), Common::getGet('m'), Common::getGet('d'))); // echo 'Start'; // var_dump($this->start); // echo 'End'; // var_dump($this->end); // echo 'Icons'; // var_dump($this->withIcons); // echo 'Numbers'; // var_dump($this->withNumbers); $dir = dirname(GWF_JPGRAPH_PATH) . '/'; require_once $dir . 'jpgraph.php'; require_once $dir . 'jpgraph_date.php'; require_once $dir . 'jpgraph_line.php'; require_once $dir . 'jpgraph_plotline.php'; $xdata = array(); $ydata = array(); $ylast = array(); $maxperc = 0; $db = gdo_db(); $uid1 = $this->user1->getVar('user_id'); $uid2 = $this->user2 === false ? 0 : $this->user2->getVar('user_id'); // $history = GWF_TABLE_PREFIX.'wc_user_history2'; $start = GWF_Time::getTimestamp($this->start); $end = GWF_Time::getTimestamp($this->end) + GWF_Time::ONE_DAY; $no_data = true; $xdata[$uid1] = array(); $ydata[$uid1] = array(); $ylast[$uid1] = array(); if ($uid2 === 0) { $where2 = ''; } else { $where2 = " OR userhist_uid={$uid2}"; $xdata[$uid2] = array(); $ydata[$uid2] = array(); $ylast[$uid2] = array(); } require_once GWF_CORE_PATH . 'module/WeChall/WC_HistoryUser2.php'; $history = GDO::table('WC_HistoryUser2'); $where = "(userhist_uid={$uid1}{$where2}) AND userhist_date BETWEEN {$start} AND {$end}"; $orderby = 'userhist_date ASC'; if (false === ($result = $history->select('userhist_uid, userhist_sid, userhist_percent, userhist_date', $where, $orderby))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // $query = "SELECT userhist_uid, userhist_sid, userhist_percent, userhist_date FROM $history WHERE (userhist_uid=$uid1$where2) AND userhist_date BETWEEN $start AND $end ORDER BY userhist_date ASC"; // if (false === ($result = $db->queryRead($query))) { // return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); // } // while (false !== ($row = $db->fetchRow($result))) while (false !== ($row = $history->fetch($result, GDO::ARRAY_N))) { $siteid = $row[1]; if (!in_array($siteid, $sites2, true)) { continue; // site not wanted in graph... } $userid = $row[0]; $percent = $row[2] / 100; $time = $row[3]; if ($percent > $maxperc) { $maxperc = $percent; } if (!isset($xdata[$userid][$siteid])) { $xdata[$userid][$siteid] = array(); $ydata[$userid][$siteid] = array(); $ylast[$userid][$siteid] = 0; // $first[$siteid] = $percent; if (!$this->withZoom) { $xdata[$userid][$siteid][] = $start; $ydata[$userid][$siteid][] = $percent; } } $xdata[$userid][$siteid][] = $time; $ydata[$userid][$siteid][] = $percent; $ylast[$userid][$siteid] = $percent; $no_data = false; } if (!$this->withZoom) { foreach (array_keys($ydata[$uid1]) as $siteid) { $xdata[$uid1][$siteid][] = $end; $ydata[$uid1][$siteid][] = $ylast[$uid1][$siteid]; } if (isset($ydata[$uid2])) { foreach (array_keys($ydata[$uid2]) as $siteid) { $xdata[$uid2][$siteid][] = $end; $ydata[$uid2][$siteid][] = $ylast[$uid2][$siteid]; } } } // $xdata[$siteid][] = $end; // $ydata[$siteid][] = $percent; // $ylast[$siteid] = $percent; // foreach ($sites2 as $siteid) // { // $xdata[$siteid][] = $end; // $ydata[$siteid][] = isset($ylast[$siteid]) ; // } //define the graph $dateformat = "d.M.y"; $datemargin = strlen(date($dateformat)) * 11; // $graph = new Graph($this->module->cfgGraphWidth()*2, $this->module->cfgGraphHeight()*2); $graph = new Graph($this->width, $this->height); if ($no_data) { $graph->SetScale('textint', 0, 100, 0, 1); } else { $graph->SetScale('datlin', 0, 100); $graph->xaxis->scale->SetDateFormat($dateformat); } $graph->SetColor(array(238, 238, 238)); $graph->SetMarginColor(array(208, 211, 237)); $graph->title->Set($this->getGraphTitle()); $graph->yaxis->title->Set($this->module->lang('percentage')); $graph->SetShadow(); $graph->xaxis->SetLabelAngle(90); $graph->img->SetMargin(40, 170, 20, $datemargin); // $graph->img->SetMargin(40, 140, 0, $datemargin); $graph->legend->Pos(0.015, 0.05, "right", "top"); $weights = array($uid1 => 3, $uid2 => 1); $labeled = array(); //make a line for each site (and user) foreach ($ydata as $userid => $ydata2) { $curr_weight = $weights[$userid]; foreach ($ydata2 as $siteid => $data) { // var_dump($data); if (!isset($this->sites[$siteid])) { continue; } $site = $this->sites[$siteid]; $site instanceof WC_Site; $lineplot = new LinePlot($data, $xdata[$userid][$siteid]); list($color, $style) = $this->getColorAndStyle($site); $lineplot->SetStyle($style); $lineplot->SetColor($color); $lineplot->SetWeight($curr_weight); if ($this->withNumbers) { $lineplot->value->Show(); } if ($this->withIcons) { $path = 'dbimg/logo_gif/' . $siteid . '.gif'; if (is_readable($path)) { $lineplot->mark->SetType(MARK_IMG, $path, 0.5); } } if (!in_array($siteid, $labeled, true)) { $lineplot->SetLegend($site->getVar('site_name')); $labeled[] = $siteid; } $graph->Add($lineplot); } } // $graph->img->SetAntiAliasing(); if ($no_data) { if (count($this->sites) === 0) { $text = $this->module->lang('err_no_sites'); } else { $text = $this->module->lang('err_graph_empty'); } $txt = new Text($text); // $txt->SetFont(FF_ARIAL,FS_NORMAL,18); $txt->SetColor("#0000ff"); $txt->SetPos(0.45, 0.45, 'center', 'center'); $graph->AddText($txt); } $graph->Stroke(); die; }
/* $tx3 = new Text("Last Ob @ ". strftime("%m/%d %I:%M %p", $mySOb['ts']) ." Sensor 0: ". $mySOb['tmpf0'] ." F Sensor 1: ". $mySOb['tmpf1'] ." F Sensor 2: ". $mySOb['tmpf2'] ." F Sensor 3: ". $mySOb['tmpf3'] ." F Air Temp: ". $myOb['tmpf'] ." F Dew Point: ". $myOb['dwpf'] ." F SubS Temp: ". $mySOb['subt'] ." F "); */ } //$tx3->SetPos(0.31,0.001, 'left', 'top'); //$tx3->SetFont(FF_FONT1, FS_NORMAL, 8); //$tx3->SetColor("blue"); $graph->AddText($tx1); $graph->AddText($tx2); //$graph->AddText($tx3); // Add the plot to the graph $graph->Add($fz); if (max($tcs0) != "" && isset($_GET["s0"])) { $graph->Add($lineplot); } if (max($tcs1) != "" && isset($_GET["s1"])) { $graph->Add($lineplot2); } if (max($tcs2) != "" && isset($_GET["s2"])) { $graph->Add($lineplot3); } if (max($tcs3) != "" && isset($_GET["s3"])) { $graph->Add($lineplot4);
private function graphB(WC_Site $site, $field) { $graphtitle = $this->module->lang('gt_site_' . $field, array($site->getVar('site_name'))); $siteid = $site->getID(); $history = GDO::table('WC_HistorySite'); if (false === ($result = $history->select("sitehist_date, {$field}", 'sitehist_sid=' . $siteid, 'sitehist_date ASC'))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // $db = gdo_db(); // $table = $history->getTableName(); // if (false === ($result = $db->query("SELECT sitehist_date, $field FROM $table WHERE sitehist_sid=$siteid ORDER BY sitehist_date ASC"))) { // return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); // } //load in the data $xdataarray = array(); $ydataarray = array(); $highestvalue = 0; // while (false !== ($row = $db->fetchRow($result))) while (false !== ($row = $history->fetch($result, GDO::ARRAY_N))) { $value = (int) $row[1]; $xdataarray[] = $row[0]; $ydataarray[] = $value; if ($value > $highestvalue) { $highestvalue = $value; } } $history->free($result); // add current value $xdataarray[] = time(); $ydataarray[] = $value = $site->getVar(str_replace('hist_', '_', $field)); if ($value > $highestvalue) { $highestvalue = $value; } // var_dump($xdataarray); // var_dump($ydataarray); // var_dump($xticks); if ($highestvalue === 0) { $graph = new Graph($this->module->cfgGraphWidth(), $this->module->cfgGraphHeight()); $graph->SetScale('intlin', 1, 2, 1, 2); $caption = new Text($this->module->lang('err_graph_empty'), 0.1, 0.8); // $caption->SetFont(FS_BOLD); $graph->AddText($caption); $graph->stroke(); die(0); } # $dateformat = GWF_HTML::lang('df_8'); // $dateformat = "d.M.y-H:i"; $dateformat = "M.y"; $datemargin = strlen(date($dateformat)) * 11; //define the graph $graph = new Graph($this->module->cfgGraphWidth(), $this->module->cfgGraphHeight()); $graph->SetScale('datlin', 0, 1.05 * $highestvalue); $graph->title->Set($graphtitle); // $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12); $graph->SetColor(array(238, 238, 238)); $graph->SetMarginColor(array(208, 211, 237)); $graph->SetShadow(); $graph->xaxis->SetLabelAngle(90); // $graph->xaxis->SetTickPositions($xticks, NULL, $xdataarray); $graph->xaxis->scale->SetDateFormat($dateformat); $graph->img->SetMargin(50, 40, 40, $datemargin); $lineplot = new LinePlot($ydataarray, $xdataarray); $lineplot->SetColor("blue"); $lineplot->SetWeight(2); $graph->Add($lineplot); // $graph->img->SetAntiAliasing(); // Display the graph GWF_HTTP::noCache(); $graph->Stroke(); die(0); }
$graph->AddY2($lineFound); // // Infotexte einfuegen // $txtStat1 = new Text(tr('graph_statistics_04') . strftime('%d-%m-%Y', time())); $txtStat1->SetPos(55, 55); $txtStat1->SetFont(FF_ARIAL, FS_NORMAL, 10); $lineHeight = $txtStat1->GetFontHeight($graph->img); $hiddenCaches = XDb::xSimpleQueryValue("SELECT COUNT(*) FROM `caches` WHERE (`status`=1 OR `status`=2 OR `status`=3)", 0); $txtStat2 = new Text(tr('graph_statistics_05') . str_replace(',', '.', number_format($hiddenCaches))); $txtStat2->SetPos(55, 55 + $lineHeight * 1.5); $txtStat2->SetFont(FF_ARIAL, FS_NORMAL, 8); $txtStat2->SetColor('blue'); $activeCaches = XDb::xSimpleQueryValue("SELECT COUNT(*) FROM `caches` WHERE `status`=1", 0); $txtStat3 = new Text(tr('graph_statistics_06') . str_replace(',', '.', number_format($activeCaches))); $txtStat3->SetPos(55, 55 + $lineHeight * 2.5); $txtStat3->SetFont(FF_ARIAL, FS_NORMAL, 8); $txtStat3->SetColor('blue'); $foundEntries = XDb::xMultiVariableQueryValue("SELECT COUNT(*) FROM `cache_logs` WHERE `type`=1 AND `deleted`=0", 0); $txtStat5 = new Text(tr('graph_statistics_07') . str_replace(',', '.', number_format($foundEntries))); $txtStat5->SetPos(55, 55 + $lineHeight * 5.0); $txtStat5->SetFont(FF_ARIAL, FS_NORMAL, 8); $txtStat5->SetColor('darkgreen'); $graph->AddText($txtStat1); $graph->AddText($txtStat2); $graph->AddText($txtStat3); $graph->AddText($txtStat5); // // Display the graph // $graph->Stroke();
function init_graphs() { global $rundate; // Create the graphs $tdate1 = new Text(); $tdate1->SetFont(FF_ARIAL, FS_NORMAL, 8); $tdate1->SetColor("#000000"); $tdate1->Set("generated at: {$rundate}"); $tdate1->SetBox("#ffffff", "#8b898b", "#aaaaaa", 0, 0); $tdate1->SetPos(280, 220); $tdate2 = new Text(); $tdate2->SetFont(FF_ARIAL, FS_NORMAL, 8); $tdate2->SetColor("#000000"); $tdate2->Set("generated at: {$rundate}"); $tdate2->SetBox("#ffffff", "#8b898b", "#aaaaaa", 0, 0); $tdate2->SetPos(560, 420); // ** ------------- ** $graph1 = new Graph(470, 250, "auto"); $graph1->SetScale("textlin"); $graph1->SetShadow(); $graph1->SetBox(); $graph1->img->SetMargin(60, 30, 30, 80); $graph1->SetMarginColor('#ececec'); $graph1->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph1->AddText($tdate1); // -------------- $graph1->ygrid->Show(true, true); $graph1->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 10); $graph1->yaxis->title->SetAngle(90); $graph1->yaxis->SetTitleMargin(40); $graph1->yaxis->title->Text("Translated Messages", "high"); $graph1->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); $graph1->yaxis->SetLabelAngle(0); $graph1->yaxis->SetPos('min'); // ------------- $graph1->xgrid->Show(false, false); $graph1->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 10); $graph1->xaxis->title->SetAngle(0); $graph1->xaxis->title->Text("Days"); $graph1->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); $graph1->xaxis->SetLabelAngle(30); $graph1->xaxis->SetTextLabelInterval(10); $graph1->xaxis->SetPos('min'); $sline = new PlotLine(HORIZONTAL, 0, "black", 1); $graph1->Add($sline); // ** ------------- ** $graph2 = new Graph(750, 450, "auto"); $graph2->SetScale("textlin"); $graph2->SetShadow(); $graph2->SetBox(); $graph2->img->SetMargin(60, 30, 30, 80); $graph2->SetMarginColor('#ececec'); $graph2->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph2->AddText($tdate2); // -------------- $graph2->ygrid->Show(true, true); $graph2->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 10); $graph2->yaxis->title->SetAngle(90); $graph2->yaxis->SetTitleMargin(40); $graph2->yaxis->title->Text("Translated Messages", "high"); $graph2->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); $graph2->yaxis->SetLabelAngle(0); $graph2->yaxis->SetPos('min'); // ------------- $graph2->xgrid->Show(true, false); $graph2->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 10); $graph2->xaxis->title->SetAngle(0); $graph2->xaxis->title->Text("Days"); $graph2->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); $graph2->xaxis->SetLabelAngle(30); $graph2->xaxis->SetTextLabelInterval(10); $graph2->xaxis->SetPos('min'); $sline = new PlotLine(HORIZONTAL, 0, "black", 1); $graph2->Add($sline); return array($graph1, $graph2); }