$datay = array(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'), array(12, 18, 19, 7, 17, 6), array(3, 5, 2, 7, 5, 25), array(6, 1.5, 2.4, 2.1, 6.9, 12.3)); // Some basic defines to specify the shape of the bar+table $nbrbar = 6; $cellwidth = 50; $tableypos = 200; $tablexpos = 60; $tablewidth = $nbrbar * $cellwidth; $rightmargin = 30; // Overall graph size $height = 320; $width = $tablexpos + $tablewidth + $rightmargin; // Create the basic graph. $graph = new Graph\Graph($width, $height); $graph->img->SetMargin($tablexpos, $rightmargin, 30, $height - $tableypos); $graph->SetScale("textlin"); $graph->SetMarginColor('white'); // 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();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; require_once 'jpgraph/jpgraph_flags.php'; // Some data $datay1 = array(140, 110, 50); $datay2 = array(35, 90, 190); $datay3 = array(20, 60, 70); // Create the basic graph $graph = new Graph\Graph(300, 200); $graph->SetScale("textlin"); $graph->SetMargin(40, 20, 20, 40); $graph->SetMarginColor('white:0.9'); $graph->SetColor('white'); $graph->SetShadow(); // Apply a perspective transformation at the end $graph->Set3DPerspective(SKEW3D_DOWN, 100, 180); // Adjust the position of the legend box $graph->legend->Pos(0.03, 0.1); // Adjust the color for theshadow of the legend $graph->legend->SetShadow('darkgray@0.5'); $graph->legend->SetFillColor('lightblue@0.1'); $graph->legend->Hide(); // Get localised version of the month names $graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth()); $graph->SetBackgroundCountryFlag('mais', BGIMG_COPY, 50); // Set axis titles and fonts $graph->xaxis->title->Set('Year 2002'); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
<?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'; // create the graph $graph = new Graph\Graph(400, 250); $ydata = array(5, 10, 15, 20, 15, 10); $graph->SetScale("textlin"); $graph->SetShadow(true); $graph->SetMarginColor("antiquewhite"); $graph->img->SetMargin(60, 40, 40, 50); $graph->img->setTransparent("white"); $graph->xaxis->SetFont(FF_FONT1); $graph->xaxis->setTextTickInterval(1); $graph->xaxis->SetTextLabelInterval(1); $graph->legend->SetFillColor("antiquewhite"); $graph->legend->SetShadow(true); $graph->legend->SetLayout(LEGEND_VERT); $graph->legend->Pos(0.02, 0.01); $graph->title->Set("Step Styled Example"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $lineplot = new Plot\LinePlot($ydata); $lineplot->SetColor("black"); $lineplot->setFillColor("gray7"); $lineplot->SetStepStyle(); $lineplot->SetLegend(" 2002 "); // add plot to the graph $graph->Add($lineplot); $graph->ygrid->show(false, false); // display graph
<?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\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 Plot\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\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" 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();
$ydata[0][$i] = rand(12, 15); $ydata[1][$i] = rand(100, 155); $ydata[2][$i] = rand(20, 30); } function formatDate(&$aVal) { $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
$format[strval($datax[$i])][strval($datay[$i])] = array($data[$i][2], $data[$i][3]); } // Callback for markers // Must return array(width,border_color,fill_color,filename,imgscale) // If any of the returned values are '' then the // default value for that parameter will be used (possible empty) function FCallback($aYVal, $aXVal) { global $format; return array($format[strval($aXVal)][strval($aYVal)][0], '', $format[strval($aXVal)][strval($aYVal)][1], '', ''); } // Setup a basic graph $graph = new Graph\Graph(450, 300, 'auto'); $graph->SetScale("intlin"); $graph->SetMargin(40, 40, 40, 40); $graph->SetMarginColor('wheat'); $graph->title->Set("Example of ballon scatter plot with X,Y callback"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph->title->SetMargin(10); // Use a lot of grace to get large scales since the ballon have // size and we don't want them to collide with the X-axis $graph->yaxis->scale->SetGrace(50, 10); $graph->xaxis->scale->SetGrace(50, 10); // Make sure X-axis as at the bottom of the graph and not at the default Y=0 $graph->xaxis->SetPos('min'); // Set X-scale to start at 0 $graph->xscale->SetAutoMin(0); // Create the scatter plot $sp1 = new ScatterPlot($datay, $datax); $sp1->mark->SetType(MARK_FILLEDCIRCLE); // Uncomment the following two lines to display the values
$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); //------------------------------------------------------------------ // 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();
$xdata = array(1, 3, 5, 7, 9, 12, 15, 17.1); $ydata = array(5, 1, 9, 6, 4, 3, 19, 12); // Get the interpolated values by creating // a new Spline object. $spline = new Spline($xdata, $ydata); // 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);
$y2data = array(); for ($i = 0; $i < $n; ++$i) { $y2data[] = $ydata[$i] + 10; } // Negate all data $n = count($ydata); for ($i = 0; $i < $n; ++$i) { $ydata[$i] = round(-$ydata[$i]); $y2data[$i] = round(-$y2data[$i]); } // Basic graph setup $graph = new Graph\Graph(400, 300); $graph->SetScale("linlin"); $graph->SetY2Scale("lin"); $graph->SetMargin(50, 50, 60, 40); $graph->SetMarginColor('darkblue'); $graph->SetColor('darkblue'); // Setup titles $graph->title->Set("Inverting both Y-axis"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->title->SetColor("white"); $graph->subtitle->Set("(Negated Y & Y2 axis)"); $graph->subtitle->SetFont(FF_FONT1, FS_NORMAL); $graph->subtitle->SetColor("white"); // Setup axis $graph->yaxis->SetLabelFormatCallback("_cb_negate"); $graph->xaxis->SetColor("lightblue", "white"); $graph->yaxis->SetColor("lightblue", "white"); $graph->ygrid->SetColor("blue"); // Setup Y2 axis $graph->y2axis->SetLabelFormatCallback("_cb_negate");
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; // Some data $ydata = array(5, 10, 15, 20, 15, 10, 8, 7, 4, 10, 5); // Create the graph $graph = new Graph\Graph(400, 300); $graph->SetScale("textlin"); $graph->SetShadow(true); $graph->SetMarginColor("lightblue"); // Setup format for legend $graph->legend->SetFillColor("antiquewhite"); $graph->legend->SetShadow(true); // Setup title $graph->title->Set("Filled Area Example"); $graph->title->SetFont(FF_FONT2, FS_BOLD); // Setup semi-filled line plot $lineplot = new Plot\LinePlot($ydata); $lineplot->SetLegend("Semi-filled\nLineplot"); // Set line color $lineplot->SetColor("black"); // Setup the two areas to be filled $lineplot->AddArea(2, 5, LP_AREA_FILLED, "red"); $lineplot->AddArea(6, 8, LP_AREA_FILLED, "green"); // Display the marks on the lines $lineplot->mark->SetType(MARK_DIAMOND); $lineplot->mark->SetSize(8); $lineplot->mark->Show(); // add plot to the graph
} for ($i = 0; $i < $numpoints; ++$i) { $datay[$i + $numpoints - 1] = exp(-$k * $i) * cos(2 * M_PI / 10 * $i) * 14; $datayenv[$i + $numpoints - 1] = exp(-$k * $i) * 14; $datax[$i + $numpoints - 1] = $i; } // Setup the basic parameters for the graph $graph = new Graph\Graph(500, 250); $graph->SetScale("intlin"); $graph->SetShadow(); $graph->SetBox(); $graph->title->Set("Impuls Example 4"); $graph->title->SetFont(FF_FONT1, FS_BOLD); // Set some other color then the boring default $graph->SetColor("lightyellow"); $graph->SetMarginColor("khaki"); // Set legend box specification $graph->legend->SetFillColor("white"); $graph->legend->SetLineWeight(2); // Set X-axis at the minimum value of Y-axis (default will be at 0) $graph->xaxis->SetPos("min"); // "min" will position the x-axis at the minimum value of the Y-axis // Extend the margin for the labels on the Y-axis and reverse the direction // of the ticks on the Y-axis $graph->yaxis->SetLabelMargin(12); $graph->xaxis->SetLabelMargin(6); $graph->yaxis->SetTickSide(SIDE_LEFT); $graph->xaxis->SetTickSide(SIDE_DOWN); // Add mark graph with static lines $line = new PlotLine(HORIZONTAL, 0, "black", 2); $graph->AddLine($line);
$graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph->xaxis->scale->SetDateFormat('h:i'); $graph->xgrid->Show(); $graph->yaxis->SetLabelAngle(45); $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(300, 800); $graph2->SetScale('datlin'); $graph2->Set90AndMargin(50, 30, 60, 30); $graph2->SetMarginColor('lightgray:1.7'); $graph2->SetFrame(true, 'white', 0); $graph2->SetBox(); $graph2->title->Set('Windspeed'); $graph2->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph2->title->SetMargin(10); $graph2->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 9); $graph2->xaxis->scale->SetDateFormat('h:i'); $graph2->xgrid->Show(); $graph2->yaxis->SetLabelAngle(45); $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');
// 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(); $graph->yaxis->SetFont(FF_FONT1, FS_BOLD);