Exemple #1
0
// 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();
Exemple #2
0
// 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();