$cond = array('time' => array('mode' => 'BETWEEN', 'topvalue' => $endtime, 'value' => $starttime)); $objects = $model->get(array('AND' => array($cond)), array('fields' => array('time'), 'type' => 'ASC')); foreach ($objects as $obj) { $ydata[$obj->getTime()] += $obj->getAantal(); $xdata[$obj->getTime()] = $obj->getTime(); } $xdata = array_values($xdata); $ydata = array_values($ydata); } $width = 600; $height = 400; // Create a graph instance $graph = new Graph($width, $height); $graph->img->SetMargin(80, 30, 55, 90); $graph->img->SetAntiAliasing(true); $graph->SetClipping(true); // Specify what scale we want to use $maxscale = $aantalbedden > max($ydata) ? $aantalbedden + 3 : max($ydata) + 3; $graph->SetScale('datlin', 0, $maxscale, $starttime, $endtime); // Setup a title for the graph $title = 'Bedbezetting ' . $naam; $graph->title->Set($title); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 14); $subtitle = date('d/m/Y', $starttime) . ' - ' . date('d/m/Y', $endtime); $graph->subtitle->Set($subtitle); $graph->subtitle->SetFont(FF_ARIAL, FS_BOLD, 12); // Setup titles and X-axis labels $graph->xaxis->title->Set(''); $graph->xaxis->SetLabelAngle(45); $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); // Setup Y-axis title
<?php // content="text/plain; charset=utf-8" require_once "jpgraph/jpgraph.php"; require_once "jpgraph/jpgraph_line.php"; $ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7); // Create the graph. These two calls are always required $graph = new Graph(300, 250); $graph->SetScale('intlin', 0, 10); $graph->SetMargin(30, 20, 70, 40); $graph->SetMarginColor(array(177, 191, 174)); $graph->SetClipping(false); $graph->xaxis->SetFont(FF_FONT1, FS_BOLD); $graph->ygrid->SetLineStyle('dashed'); $graph->title->Set("Manual scale"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph->title->SetColor('white'); $graph->subtitle->Set("(No clipping)"); $graph->subtitle->SetColor('white'); $graph->subtitle->SetFont(FF_ARIAL, FS_BOLD, 10); // Create the linear plot $lineplot = new LinePlot($ydata); $lineplot->SetColor("red"); $lineplot->SetWeight(2); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke();
/** * Construct the graph * */ private function Init() { // Setup limits for color indications $lowx = $this->iXMin; $highx = $this->iXMax; $lowy = $this->iYMin; $highy = $this->iYMax; $width = $this->iWidth; $height = $this->iHeight; // Margins $lm = 50; $rm = 40; $tm = 60; $bm = 40; if ($width <= 300 || $height <= 250) { $labelsize = 8; $lm = 25; $rm = 25; $tm = 45; $bm = 25; } elseif ($width <= 450 || $height <= 300) { $labelsize = 8; $lm = 30; $rm = 30; $tm = 50; $bm = 30; } elseif ($width <= 600 || $height <= 400) { $labelsize = 9; } else { $labelsize = 11; } if ($this->iSubTitle == '') { $tm -= $labelsize + 4; } $graph = new Graph($width, $height); $graph->SetScale('intint', $lowy, $highy, $lowx, $highx); $graph->SetMargin($lm, $rm, $tm, $bm); $graph->SetMarginColor($this->iMarginColor[$this->iColorMap]); $graph->SetClipping(); $graph->title->Set($this->iTitle); $graph->subtitle->Set($this->iSubTitle); $graph->title->SetFont(FF_ARIAL, FS_BOLD, $labelsize + 4); $graph->subtitle->SetFont(FF_ARIAL, FS_BOLD, $labelsize + 1); $graph->SetBox(true, 'black@0.3'); $graph->xaxis->SetFont(FF_ARIAL, FS_BOLD, $labelsize); $graph->yaxis->SetFont(FF_ARIAL, FS_BOLD, $labelsize); $graph->xaxis->scale->ticks->Set(CCBPGraph::TickStep, CCBPGraph::TickStep); $graph->yaxis->scale->ticks->Set(CCBPGraph::TickStep, CCBPGraph::TickStep); $graph->xaxis->HideZeroLabel(); $graph->yaxis->HideZeroLabel(); $graph->xaxis->SetLabelFormatString('%d%%'); $graph->yaxis->SetLabelFormatString('%d%%'); // For the x-axis we adjust the color so labels on the left of the Y-axis are in black $n1 = floor(abs($this->iXMin / 25)) + 1; $n2 = floor($this->iXMax / 25); if ($this->iColorMap == 0) { $xlcolors = array(); for ($i = 0; $i < $n1; ++$i) { $xlcolors[$i] = 'black'; } for ($i = 0; $i < $n2; ++$i) { $xlcolors[$n1 + $i] = 'lightgray:1.5'; } $graph->xaxis->SetColor('gray', $xlcolors); $graph->yaxis->SetColor('gray', 'lightgray:1.5'); } else { $graph->xaxis->SetColor('darkgray', 'darkgray:0.8'); $graph->yaxis->SetColor('darkgray', 'darkgray:0.8'); } $graph->SetGridDepth(DEPTH_FRONT); $graph->ygrid->SetColor('gray@0.6'); $graph->ygrid->SetLineStyle('dotted'); $graph->ygrid->Show(); $graph->xaxis->SetWeight(1); $graph->yaxis->SetWeight(1); $ytitle = new Text(CCBPGraph::YTitle, floor($lm * 0.75), ($height - $tm - $bm) / 2 + $tm); #$ytitle->SetFont(FF_VERA,FS_BOLD,$labelsize+1); $ytitle->SetAlign('right', 'center'); $ytitle->SetAngle(90); $graph->Add($ytitle); $xtitle = new Text(CCBPGraph::XTitle, ($width - $lm - $rm) / 2 + $lm, $height - 10); #$xtitle->SetFont(FF_VERA,FS_BOLD,$labelsize); $xtitle->SetAlign('center', 'bottom'); $graph->Add($xtitle); $df = 'D j:S M, Y'; if ($width < 400) { $df = 'D j:S M'; } $time = new Text(date($df), $width - 10, $height - 10); $time->SetAlign('right', 'bottom'); #$time->SetFont(FF_VERA,FS_NORMAL,$labelsize-1); $time->SetColor('darkgray'); $graph->Add($time); // Use an accumulated fille line graph to create the colored bands $n = 3; for ($i = 0; $i < $n; ++$i) { $b = $this->iColorInd[$i][0]; $k = ($this->iColorInd[$i][1] - $this->iColorInd[$i][0]) / $this->iXMax; $colarea[$i] = array(array($lowx, $lowx * $k + $b), array($highx, $highx * $k + $b)); } $colarea[3] = array(array($lowx, $highy), array($highx, $highy)); $cb = array(); for ($i = 0; $i < 4; ++$i) { $cb[$i] = new LinePlot(array($colarea[$i][0][1], $colarea[$i][1][1]), array($colarea[$i][0][0], $colarea[$i][1][0])); $cb[$i]->SetFillColor($this->iColorSpec[$this->iColorMap][$i]); $cb[$i]->SetFillFromYMin(); } $graph->Add(array_slice(array_reverse($cb), 0, 4)); $this->graph = $graph; }