<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $datay1 = array(20, 7, 16, 46); $datay2 = array(6, 20, 10, 22); // Setup the graph $graph = new Graph\Graph(350, 230); $graph->SetScale("textlin"); $theme_class = new UniversalTheme(); $graph->SetTheme($theme_class); $graph->title->Set('Background Image'); $graph->SetBox(false); $graph->yaxis->HideZeroLabel(); $graph->yaxis->HideLine(false); $graph->yaxis->HideTicks(false, false); $graph->xaxis->SetTickLabels(array('A', 'B', 'C', 'D')); $graph->ygrid->SetFill(false); $graph->SetBackgroundImage("tiger_bkg.png", BGIMG_FILLFRAME); $p1 = new Plot\LinePlot($datay1); $graph->Add($p1); $p2 = new Plot\LinePlot($datay2); $graph->Add($p2); $p1->SetColor("#55bbdd"); $p1->SetLegend('Line 1'); $p1->mark->SetType(MARK_FILLEDCIRCLE, '', 1.0); $p1->mark->SetColor('#55bbdd'); $p1->mark->SetFillColor('#55bbdd'); $p1->SetCenter(); $p2->SetColor("#aaaaaa");
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; // Some data $ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7); // Create the graph. These two calls are always required $graph = new Graph\Graph(350, 250); $graph->SetScale("textlin"); $graph->SetMargin(40, 40, 50, 50); // Setup the grid and plotarea box $graph->ygrid->SetLineStyle('dashed'); $graph->ygrid->setColor('darkgray'); $graph->SetBox(true); // Steup graph titles $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph->title->Set('Using background image'); $graph->subtitle->SetFont(FF_COURIER, FS_BOLD, 11); $graph->subtitle->Set('"BGIMG_FILLFRAME"'); $graph->subtitle->SetColor('darkred'); // Add background with 25% mix $graph->SetBackgroundImage('heat1.jpg', BGIMG_FILLFRAME); $graph->SetBackgroundImageMix(25); // Create the linear plot $lineplot = new Plot\LinePlot($ydata); $lineplot->SetColor("blue"); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; require_once 'jpgraph/jpgraph_utils.inc.php'; $f = new FuncGenerator('cos($i)', '$i*$i*$i'); list($xdata, $ydata) = $f->E(-M_PI, M_PI, 25); $graph = new Graph\Graph(350, 430); $graph->SetScale("linlin"); $graph->SetShadow(); $graph->img->SetMargin(50, 50, 60, 40); $graph->SetBox(true, 'black', 2); $graph->SetMarginColor('white'); $graph->SetColor('lightyellow'); $graph->SetAxisStyle(AXSTYLE_BOXIN); $graph->xgrid->Show(); //$graph->xaxis->SetLabelFormat('%.0f'); $graph->img->SetMargin(50, 50, 60, 40); $graph->title->Set("Function plot"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->subtitle->Set("(BOXIN Axis style)"); $graph->subtitle->SetFont(FF_FONT1, FS_NORMAL); $lp1 = new Plot\LinePlot($ydata, $xdata); $lp1->SetColor("blue"); $lp1->SetWeight(2); $graph->Add($lp1); $graph->Stroke();
$graph->title->Set('Example of combined graph'); $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 14); $graph->xaxis->SetTickPositions($tickPositions, $minTickPositions); $graph->xaxis->SetLabelFormatString('My', true); $graph->xgrid->Show(); $p1 = new Plot\LinePlot($datay, $datax); $graph->Add($p1); //---------------------- // Setup the bar graph //---------------------- $graph2 = new Graph\Graph($w, 110); $graph2->SetScale('linlin', 0, 0, $xmin, $xmax); $graph2->SetMargin($lm, $rm, 5, 10); $graph2->SetMarginColor('white'); $graph2->SetFrame(false); $graph2->SetBox(true); $graph2->xgrid->Show(); $graph2->xaxis->SetTickPositions($tickPositions, $minTickPositions); $graph2->xaxis->SetLabelFormatString('My', true); $graph2->xaxis->SetPos('max'); $graph2->xaxis->HideLabels(); $graph2->xaxis->SetTickSide(SIDE_DOWN); $b1 = new Plot\BarPlot($datay2, $datax); $b1->SetFillColor('teal'); $b1->SetColor('teal:1.2'); $graph2->Add($b1); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(2, 2, 2, 2);
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $datay = array(20, 10, 35, 5, 17, 35, 22); // Setup the graph $graph = new Graph\Graph(400, 200); $graph->SetMargin(40, 40, 20, 30); $graph->SetScale("intlin"); $graph->SetBox(); $graph->SetMarginColor('darkgreen@0.8'); // Setup a background gradient image $graph->SetBackgroundGradient('darkred', 'yellow', GRAD_HOR, BGRAD_PLOT); $graph->title->Set('Gradient filled line plot ex3'); $graph->yscale->SetAutoMin(0); // Create the line $p1 = new Plot\LinePlot($datay); $p1->SetFillGradient('white', 'darkgreen', 4); $graph->Add($p1); // Output line $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\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 Plot\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; }
$graph2->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph2->yaxis->SetLabelMargin(0); $graph2->yaxis->scale->SetAutoMin(0); $line2 = new Plot\LinePlot($data_windspeed, $xdata); $line2->SetStepStyle(); $line2->SetColor('red'); $graph2->Add($line2); //------------------------------------------------------------------ // Setup the wind temp graph //------------------------------------------------------------------ $graph3 = new Graph\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 Plot\LinePlot($data_windtemp, $xdata); $line3->SetStepStyle(); $line3->SetColor('black'); $graph3->Add($line3);
$graph->yaxis->SetLabelAngle(90); $graph->yaxis->SetColor('blue'); $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph->yaxis->SetLabelMargin(0); $graph->yaxis->scale->SetAutoMin(0); $line = new Plot\LinePlot($data_winddirection, $xdata); $line->SetStepStyle(); $line->SetColor('blue'); $graph->Add($line); // Setup the wind speed graph $graph2 = new Graph\Graph(WIND_WIDTH - 30, WIND_HEIGHT); $graph2->SetScale('datlin'); $graph2->Set90AndMargin(5, 20, 60, 30); $graph2->SetMarginColor(BKG_COLOR); $graph2->SetFrame(true, 'white', 0); $graph2->SetBox(); $graph2->title->Set('Windspeed'); $graph2->title->SetColor('red'); $graph2->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph2->title->SetMargin(5); $graph2->xaxis->HideLabels(); $graph2->xgrid->Show(); $graph2->yaxis->SetLabelAngle(90); $graph2->yaxis->SetColor('red'); $graph2->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph2->yaxis->SetLabelMargin(0); $graph2->yaxis->scale->SetAutoMin(0); $line2 = new Plot\LinePlot($data_windspeed, $xdata); $line2->SetStepStyle(); $line2->SetColor('red'); $graph2->Add($line2);
$m = $gDateLocale->GetShortMonth(); $k = 0; for ($i = 0; $i < 480; ++$i) { $datay[$i] = rand(1, 40); if ($i % DATAPERMONTH === 0) { $months[$i] = $m[(int) ($i / DATAPERMONTH)]; } else { $months[$i] = 'xx'; } } // new Graph\Graph with a drop shadow $graph = new Graph\Graph(400, 200); //$graph->SetShadow(); // Use a "text" X-scale $graph->SetScale('textlin'); // Specify X-labels $graph->xaxis->SetTickLabels($months); $graph->xaxis->SetTextTickInterval(DATAPERMONTH, 0); $graph->xaxis->SetTextLabelInterval(2); // Set title and subtitle $graph->title->Set('Textscale with tickinterval=2'); // Use built in font $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->SetBox(true, 'red'); // Create the bar plot $lp1 = new Plot\LinePlot($datay); $lp1->SetLegend('Temperature'); // The order the plots are added determines who's ontop $graph->Add($lp1); // Finally output the image $graph->Stroke();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; require_once 'jpgraph/jpgraph_utils.inc.php'; $f = new FuncGenerator('cos($x)*$x'); list($xdata, $ydata) = $f->E(-1.2 * M_PI, 1.2 * M_PI); $f = new FuncGenerator('$x*$x'); list($x2data, $y2data) = $f->E(-2, 2); // Setup the basic graph $graph = new Graph\Graph(450, 350); $graph->SetScale("linlin"); //$graph->SetShadow(); $graph->img->SetMargin(5, 10, 60, 9); $graph->SetBox(true, 'green', 2); $graph->SetMarginColor('black'); $graph->SetColor('black'); // ... and titles $graph->title->Set('Example of Function plot'); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->title->SetColor('lightgreen'); $graph->subtitle->Set("(With some more advanced axis formatting\nHiding first and last label)"); $graph->subtitle->SetFont(FF_FONT1, FS_NORMAL); $graph->subtitle->SetColor('lightgreen'); $graph->xgrid->Show(); $graph->xgrid->SetColor('darkgreen'); $graph->ygrid->SetColor('darkgreen'); $graph->yaxis->SetPos(0); $graph->yaxis->SetWeight(2); $graph->yaxis->HideZeroLabel();