<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $datay = array(1.23, 1.9, 1.6, 3.1, 3.4, 2.8, 2.1, 1.9); $graph = new Graph\Graph(300, 200); $graph->SetScale("textlin"); $graph->img->SetMargin(40, 40, 40, 40); $graph->SetShadow(); $graph->SetGridDepth(DEPTH_FRONT); $graph->title->Set("Example of filled line plot"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $p1 = new Plot\LinePlot($datay); $p1->SetFillColor("orange"); $p1->mark->SetType(MARK_FILLEDCIRCLE); $p1->mark->SetFillColor("red"); $p1->mark->SetWidth(4); $graph->Add($p1); $graph->Stroke();
// Make sure that the X-axis is always at the bottom of the scale // (By default the X-axis is alwys positioned at Y=0 so if the scale // doesn't happen to include 0 the axis will not be shown) $graph->xaxis->SetPos('min'); // Now set the tic positions $graph->xaxis->SetMajTickPositions($tickPositions, $tickLabels); // Use Times font $graph->xaxis->SetFont(FF_TIMES, FS_NORMAL, 11); $graph->yaxis->SetFont(FF_TIMES, FS_NORMAL, 9); // Set colors for axis $graph->xaxis->SetColor('lightgray'); $graph->yaxis->SetColor('lightgray'); // Add a X-grid $graph->xgrid->Show(); // Show ticks outwards $graph->xaxis->SetTickSide(SIDE_DOWN); $graph->xaxis->SetLabelMargin(8); $graph->yaxis->SetTickSide(SIDE_LEFT); // Setup a filled y-grid //$graph->ygrid->SetFill(true,'darkgray:1.55@0.7','darkgray:1.6@0.7'); $graph->ygrid->SetStyle('dotted'); $graph->xgrid->SetStyle('dashed'); // Create the plot line $p1 = new Plot\LinePlot($datay, $datax); $p1->SetWeight(2); $p1->SetColor('orange:0.9'); $p1->SetFillColor('white@0.7'); $p1->SetFillFromYMin(); $graph->Add($p1); // Output graph $graph->Stroke();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $datay = array(11, 30, 20, 13, 10, 'x', 16, 12, 'x', 15, 4, 9); // Setup the graph $graph = new Graph\Graph(400, 250); $graph->SetScale('intlin'); $graph->title->Set('Filled line with NULL values'); //Make sure data starts from Zero whatever data we have $graph->yscale->SetAutoMin(0); $p1 = new Plot\LinePlot($datay); $p1->SetFillColor('lightblue'); $graph->Add($p1); // Output line $graph->Stroke();
// content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; require_once 'jpgraph/jpgraph_date.php'; // Create a data set in range (50,70) and X-positions DEFINE('NDATAPOINTS', 360); DEFINE('SAMPLERATE', 240); $start = time(); $end = $start + NDATAPOINTS * SAMPLERATE; $data = array(); $xdata = array(); for ($i = 0; $i < NDATAPOINTS; ++$i) { $data[$i] = rand(50, 70); $xdata[$i] = $start + $i * SAMPLERATE; } // Create the new Graph\Graph $graph = new Graph\Graph(540, 300); // Slightly larger than normal margins at the bottom to have room for // the x-axis labels $graph->SetMargin(40, 40, 30, 130); // Fix the Y-scale to go between [0,100] and use date for the x-axis $graph->SetScale('datlin', 0, 100); $graph->title->Set("Example on Date scale"); // Set the angle for the labels to 90 degrees $graph->xaxis->SetLabelAngle(90); $line = new Plot\LinePlot($data, $xdata); $line->SetLegend('Year 2005'); $line->SetFillColor('lightblue@0.5'); $graph->Add($line); $graph->Stroke();
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();
{ $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();
$graph->tabtitle->SetWidth(TABTITLE_WIDTHFULL); // Enable X and Y Grid $graph->xgrid->Show(); $graph->xgrid->SetColor('gray@0.5'); $graph->ygrid->SetColor('gray@0.5'); // Format the legend box $graph->legend->SetColor('navy'); $graph->legend->SetFillColor('lightgreen'); $graph->legend->SetLineWeight(1); $graph->legend->SetFont(FF_ARIAL, FS_BOLD, 8); $graph->legend->SetShadow('gray@0.4', 3); $graph->legend->SetAbsPos(15, 120, 'right', 'bottom'); // Create the line plots $p1 = new Plot\LinePlot($datay1); $p1->SetColor("red"); $p1->SetFillColor("yellow@0.5"); $p1->SetWeight(2); $p1->mark->SetType(MARK_IMG_DIAMOND, 5, 0.6); $p1->SetLegend('2006'); $graph->Add($p1); $p2 = new Plot\LinePlot($datay2); $p2->SetColor("darkgreen"); $p2->SetWeight(2); $p2->SetLegend('2001'); $p2->mark->SetType(MARK_IMG_MBALL, 'red'); $graph->Add($p2); // Add a vertical line at the end scale position '7' $l1 = new PlotLine(VERTICAL, 7); $graph->Add($l1); // Output the graph $graph->Stroke();
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; require_once 'jpgraph/jpgraph_error.php'; //$datax = array(3.5,3.7,3,4,6.2,6,3.5,8,14,8,11.1,13.7); $datay = array(1.23, 1.9, 1.6, 3.1, 3.4, 2.8, 2.1, 1.9); $graph = new Graph\Graph(300, 200); $graph->img->SetMargin(40, 40, 40, 40); $graph->img->SetAntiAliasing(); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->title->Set("Example of filled line centered plot"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $p1 = new Plot\LinePlot($datay); $p1->SetFillColor("green"); $p1->mark->SetType(MARK_FILLEDCIRCLE); $p1->mark->SetFillColor("red"); $p1->mark->SetWidth(4); $p1->SetColor("blue"); $p1->SetCenter(); $graph->Add($p1); $graph->Stroke();
$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)'); $graph->xaxis->SetTickLabels($year); // Setup Y-axis title $graph->yaxis->title->Set('(# sunspots)'); // Create the linear plot $lineplot = new Plot\LinePlot($ydata); $lineplot->SetFillColor('orange@0.5'); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke();
require_once '../jpgraph.php'; require_once '../jpgraph_line.php'; $datay = array(0, 3, 5, 12, 15, 18, 22, 36, 37, 41); // Setup the graph $graph = new Graph\Graph(320, 200); $graph->title->Set('Education growth'); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph->SetScale('intlin'); $graph->SetMarginColor('white'); $graph->SetBox(); //$graph->img->SetAntialiasing(); $graph->SetGridDepth(DEPTH_FRONT); $graph->ygrid->SetColor('gray@0.7'); $graph->SetBackgroundImage('classroom.jpg', BGIMG_FILLPLOT); // Masking graph $p1 = new Plot\LinePlot($datay); $p1->SetFillColor('white'); $p1->SetFillFromYMax(); $p1->SetWeight(0); $graph->Add($p1); // Line plot $p2 = new Plot\LinePlot($datay); $p2->SetColor('black@0.4'); $p2->SetWeight(3); $p2->mark->SetType(MARK_SQUARE); $p2->mark->SetColor('orange@0.5'); $p2->mark->SetFillColor('orange@0.3'); $graph->Add($p2); // Output line $graph->Stroke();
} $n = count($datax); $datay = array(); for ($i = 0; $i < $n; ++$i) { $datay[] = rand(30, 150); } // Setup the basic graph $graph = new Graph\Graph(324, 250); $graph->SetMargin(40, 40, 30, 70); $graph->title->Set('Date: ' . date('Y-m-d', $now)); $graph->SetAlphaBlending(); // Setup a manual x-scale (We leave the sentinels for the // Y-axis at 0 which will then autoscale the Y-axis.) // We could also use autoscaling for the x-axis but then it // probably will start a little bit earlier than the first value // to make the first value an even number as it sees the timestamp // as an normal integer value. $graph->SetScale("intlin", 0, 200, $now, $datax[$n - 1]); // Setup the x-axis with a format callback to convert the timestamp // to a user readable time $graph->xaxis->SetLabelFormatCallback('TimeCallback'); $graph->xaxis->SetLabelAngle(90); // Create the line $p1 = new Plot\LinePlot($datay, $datax); $p1->SetColor("blue"); // Set the fill color partly transparent $p1->SetFillColor("blue@0.4"); // Add lineplot to the graph $graph->Add($p1); // Output line $graph->Stroke();