Exemple #1
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_bar.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_plotline.php';
$datay = array(2, 3, 5, 8.5, 11.5, 6, 3);
// Create the graph.
$graph = new Graph\Graph(460, 400, 'auto');
$graph->SetScale("textlin");
$graph->SetMargin(40, 20, 50, 70);
$graph->legend->SetPos(0.5, 0.97, 'center', 'bottom');
$graph->title->Set('Plot line legend');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 14);
$graph->SetTitleBackground('lightblue:1.3', TITLEBKG_STYLE2, TITLEBKG_FRAME_BEVEL);
$graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED, 'lightblue', 'navy');
// Create a bar pot
$bplot = new Plot\BarPlot($datay);
$bplot->value->Show();
$bplot->value->SetFont(FF_VERDANA, FS_BOLD, 8);
$bplot->SetValuePos('top');
$bplot->SetLegend('Bar Legend');
$graph->Add($bplot);
$pline = new PlotLine(HORIZONTAL, 8, 'red', 2);
$pline->SetLegend('Line Legend');
$graph->legend->SetColumns(10);
$graph->Add($pline);
$graph->Stroke();
Exemple #2
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
$ydata = array(12, 17, 22, 19, 5, 15);
$graph = new Graph\Graph(270, 170);
$graph->SetMargin(30, 90, 30, 30);
$graph->SetScale("textlin");
$graph->img->SetAngle(90);
$graph->img->SetCenter(floor(270 / 2), floor(170 / 2));
$line = new Plot\LinePlot($ydata);
$line->SetLegend('2002');
$line->SetColor('darkred');
$line->SetWeight(2);
$graph->Add($line);
// Output graph
$graph->Stroke();
$n = 5;
for ($i = 0; $i < $n; ++$i) {
    $targ1[$i] = "#{$i}";
    $targ2[$i] = "#{$i}";
    $targ3[$i] = "#{$i}";
    $alts1[$i] = "val=%d";
    $alts2[$i] = "val=%d";
    $alts3[$i] = "val=%d";
}
// Some data for the points
$datay1 = array(3, 10, 4, 1, 6);
$datay2 = array(25, 22, 18, 24, 20);
$datay3 = array(89, 70, 92, 77, 96);
// Create a basic graph with some suitable margins
$graph = new Graph\Graph(500, 250);
$graph->SetMargin(60, 180, 50, 40);
$graph->SetMarginColor('white');
$graph->title->Set("Multi Y-axes with Image Map");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
// Setup the scales for all axes
$graph->SetScale("intlin");
$graph->SetYScale(0, 'int');
$graph->SetYScale(1, 'int');
// Standard Y-axis plot
$lp1 = new Plot\LinePlot($datay1);
$lp1->SetLegend('2001');
$lp1->mark->SetType(MARK_DIAMOND);
$lp1->mark->SetWidth(15);
$lp1->mark->SetFillColor('orange');
$lp1->SetCSIMTargets($targ1, $alts1);
$graph->yaxis->title->Set('Basic Rate');
Exemple #4
0
// 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();
<?php

