// content="text/plain; charset=utf-8" require_once '../../vendor/autoload.php'; use Amenadiel\JpGraph\Graph; use Amenadiel\JpGraph\Plot; $l1datay = array(11, 9, 2, 4, 3, 13, 17); $l2datay = array(23, 12, 5, 19, 17, 10, 15); $datax = array("Jan", "Feb", "Mar", "Apr", "May"); // Create the graph. $graph = new Graph\Graph(400, 200); $graph->SetScale("textlin"); $graph->img->SetMargin(40, 130, 20, 40); $graph->SetShadow(); // Create the linear error plot $l1plot = new Plot\LinePlot($l1datay); $l1plot->SetColor("red"); $l1plot->SetWeight(2); $l1plot->SetLegend("Prediction"); // Create the bar plot $bplot = new Plot\BarPlot($l2datay); $bplot->SetFillColor("orange"); $bplot->SetLegend("Result"); // Add the plots to t'he graph $graph->Add($l1plot); $graph->Add($bplot); $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); //$graph->xaxis->SetTickLabels($datax);
$lr = new LinearRegression($datax, $datay); list($stderr, $corr) = $lr->GetStat(); list($xd, $yd) = $lr->GetY(0, 19); // Create the graph $graph = new Graph\Graph(300, 250); $graph->SetScale('linlin'); // Setup title $graph->title->Set("Linear regression"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph->subtitle->Set('(stderr=' . sprintf('%.2f', $stderr) . ', corr=' . sprintf('%.2f', $corr) . ')'); $graph->subtitle->SetFont(FF_ARIAL, FS_NORMAL, 12); // make sure that the X-axis is always at the // bottom at the plot and not just at Y=0 which is // the default position $graph->xaxis->SetPos('min'); // Create the scatter plot with some nice colors $sp1 = new ScatterPlot($datay, $datax); $sp1->mark->SetType(MARK_FILLEDCIRCLE); $sp1->mark->SetFillColor("red"); $sp1->SetColor("blue"); $sp1->SetWeight(3); $sp1->mark->SetWidth(4); // Create the regression line $lplot = new Plot\LinePlot($yd); $lplot->SetWeight(2); $lplot->SetColor('navy'); // Add the pltos to the line $graph->Add($sp1); $graph->Add($lplot); // ... and stroke $graph->Stroke();
use Amenadiel\JpGraph\Plot; // Some (random) data $ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7); // Size of the overall graph $width = 350; $height = 250; // Create the graph and set a scale. // These two calls are always required $graph = new Graph\Graph($width, $height); $graph->SetScale('intlin'); $graph->SetShadow(); // Setup margin and titles $graph->SetMargin(40, 20, 20, 40); $graph->title->Set('Calls per operator'); $graph->subtitle->Set('(March 12, 2008)'); $graph->xaxis->title->Set('Operator'); $graph->yaxis->title->Set('# of calls'); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->SetColor('blue'); // Create the linear plot $lineplot = new Plot\LinePlot($ydata); $lineplot->SetColor('blue'); $lineplot->SetWeight(2); // Two pixel wide // Add an image mark scaled to 50% $lineplot->mark->SetType(MARK_IMG_DIAMOND, 'red', 0.5); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke();
<?php // content="text/plain; charset=utf-8" require_once '../../vendor/autoload.php'; use Amenadiel\JpGraph\Graph; use Amenadiel\JpGraph\Plot; $ydata = array(11, 11, 11); // Create the graph. $graph = new Graph\Graph(350, 250); $graph->SetScale("textlin"); $graph->img->SetMargin(30, 90, 40, 50); $graph->xaxis->SetFont(FF_FONT1, FS_BOLD); $graph->title->Set("Example 1.1 same y-values"); // Create the linear plot $lineplot = new Plot\LinePlot($ydata); $lineplot->SetLegend("Test 1"); $lineplot->SetColor("blue"); $lineplot->SetWeight(5); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke();