Example #1
0
use Amenadiel\JpGraph\Plot;
$ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7);
$y2data = array(354, 200, 265, 99, 111, 91, 198, 225, 293, 251);
// Create the graph and specify the scale for both Y-axis
$graph = new Graph\Graph(400, 200);
$graph->SetScale('textlin');
$graph->SetY2Scale('lin');
$graph->SetShadow();
// Adjust the margin
$graph->img->SetMargin(40, 140, 20, 40);
// Create the two 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);
// Adjust the axis color
$graph->y2axis->SetColor('orange');
$graph->yaxis->SetColor('blue');
$graph->title->Set('Example 6');
$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);
// Set the colors for the plots
$lineplot->SetColor('blue');
$lineplot->SetWeight(2);
$lineplot2->SetColor('orange');
Example #2
0
$graph->subtitle->Set("100 data points, X-Scale: 'text'");
// Use built in font (don't need TTF support)
$graph->title->SetFont(FF_FONT1, FS_BOLD);
// Make the margin around the plot a little bit bigger then default
$graph->img->SetMargin(40, 140, 40, 80);
// Slightly adjust the legend from it's default position in the
// top right corner to middle right side
$graph->legend->Pos(0.03, 0.5, "right", "center");
// Display every 6:th tickmark
$graph->xaxis->SetTextTickInterval(6);
// Label every 2:nd tick mark
$graph->xaxis->SetTextLabelInterval(2);
// Setup the labels
$graph->xaxis->SetTickLabels($databarx);
$graph->xaxis->SetLabelAngle(90);
// Create a red line plot
$p1 = new Plot\LinePlot($datay);
$p1->SetColor("red");
$p1->SetLegend("Pressure");
// Create the bar plot
$b1 = new Plot\BarPlot($databary);
$b1->SetLegend("Temperature");
$b1->SetFillColor("orange");
$b1->SetAbsWidth(8);
// Drop shadow on bars adjust the default values a little bit
$b1->SetShadow("steelblue", 2, 2);
// The order the plots are added determines who's ontop
$graph->Add($p1);
$graph->AddY2($b1);
// Finally output the  image
$graph->Stroke();
Example #3
0
$graph->yaxis->HideTicks(false, false);
// Setup month as labels on the X-axis
$graph->xaxis->SetTickLabels($months);
// Create the bar plots
$b1plot = new Plot\BarPlot($data1y);
$b2plot = new Plot\BarPlot($data2y);
$b3plot = new Plot\BarPlot($data3y);
$b4plot = new Plot\BarPlot($data4y);
$b5plot = new Plot\BarPlot($data5y);
$lplot = new Plot\LinePlot($data6y);
// Create the grouped bar plot
$gbbplot = new Plot\AccBarPlot(array($b3plot, $b4plot, $b5plot));
$gbplot = new Plot\GroupBarPlot(array($b1plot, $b2plot, $gbbplot));
// ...and add it to the graPH
$graph->Add($gbplot);
$graph->AddY2($lplot);
$b1plot->SetColor("#0000CD");
$b1plot->SetFillColor("#0000CD");
$b1plot->SetLegend("Cliants");
$b2plot->SetColor("#B0C4DE");
$b2plot->SetFillColor("#B0C4DE");
$b2plot->SetLegend("Machines");
$b3plot->SetColor("#8B008B");
$b3plot->SetFillColor("#8B008B");
$b3plot->SetLegend("First Track");
$b4plot->SetColor("#DA70D6");
$b4plot->SetFillColor("#DA70D6");
$b4plot->SetLegend("All");
$b5plot->SetColor("#9370DB");
$b5plot->SetFillColor("#9370DB");
$b5plot->SetLegend("Single Only");
Example #4
0
$datazero = array(0, 0, 0, 0);
// Create the graph.
$graph = new Graph\Graph(450, 200);
$graph->title->Set('Example with 2 scale bars');
// Setup Y and Y2 scales with some "grace"
$graph->SetScale("textlin");
$graph->SetY2Scale("lin");
$graph->yaxis->scale->SetGrace(30);
$graph->y2axis->scale->SetGrace(30);
//$graph->ygrid->Show(true,true);
$graph->ygrid->SetColor('gray', 'lightgray@0.5');
// Setup graph colors
$graph->SetMarginColor('white');
$graph->y2axis->SetColor('darkred');
// Create the "dummy" 0 bplot
$bplotzero = new Plot\BarPlot($datazero);
// Create the "Y" axis group
$ybplot1 = new Plot\BarPlot($datay);
$ybplot1->value->Show();
$ybplot = new Plot\GroupBarPlot(array($ybplot1, $bplotzero));
// Create the "Y2" axis group
$ybplot2 = new Plot\BarPlot($datay2);
$ybplot2->value->Show();
$ybplot2->value->SetColor('darkred');
$ybplot2->SetFillColor('darkred');
$y2bplot = new Plot\GroupBarPlot(array($bplotzero, $ybplot2));
// Add the grouped bar plots to the graph
$graph->Add($ybplot);
$graph->AddY2($y2bplot);
// .. and finally stroke the image back to browser
$graph->Stroke();