require_once 'dataset01.inc.php'; $dateUtils = new DateScaleUtils(); // Setup a basic graph $width = 500; $height = 300; $graph = new Graph\Graph($width, $height); $graph->SetScale('datlin'); $graph->SetMargin(60, 20, 40, 60); // Setup the titles $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph->title->Set('Development since 1984'); $graph->subtitle->SetFont(FF_ARIAL, FS_ITALIC, 10); $graph->subtitle->Set('(Example using the builtin date scale)'); // Setup the labels to be correctly format on the X-axis $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); $graph->xaxis->SetLabelAngle(30); // The second paramter set to 'true' will make the library interpret the // format string as a date format. We use a Month + Year format // $graph->xaxis->SetLabelFormatString('M, Y',true); // First add an area plot $lp1 = new Plot\LinePlot($ydata, $xdata); $lp1->SetWeight(0); $lp1->SetFillColor('orange@0.85'); $graph->Add($lp1); // And then add line. We use two plots in order to get a // more distinct border on the graph $lp2 = new Plot\LinePlot($ydata, $xdata); $lp2->SetColor('orange'); $graph->Add($lp2); // And send back to the client $graph->Stroke();
} // new Graph\Graph with a background image and drop shadow $graph = new Graph\Graph(450, 300); $graph->SetBackgroundImage("tiger_bkg.png", BGIMG_FILLFRAME); $graph->SetShadow(); // Use an integer X-scale $graph->SetScale("intlin"); // Set title and subtitle $graph->title->Set("Combined bar and line plot"); $graph->subtitle->Set("(\"left\" aligned bars)"); // Use built in font $graph->title->SetFont(FF_FONT1, FS_BOLD); // Make the margin around the plot a little bit bigger // then default $graph->img->SetMargin(40, 120, 40, 40); // Slightly adjust the legend from it's default position in the // top right corner to middle right side $graph->legend->Pos(0.05, 0.5, "right", "center"); // Create a red line plot $p1 = new Plot\LinePlot($datay, $datax); $p1->SetColor("red"); $p1->SetLegend("Status one"); $graph->Add($p1); // Create the bar plot $b1 = new Plot\BarPlot($databary, $databarx); $b1->SetLegend("Status two"); $b1->SetAlign("left"); $b1->SetShadow(); $graph->Add($b1); // Finally output the image $graph->Stroke();
$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"); $p2->SetLegend('Line 2'); $p2->mark->SetType(MARK_UTRIANGLE, '', 1.0); $p2->mark->SetColor('#aaaaaa'); $p2->mark->SetFillColor('#aaaaaa'); $p2->value->SetMargin(14); $p2->SetCenter();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; require_once 'jpgraph/jpgraph_line.php'; $ydata = array(12, 15, 22, 19, 5); $graph = new Graph\Graph(400, 200); $graph->img->SetMargin(40, 80, 40, 40); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->title->Set('Center the line points in bars'); $line = new Plot\LinePlot($ydata); $line->SetBarCenter(); $line->SetWeight(2); $bar = new Plot\BarPlot($ydata); $bar2 = new Plot\BarPlot($ydata); $bar2->SetFillColor("red"); $gbar = new Plot\GroupBarPlot(array($bar, $bar2)); $graph->Add($gbar); $graph->Add($line); // Output line $graph->Stroke();
// content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_scatter.php'; // Make a circle with a scatterplot $steps = 16; for ($i = 0; $i < $steps; ++$i) { $a = 2 * M_PI / $steps * $i; $datax[$i] = cos($a); $datay[$i] = sin($a); } $graph = new Graph\Graph(350, 230); $graph->SetScale('linlin'); $graph->SetShadow(); $graph->SetAxisStyle(AXSTYLE_BOXOUT); $graph->img->SetMargin(50, 50, 60, 40); $graph->title->Set('Linked scatter plot'); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->subtitle->Set('(BOXOUT Axis style)'); $graph->subtitle->SetFont(FF_FONT1, FS_NORMAL); // 10% top and bottom grace $graph->yscale->SetGrace(5, 5); $graph->xscale->SetGrace(1, 1); $sp1 = new ScatterPlot($datay, $datax); $sp1->mark->SetType(MARK_FILLEDCIRCLE); $sp1->mark->SetFillColor('red'); $sp1->SetColor('blue'); $sp1->mark->SetWidth(4); $sp1->link->Show(); $sp1->link->SetStyle('dotted'); $graph->Add($sp1); $graph->Stroke();
// Data arrays $datax = array(10, 20, 30, 40, 54, 60, 70, 80); $datay = array(12, 23, 65, 18, 84, 28, 86, 44); // Setup the graph $graph = new Graph\Graph(400, 270); // We add a small 1pixel left,right,bottom margin so the plot area // doesn't cover the frame around the graph. $graph->img->SetMargin(1, 1, 1, 1); $graph->SetScale('linlin', 0, 100, 0, 100); // We don't want any axis to be shown $graph->xaxis->Hide(); $graph->yaxis->Hide(); // Use a worldmap as the background and let it fill the plot area $graph->SetBackgroundImage(WORLDMAP, BGIMG_FILLPLOT); // Setup a nice title with a striped bevel background $graph->title->Set("Pushpin graph"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 16); $graph->title->SetColor('white'); $graph->SetTitleBackground('darkgreen', TITLEBKG_STYLE1, TITLEBKG_FRAME_BEVEL); $graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED, 'blue', 'darkgreen'); // Finally create the lineplot $lp = new Plot\LinePlot($datay, $datax); $lp->SetColor('lightgray'); // We want the markers to be an image $lp->mark->SetType(MARK_IMG_PUSHPIN, 'blue', 0.6); // Install the Y-X callback for the markers $lp->mark->SetCallbackYX('markCallback'); // ... and add it to the graph $graph->Add($lp); // .. and output to browser $graph->Stroke();
$graph->xaxis->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetColor('navy'); $graph->yaxis->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->SetColor('navy'); //$graph->ygrid->Show(false); $graph->ygrid->SetColor('white@0.5'); // Setup graph title $graph->title->Set('Using a country flag background'); // Some extra margin (from the top) $graph->title->SetMargin(3); $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12); // Create the three var series we will combine $bplot1 = new Plot\BarPlot($datay1); $bplot2 = new Plot\BarPlot($datay2); $bplot3 = new Plot\BarPlot($datay3); // Setup the colors with 40% transparency (alpha channel) $bplot1->SetFillColor('yellow@0.4'); $bplot2->SetFillColor('red@0.4'); $bplot3->SetFillColor('darkgreen@0.4'); // Setup legends $bplot1->SetLegend('Label 1'); $bplot2->SetLegend('Label 2'); $bplot3->SetLegend('Label 3'); // Setup each bar with a shadow of 50% transparency $bplot1->SetShadow('black@0.4'); $bplot2->SetShadow('black@0.4'); $bplot3->SetShadow('black@0.4'); $gbarplot = new Plot\GroupBarPlot(array($bplot1, $bplot2, $bplot3)); $gbarplot->SetWidth(0.6); $graph->Add($gbarplot); $graph->Stroke();
$h = sqrt($d1 * $d1 + $d2 * $d2); $t = -$d2 / $h; $ac = acos($t); if ($y < $poley) { $ac += M_PI; } $a = $ac * 180 / M_PI; } $datax[] = $x; $datay[] = $y; $angle[] = $a; } } // Setup the graph $graph = new Graph\Graph(300, 200); $graph->SetScale("intlin", 0, 100, 0, 10); $graph->SetMarginColor('lightblue'); // ..and titles $graph->title->Set("Field plot"); // Setup the field plot $fp = new FieldPlot($datay, $datax, $angle); // Setup formatting callback $fp->SetCallback('FldCallback'); // First size argument is length (in pixels of arrow) // Second size argument is roughly size of arrow. Arrow size is specified as // an integer in the range [0,9] $fp->arrow->SetSize(20, 2); $fp->arrow->SetColor('navy'); $graph->Add($fp); // .. and output $graph->Stroke();
<?php // content="text/plain; charset=utf-8" require_once '../../vendor/autoload.php'; require_once 'jpgraph/jpgraph_bar.php'; $data1y = array(12, 8, 19, 3, 10, 5); $data2y = array(8, 2, 11, 7, 14, 4); // Create the graph. These two calls are always required $graph = new Graph\Graph(310, 200); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->img->SetMargin(40, 30, 20, 40); // Create the bar plots $b1plot = new Plot\BarPlot($data1y); $b1plot->SetFillColor("orange"); $b2plot = new Plot\BarPlot($data2y); $b2plot->SetFillColor("blue"); // Create the grouped bar plot $gbplot = new Plot\GroupBarPlot(array($b1plot, $b2plot)); // ...and add it to the graPH $graph->Add($gbplot); $graph->title->Set("Example 21"); $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();
{ $aVal = date('Y-m-d H:i', $aVal); } // Apply this format to all time values in the data to prepare it to be display array_walk($xdata, 'formatDate'); // Create the graph. $graph = new Graph\Graph(600, 350); $graph->title->Set('Accumulated values with specified X-axis scale'); $graph->SetScale('textlin'); // Setup margin color $graph->SetMarginColor('green@0.95'); // Adjust the margin to make room for the X-labels $graph->SetMargin(40, 30, 40, 120); // Turn the tick marks out from the plot area $graph->xaxis->SetTickSide(SIDE_BOTTOM); $graph->yaxis->SetTickSide(SIDE_LEFT); $p0 = new Plot\LinePlot($ydata[0]); $p0->SetFillColor('sandybrown'); $p1 = new Plot\LinePlot($ydata[1]); $p1->SetFillColor('lightblue'); $p2 = new Plot\LinePlot($ydata[2]); $p2->SetFillColor('red'); $ap = new AccLinePlot(array($p0, $p1, $p2)); $graph->xaxis->SetTickLabels($xdata); $graph->xaxis->SetTextLabelInterval(4); // Add the plot to the graph $graph->Add($ap); // Set the angle for the labels to 90 degrees $graph->xaxis->SetLabelAngle(90); // Display the graph $graph->Stroke();
} foreach ($lines as $line => $datarow) { $split = preg_split('/[\\s]+/', $datarow); $aYears[] = substr(trim($split[0]), 0, 4); $aSunspots[] = trim($split[1]); } } $year = array(); $ydata = array(); readsunspotdata('yearssn.txt', $year, $ydata); // Width and height of the graph $width = 600; $height = 200; // Create a graph instance $graph = new Graph\Graph($width, $height); // Specify what scale we want to use, // int = integer scale for the X-axis // int = integer scale for the Y-axis $graph->SetScale('intint'); // Setup a title for the graph $graph->title->Set('Sunspot example'); // Setup titles and X-axis labels $graph->xaxis->title->Set('(year from 1701)'); // Setup Y-axis title $graph->yaxis->title->Set('(# sunspots)'); // Create the bar plot $barplot = new Plot\BarPlot($ydata); // Add the plot to the graph $graph->Add($barplot); // Display the graph $graph->Stroke();
// For the new data set we want 40 points to // get a smooth curve. list($newx, $newy) = $spline->Get(50); // Create the graph $g = new Graph\Graph(300, 200); $g->SetMargin(30, 20, 40, 30); $g->title->Set("Natural cubic splines"); $g->title->SetFont(FF_ARIAL, FS_NORMAL, 12); $g->subtitle->Set('(Control points shown in red)'); $g->subtitle->SetColor('darkred'); $g->SetMarginColor('lightblue'); //$g->img->SetAntiAliasing(); // We need a linlin scale since we provide both // x and y coordinates for the data points. $g->SetScale('linlin'); // We want 1 decimal for the X-label $g->xaxis->SetLabelFormat('%1.1f'); // We use a scatterplot to illustrate the original // contro points. $splot = new ScatterPlot($ydata, $xdata); // $splot->mark->SetFillColor('red@0.3'); $splot->mark->SetColor('red@0.5'); // And a line plot to stroke the smooth curve we got // from the original control points $lplot = new Plot\LinePlot($newy, $newx); $lplot->SetColor('navy'); // Add the plots to the graph and stroke $g->Add($lplot); $g->Add($splot); $g->Stroke();
$graph->SetShadow(); // Create a bar pot $bplot = new Plot\BarPlot($datay); // Create targets for the bars image maps. One for each column $targ = array("bar_clsmex1.php#1", "bar_clsmex1.php#2", "bar_clsmex1.php#3", "bar_clsmex1.php#4", "bar_clsmex1.php#5", "bar_clsmex1.php#6"); $alts = array("val=%d", "val=%d", "val=%d", "val=%d", "val=%d", "val=%d"); $bplot->SetCSIMTargets($targ, $alts); $bplot->SetFillColor("orange"); $bplot->SetLegend('Year 2001 %%', '#kalle ', '%s'); // Display the values on top of each bar $bplot->SetShadow(); $bplot->value->SetFormat(" \$ %2.1f", 70); $bplot->value->SetFont(FF_ARIAL, FS_NORMAL, 9); $bplot->value->SetColor("blue"); $bplot->value->Show(); $graph->Add($bplot); // Create a big "button" that has an image map action $txt1 = new Text("A simple text with\ntwo rows"); $txt1->SetFont(FF_ARIAL); $txt1->SetBox('lightblue', 'black', 'white@1', 5); $txt1->SetParagraphAlign('center'); $txt1->SetPos(40, 50); $txt1->SetCSIMTarget('#88', 'Text element'); $graph->Add($txt1); // Add image map to the graph title as well (you can do this to the // sub- and subsub-title as well) $graph->title->Set("Image maps barex1"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->title->SetCSIMTarget('#45', 'Title for Bar'); $graph->xaxis->title->Set("X-title"); $graph->yaxis->title->Set("Y-title");
} // Data arrays $datax = array(10, 20, 30, 40, 54, 60, 70, 80); $datay = array(12, 23, 65, 18, 84, 28, 86, 44); // Setup the graph $graph = new Graph\Graph(400, 270); // We add a small 1pixel left,right,bottom margin so the plot area // doesn't cover the frame around the graph. $graph->img->SetMargin(1, 1, 1, 1); $graph->SetScale('linlin', 0, 100, 0, 100); // We don't want any axis to be shown $graph->xaxis->Hide(); $graph->yaxis->Hide(); // Use a worldmap as the background and let it fill the plot area $graph->SetBackgroundImage(WORLDMAP, BGIMG_FILLPLOT); // Setup a nice title with a striped bevel background $graph->title->Set("Pushpin graph"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 16); $graph->title->SetColor('white'); $graph->SetTitleBackground('darkgreen', TITLEBKG_STYLE1, TITLEBKG_FRAME_BEVEL); $graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED, 'blue', 'darkgreen'); // Finally create the scatterplot $sp = new ScatterPlot($datay, $datax); // We want the markers to be an image $sp->mark->SetType(MARK_IMG_PUSHPIN, 'blue', 0.6); // Install the Y-X callback for the markers $sp->mark->SetCallbackYX('markCallback'); // ... and add it to the graph $graph->Add($sp); // .. and output to browser $graph->Stroke();
$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); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->Add($graph); $mgraph->Add($graph2, 0, 240); $mgraph->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; }
<?php // content="text/plain; charset=utf-8" // Illustration of the different patterns for bands // $Id: smallstaticbandsex7.php,v 1.1 2002/09/01 21:51:08 aditus Exp $ require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; $datay = array(10, 29, 3, 6); // Create the graph. $graph = new Graph\Graph(200, 150); $graph->SetScale("textlin"); $graph->SetMargin(25, 10, 20, 20); // Add 10% grace ("space") at top and botton of Y-scale. $graph->yscale->SetGrace(10); // Create a bar pot $bplot = new Plot\BarPlot($datay); $bplot->SetFillColor("lightblue"); // Position the X-axis at the bottom of the plotare $graph->xaxis->SetPos("min"); $graph->ygrid->Show(false); // .. and add the plot to the graph $graph->Add($bplot); // Add band $band = new Plot\PlotBand(HORIZONTAL, BAND_HLINE, 15, 35, 'khaki4'); $band->ShowFrame(false); $graph->Add($band); // Set title $graph->title->SetFont(FF_ARIAL, FS_BOLD, 10); $graph->title->SetColor('darkred'); $graph->title->Set('BAND_HLINE'); $graph->Stroke();
// Add 10% grace ("space") at top of Y-scale. $graph->yscale->SetGrace(10); $graph->yscale->SetAutoMin(-20); // Turn the tick mark out from the plot area $graph->xaxis->SetTickSide(SIDE_DOWN); $graph->yaxis->SetTickSide(SIDE_LEFT); // Create a bar pot $bplot = new Plot\BarPlot($datay); $bplot->SetFillColor("orange"); $bplot->SetShadow("darkblue"); // Show the actual value for each bar on top/bottom $bplot->value->Show(true); $bplot->value->SetFormat("%02d kr"); // Position the X-axis at the bottom of the plotare $graph->xaxis->SetPos("min"); // .. and add the plot to the graph $graph->Add($bplot); // Add upper and lower band and use no frames $band[0] = new Plot\PlotBand(HORIZONTAL, BAND_3DPLANE, "min", 0, "blue"); $band[0]->ShowFrame(false); $band[0]->SetDensity(20); $band[1] = new Plot\PlotBand(HORIZONTAL, BAND_SOLID, 0, "max", "steelblue"); $band[1]->ShowFrame(false); $graph->Add($band); $graph->Add(new PlotLine(HORIZONTAL, 0, "black", 2)); //$graph->title->Set("Test of bar gradient fill"); $graph->xaxis->title->Set("X-title"); $graph->yaxis->title->Set("Y-title"); $graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 11); $graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 11); $graph->Stroke();
// 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); $y2data = array(354, 200, 265, 99, 111, 91, 198, 225, 293, 251); $graph = new Graph\Graph(350, 300); $graph->SetAngle(40); $graph->img->SetMargin(80, 80, 80, 80); $graph->SetScale("textlin"); $graph->SetY2Scale("lin"); $graph->SetShadow(); // Create the linear plot $lineplot = new Plot\LinePlot($ydata); $lineplot2 = new Plot\LinePlot($y2data); // Add the plot to the graph $graph->Add($lineplot); $graph->AddY2($lineplot2); $lineplot2->SetColor("orange"); $lineplot2->SetWeight(2); $graph->y2axis->SetColor("orange"); $graph->title->Set("Example 1 rotated graph (40 degree)"); $graph->legend->Pos(0.05, 0.1, "right", "top"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $lineplot->SetColor("blue"); $lineplot->SetWeight(2); $lineplot2->SetColor("orange"); $lineplot2->SetWeight(2); $graph->yaxis->SetColor("blue"); $lineplot->SetLegend("Plot 1");
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; require_once 'jpgraph/jpgraph_line.php'; require_once 'jpgraph/jpgraph_plotline.php'; $datay = array(2, 3, 5, 8.5, 11.5, 6, 3); // Create the graph. $graph = new Graph\Graph(460, 400, 'auto'); $graph->SetScale("textlin"); $graph->SetMargin(40, 20, 50, 70); $graph->legend->SetPos(0.5, 0.97, 'center', 'bottom'); $graph->title->Set('Plot line legend'); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph->SetTitleBackground('lightblue:1.3', TITLEBKG_STYLE2, TITLEBKG_FRAME_BEVEL); $graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED, 'lightblue', 'navy'); // Create a bar pot $bplot = new Plot\BarPlot($datay); $bplot->value->Show(); $bplot->value->SetFont(FF_VERDANA, FS_BOLD, 8); $bplot->SetValuePos('top'); $bplot->SetLegend('Bar Legend'); $graph->Add($bplot); $pline = new PlotLine(HORIZONTAL, 8, 'red', 2); $pline->SetLegend('Line Legend'); $graph->legend->SetColumns(10); $graph->Add($pline); $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();
require_once 'jpgraph/jpgraph_line.php'; require_once 'jpgraph/jpgraph_iconplot.php'; //$datay = array(20,15,23,15,17,35,22); $datay = array(30, 25, 33, 25, 27, 45, 32); $datay2 = array(3, 25, 10, 15, 50, 5, 18); $datay3 = array(10, 5, 10, 15, 5, 2, 1); // Setup the graph $graph = new Graph\Graph(400, 250); $graph->SetMargin(40, 40, 20, 30); $graph->SetScale("textlin"); $graph->title->Set('Adding an icon ("tux") in the background'); $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12); //$graph->SetBackgroundGradient('red','blue'); $graph->xaxis->SetPos('min'); $p1 = new Plot\LinePlot($datay); $p1->SetColor("blue"); $p1->SetFillGradient('yellow@0.4', 'red@0.4'); $p2 = new Plot\LinePlot($datay2); $p2->SetColor("black"); $p2->SetFillGradient('green@0.4', 'white'); $p3 = new Plot\LinePlot($datay3); $p3->SetColor("blue"); $p3->SetFillGradient('navy@0.4', 'white@0.4'); $graph->Add($p1); $graph->Add($p2); $graph->Add($p3); $icon = new IconPlot('penguin.png', 0.2, 0.3, 1, 30); $icon->SetAnchor('center', 'center'); $graph->Add($icon); // Output line $graph->Stroke();
<?php // content="text/plain; charset=utf-8" // Example of a stock chart require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_stock.php'; // Data must be in the format : open,close,min,max $datay = array(34, 42, 27, 45, 55, 25, 14, 59, 15, 40, 12, 47, 62, 38, 25, 65, 38, 49, 32, 64); // Setup a simple graph $graph = new Graph\Graph(300, 200); $graph->SetScale("textlin"); $graph->SetMarginColor('lightblue'); $graph->title->Set('Stockchart example'); // Create a new stock plot $p1 = new StockPlot($datay); // Width of the bars (in pixels) $p1->SetWidth(9); // Uncomment the following line to hide the horizontal end lines //$p1->HideEndLines(); // Add the plot to the graph and send it back to the browser $graph->Add($p1); $graph->Stroke();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $ydata = array(12, 17, 22, 19, 5, 15); $graph = new Graph\Graph(270, 170); $graph->SetMargin(30, 90, 30, 30); $graph->SetScale("textlin"); $graph->img->SetAngle(90); $graph->img->SetCenter(floor(270 / 2), floor(170 / 2)); $line = new Plot\LinePlot($ydata); $line->SetLegend('2002'); $line->SetColor('darkred'); $line->SetWeight(2); $graph->Add($line); // Output graph $graph->Stroke();
// Setup titles and fonts $graph->title->Set('Bar and table'); $graph->title->SetFont(FF_VERDANA, FS_NORMAL, 14); $graph->yaxis->title->Set("Flow"); $graph->yaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 12); $graph->yaxis->title->SetMargin(10); // Create the bars and the accbar plot $bplot = new Plot\BarPlot($datay[3]); $bplot->SetFillColor("orange"); $bplot2 = new Plot\BarPlot($datay[2]); $bplot2->SetFillColor("red"); $bplot3 = new Plot\BarPlot($datay[1]); $bplot3->SetFillColor("darkgreen"); $accbplot = new Plot\AccBarPlot(array($bplot, $bplot2, $bplot3)); $accbplot->value->Show(); $graph->Add($accbplot); //Setup the table $table = new GTextTable(); $table->Set($datay); $table->SetPos($tablexpos, $tableypos + 1); $table->SetCellCSIMTarget(1, 1, 'tableex02.php', 'View details'); // Basic table formatting $table->SetFont(FF_ARIAL, FS_NORMAL, 10); $table->SetAlign('right'); $table->SetMinColWidth($cellwidth); $table->SetNumberFormat('%0.1f'); // Format table header row $table->SetRowFillColor(0, 'teal@0.7'); $table->SetRowFont(0, FF_ARIAL, FS_BOLD, 11); $table->SetRowAlign(0, 'center'); // .. and add it to the graph
$l1datay = array(11, 9, 2, 4, 3, 13, 17); $l2datay = array(23, 12, 5, 19, 17, 10, 15); $datax = $gDateLocale->GetShortMonth(); // Create the graph. $graph = new Graph\Graph(400, 200); $graph->SetScale("textlin"); $graph->SetMargin(40, 130, 20, 40); $graph->SetShadow(); $graph->xaxis->SetTickLabels($datax); // Create the linear error plot $l1plot = new Plot\LinePlot($l1datay); $l1plot->SetColor("red"); $l1plot->SetWeight(2); $l1plot->SetLegend("Prediction"); //Center the line plot in the center of the bars $l1plot->SetBarCenter(); // Create the bar plot $bplot = new Plot\BarPlot($l2datay); $bplot->SetFillColor("orange"); $bplot->SetLegend("Result"); // Add the plots to t'he graph $graph->Add($bplot); $graph->Add($l1plot); $graph->title->Set("Adding a line plot to a bar graph v1"); $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();
$graph->xgrid->Show(true, false); // Add 10% grace ("space") at top and botton of Y-scale. $graph->yscale->SetGrace(10, 10); // Turn the tick mark out from the plot area $graph->xaxis->SetTickSide(SIDE_DOWN); $graph->yaxis->SetTickSide(SIDE_LEFT); // Create a bar pot $bplot = new Plot\BarPlot($datay); $bplot->SetFillColor("orange"); // Show the actual value for each bar on top/bottom $bplot->value->Show(true); $bplot->value->SetFormat("%02d kr"); // Position the X-axis at the bottom of the plotare $graph->xaxis->SetPos("min"); // .. and add the plot to the graph $graph->Add($bplot); // Add upper and lower band and use no frames $uband = new Plot\PlotBand(HORIZONTAL, BAND_RDIAG, 0, "max", "green"); $uband->ShowFrame(false); $uband->SetDensity(50); // 50% line density $lband = new Plot\PlotBand(HORIZONTAL, BAND_LDIAG, "min", 0, "red"); $lband->ShowFrame(false); $lband->SetDensity(20); // 20% line density $graph->Add($uband); $graph->Add($lband); //$graph->title->Set("Test of bar gradient fill"); $graph->xaxis->title->Set("X-title"); $graph->yaxis->title->Set("Y-title"); $graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 11);
// Create the graph. These two calls are always required $graph = new Graph\Graph(400, 300); $graph->SetScale("textlin"); if ($theme) { $graph->SetTheme(new $theme()); } $theme_class = new VividTheme(); $graph->SetTheme($theme_class); $plot = array(); // Create the bar plots for ($i = 0; $i < 4; $i++) { $plot[$i] = new Plot\BarPlot($data[$i]); $plot[$i]->SetLegend('plot' . ($i + 1)); } //$acc1 = new Plot\AccBarPlot(array($plot[0], $plot[1])); //$acc1->value->Show(); $gbplot = new Plot\GroupBarPlot(array($plot[2], $plot[1])); for ($i = 4; $i < 8; $i++) { $plot[$i] = new Plot\LinePlot($data[$i]); $plot[$i]->SetLegend('plot' . $i); $plot[$i]->value->Show(); } $graph->Add($gbplot); $graph->Add($plot[4]); $title = "VividTheme Example"; $title = mb_convert_encoding($title, 'UTF-8'); $graph->title->Set($title); $graph->xaxis->title->Set("X-title"); $graph->yaxis->title->Set("Y-title"); // Display the graph $graph->Stroke();
// content="text/plain; charset=utf-8" require_once '../../vendor/autoload.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\Graph(300, 200); $graph->SetScale("textlin"); $graph->yaxis->scale->SetGrace(20); // 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 Plot\BarPlot($datay); // Adjust fill color $bplot->SetFillColor('orange'); $bplot->value->Show(); $bplot->value->SetFont(FF_ARIAL, FS_BOLD, 10); $bplot->value->SetAngle(45); $bplot->value->SetFormat('%0.1f'); $graph->Add($bplot); // Setup the titles $graph->title->Set("Bar graph with Y-scale grace"); $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();
$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); //----------------------- // Create a multigraph //---------------------- $mgraph = new MGraph(); $mgraph->SetMargin(2, 2, 2, 2); $mgraph->SetFrame(true, 'darkgray', 2); $mgraph->SetFillColor(BKG_COLOR); $mgraph->Add($graph, 0, 50); $mgraph->Add($graph2, 250, 50); $mgraph->Add($graph3, 460, 50); $mgraph->title->Set('Climate diagram 12 March 2009'); $mgraph->title->SetFont(FF_ARIAL, FS_BOLD, 20); $mgraph->title->SetMargin(8); $mgraph->Stroke();