// content="text/plain; charset=utf-8"
require_once '../jpgraph.php';
require_once '../jpgraph_bar.php';
$datay = array(12, 26, 9, 17, 31);
// Create the graph.
$graph = new Graph\Graph(400, 250);
$graph->SetScale('textlin');
$graph->SetMargin(50, 80, 20, 40);
// Create a bar pot
$bplot = new Plot\BarPlot($datay);
$n = count($datay);
// Number of bars
global $_wrapperfilename;
// Create targets for the image maps. One for each column
$targ = array();
$alt = array();
$wtarg = array();
for ($i = 0; $i < $n; ++$i) {
    $urlarg = 'clickedon=' . ($i + 1);
    $targ[] = $_wrapperfilename . '?' . $urlarg;
    $alt[] = 'val=%d';
    $wtarg[] = '';
}
$bplot->SetCSIMTargets($targ, $alt, $wtarg);
$graph->Add($bplot);
$graph->title->Set('Multiple Image maps');
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->title->SetCSIMTarget('#45', 'Title for Bar', '_blank');
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
Exemple #6
0
<?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();
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_plotline.php';
$datay1 = array(2, 6, 7, 12, 13, 18);
$datay2 = array(5, 12, 12, 19, 25, 20);
// Setup the graph
$graph = new Graph\Graph(350, 200);
$graph->SetMargin(30, 20, 60, 20);
$graph->SetMarginColor('white');
$graph->SetScale("linlin");
// Hide the frame around the graph
$graph->SetFrame(false);
// Setup title
$graph->title->Set("Using Builtin PlotMarks");
$graph->title->SetFont(FF_VERDANA, FS_BOLD, 14);
// Note: requires jpgraph 1.12p or higher
// $graph->SetBackgroundGradient('blue','navy:0.5',GRAD_HOR,BGRAD_PLOT);
$graph->tabtitle->Set('Region 1');
$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);
Exemple #8
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
$datay1 = array(20, 15, 23, 15);
$datay2 = array(12, 9, 42, 8);
$datay3 = array(5, 17, 32, 24);
// Setup the graph
$graph = new Graph\Graph(300, 200);
$graph->SetMarginColor('white');
$graph->SetScale("textlin");
$graph->SetFrame(false);
$graph->SetMargin(30, 50, 30, 30);
$graph->tabtitle->Set(' Year 2003 ');
$graph->tabtitle->SetFont(FF_ARIAL, FS_BOLD, 13);
$graph->yaxis->HideZeroLabel();
$graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5');
$graph->xgrid->Show();
$graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());
// Create the first line
$p1 = new Plot\LinePlot($datay1);
$p1->SetColor("navy");
$p1->SetLegend('Line 1');
$graph->Add($p1);
// Create the second line
$p2 = new Plot\LinePlot($datay2);
$p2->SetColor("red");
$p2->SetLegend('Line 2');
$graph->Add($p2);
// Create the third line
$startbid = 8000;
for ($i = 0; $i < $m; ++$i) {
    $bids[$i] = array($startbid + rand(100, 500) * 10);
    for ($j = 1; $j < $n; ++$j) {
        $bids[$i][$j] = $bids[$i][$j - 1] + rand(20, 500) * 10;
    }
}
$start = floor(time() / INTERVAL) * INTERVAL;
$times = array($start);
for ($i = 1; $i < $n; ++$i) {
    // Create a timestamp for every 5 minutes
    $times[$i] = $times[$i - 1] + INTERVAL;
}
// Setup the bid graph
$graph = new Graph\Graph(600, 250);
$graph->SetMargin(80, 30, 50, 40);
$graph->SetMarginColor('white');
$graph->SetScale('dateint');
$graph->title->Set('Current Bids');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
$graph->subtitle->Set('(Updated every 5 minutes)');
$graph->subtitle->SetFont(FF_ARIAL, FS_ITALIC, 10);
// Enable antialias
$graph->img->SetAntiAliasing();
// Setup the y-axis to show currency values
$graph->yaxis->SetLabelFormatCallback('number_format');
$graph->yaxis->SetLabelFormat('$%s');
//Use hour:minute format for the labels
$graph->xaxis->scale->SetDateFormat('H:i');
// Force labels to only be displayed every 5 minutes
$graph->xaxis->scale->ticks->Set(INTERVAL);
Exemple #10
0
$n = count($ydata);
$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
Exemple #11
0
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_bar.php';
function toFahrenheit($aVal)
{
    return round($aVal * 9 / 5 + 32, 2);
}
function toCelcius($aVal)
{
    return round(($aVal - 32) * 5 / 9, 2);
}
$datay = array(2, 3, 8, 19, 7, 17, 6, 22);
// Create the graph.
$graph = new Graph\Graph(400, 280);
// Slightly bigger margins than default to make room for titles
$graph->SetMargin(50, 60, 40, 45);
$graph->SetMarginColor('white');
// Setup the scales for X,Y and Y2 axis
$graph->SetScale("intlin");
// X and Y axis
$graph->SetY2Scale("lin");
// Y2 axis
// Overall graph title
$graph->title->Set('Synchronized Y & Y2 scales');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
// Title for X-axis
$graph->xaxis->title->Set('Measurement');
$graph->xaxis->title->SetMargin(5);
$graph->xaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 11);
// Create Y data set
$lplot = new Plot\LinePlot($datay);
Exemple #12
0
// Set the start time to be on the closest minute just before the "start" timestamp
$adjstart = floor($start / 60);
// Create a data set in range (20,100) and X-positions
// We also apply a simple low pass filter on the data to make it less
// random and a little smoother
$data = array();
$xdata = array();
$data[0] = rand(20, 100);
$xdata[0] = $adjstart;
for ($i = 1; $i < NDATAPOINTS; ++$i) {
    $data[$i] = rand(20, 100) * 0.2 + $data[$i - 1] * 0.8;
    $xdata[$i] = $adjstart + $i * SAMPLERATE;
}
// Assume that the data points represents data that is sampled every 10s
// when determing the end value on the scale. We also add some extra
// length to end on an even label tick.
$adjend = $adjstart + (NDATAPOINTS + 10) * 10;
$graph = new Graph\Graph(500, 250);
$graph->SetMargin(40, 20, 30, 50);
// Now specify the X-scale explicit but let the Y-scale be auto-scaled
$graph->SetScale("intlin", 0, 0, $adjstart, $adjend);
$graph->title->Set("Example on TimeStamp Callback");
// Setup the callback and adjust the angle of the labels
$graph->xaxis->SetLabelFormatCallback('TimeCallback');
$graph->xaxis->SetLabelAngle(90);
// Set the labels every 5min (i.e. 300seconds) and minor ticks every minute
$graph->xaxis->scale->ticks->Set(300, 60);
$line = new Plot\LinePlot($data, $xdata);
$line->SetColor('lightblue');
$graph->Add($line);
$graph->Stroke();
Exemple #13
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
// Some data
$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(200, 150);
$graph->SetScale("textlin");
$graph->SetMargin(25, 10, 30, 30);
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
$graph->title->Set('The Title');
$graph->subtitle->SetFont(FF_ARIAL, FS_BOLD, 10);
$graph->subtitle->Set('The Subtitle');
$graph->subsubtitle->SetFont(FF_ARIAL, FS_ITALIC, 9);
$graph->subsubtitle->Set('The Subsubitle');
// Create the linear plot
$lineplot = new Plot\LinePlot($ydata);
$lineplot->SetColor("blue");
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
Exemple #14
0
$graph->SetMarginColor('white');
$graph->SetFrame(false);
$graph->SetBox(true);
$graph->title->Set('Example of combined graph');
$graph->title->SetFont(FF_ARIAL, FS_NORMAL, 14);
$graph->xaxis->SetTickPositions($tickPositions, $minTickPositions);
$graph->xaxis->SetLabelFormatString('My', true);
$graph->xgrid->Show();
$p1 = new Plot\LinePlot($datay, $datax);
$graph->Add($p1);
//----------------------
// Setup the bar graph
//----------------------
$graph2 = new Graph\Graph($w, 110);
$graph2->SetScale('linlin', 0, 0, $xmin, $xmax);
$graph2->SetMargin($lm, $rm, 5, 10);
$graph2->SetMarginColor('white');
$graph2->SetFrame(false);
$graph2->SetBox(true);
$graph2->xgrid->Show();
$graph2->xaxis->SetTickPositions($tickPositions, $minTickPositions);
$graph2->xaxis->SetLabelFormatString('My', true);
$graph2->xaxis->SetPos('max');
$graph2->xaxis->HideLabels();
$graph2->xaxis->SetTickSide(SIDE_DOWN);
$b1 = new Plot\BarPlot($datay2, $datax);
$b1->SetFillColor('teal');
$b1->SetColor('teal:1.2');
$graph2->Add($b1);
//-----------------------
// Create a multigraph
Exemple #15
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_date.php';
require_once 'jpgraph/jpgraph_utils.inc.php';
// Get a dataset stored in $xdata and $ydata
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');
<?php

// content="text/plain; charset=utf-8"
// Illustration of the different patterns for bands
// $Id: smallstaticbandsex7.php,v 1.1 2002/09/01 21:51:08 aditus Exp $
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_bar.php';
$datay = array(10, 29, 3, 6);
// Create the graph.
$graph = new Graph\Graph(200, 150);
$graph->SetScale("textlin");
$graph->SetMargin(25, 10, 20, 20);
// Add 10% grace ("space") at top and botton of Y-scale.
$graph->yscale->SetGrace(10);
// Create a bar pot
$bplot = new Plot\BarPlot($datay);
$bplot->SetFillColor("lightblue");
// Position the X-axis at the bottom of the plotare
$graph->xaxis->SetPos("min");
$graph->ygrid->Show(false);
// .. and add the plot to the graph
$graph->Add($bplot);
// Add band
$band = new Plot\PlotBand(HORIZONTAL, BAND_HLINE, 15, 35, 'khaki4');
$band->ShowFrame(false);
$graph->Add($band);
// Set title
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 10);
$graph->title->SetColor('darkred');
$graph->title->Set('BAND_HLINE');
$graph->Stroke();
Exemple #17
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_scatter.php';
$datay1 = array(4, 26, 15, 44);
// Setup the graph
$graph = new Graph\Graph(300, 200);
$graph->SetMarginColor('white');
$graph->SetScale("textlin");
$graph->SetFrame(false);
$graph->SetMargin(30, 5, 25, 20);
// Setup the tab
$graph->tabtitle->Set(' Year 2003 ');
$graph->tabtitle->SetFont(FF_ARIAL, FS_BOLD, 13);
$graph->tabtitle->SetColor('darkred', '#E1E1FF');
// Enable X-grid as well
$graph->xgrid->Show();
// Use months as X-labels
$graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());
// Create the plot
$p1 = new Plot\LinePlot($datay1);
$p1->SetColor("navy");
// Use an image of favourite car as marker
$p1->mark->SetType(MARK_IMG, 'saab_95.jpg', 0.5);
// Displayes value on top of marker image
$p1->value->SetFormat('%d mil');
$p1->value->Show();
$p1->value->SetColor('darkred');
$p1->value->SetFont(FF_ARIAL, FS_BOLD, 10);
// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_log.php';
// Matrix size rxr
$r = 10;
// Max Interpolation factor
$f = 5;
for ($i = 1; $i <= $f; ++$i) {
    $xdata[] = $i;
    $ydata[] = pow($r * pow(2, $i - 1) - (pow(2, $i) - 1), 2);
}
$graph = new Graph\Graph(400, 240);
$graph->SetScale('intlog');
$graph->SetMargin(50, 50, 20, 30);
$graph->SetFrame(false);
$graph->SetBox(true, 'black', 2);
$graph->SetMarginColor('white');
$graph->SetColor('lightyellow@0.7');
$graph->title->Set('Interpolation growth for size 10x10');
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->SetTitle('Interpolation factor', 'center');
$graph->xaxis->SetTitleMargin(10);
$graph->SetAxisStyle(AXSTYLE_YBOXIN);
$graph->xgrid->Show();
$lp1 = new Plot\LinePlot($ydata, $xdata);
$lp1->SetColor('darkred');
$lp1->SetWeight(3);
$graph->Add($lp1);
$graph->Stroke();
Exemple #19
0
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_scatter.php';
require_once 'jpgraph/jpgraph_regstat.php';
// Original data points
$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);
//
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
// Some data
$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(350, 250);
$graph->SetScale("textlin");
$graph->SetMargin(40, 40, 50, 50);
// Setup the grid and plotarea box
$graph->ygrid->SetLineStyle('dashed');
$graph->ygrid->setColor('darkgray');
$graph->SetBox(true);
// Steup graph titles
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
$graph->title->Set('Using background image');
$graph->subtitle->SetFont(FF_COURIER, FS_BOLD, 11);
$graph->subtitle->Set('"BGIMG_FILLFRAME"');
$graph->subtitle->SetColor('darkred');
// Add background with 25% mix
$graph->SetBackgroundImage('heat1.jpg', BGIMG_FILLFRAME);
$graph->SetBackgroundImageMix(25);
// Create the linear plot
$lineplot = new Plot\LinePlot($ydata);
$lineplot->SetColor("blue");
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
Exemple #21
0
 /**
  * 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;
 }
Exemple #22
0
<?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);
Exemple #23
0
    return Date('H:i:s', $aVal);
}
// Fake some suitable random data
$now = time();
$datax = array($now);
for ($i = 0; $i < 360; $i += 10) {
    $datax[] = $now + $i;
}
$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);