예제 #1
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(220, 170);
$graph->SetScale("textlin", 3, 35);
$graph->yscale->ticks->Set(8, 2);
$graph->title->Set('Manual scale, manual ticks');
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$line = new Plot\LinePlot($ydata);
$graph->Add($line);
// Output graph
$graph->Stroke();
예제 #2
0
// Some data
$steps = 100;
for ($i = 0; $i < $steps; ++$i) {
    $datay[$i] = log(pow($i, $i / 10) + 1) * sin($i / 15) + 35;
    $datax[] = $i;
    if ($i % 10 == 0) {
        $databarx[] = $i;
        $databary[] = $datay[$i] / 2;
    }
}
// new Graph\Graph with a background image and drop shadow
$graph = new Graph\Graph(450, 300);
$graph->SetBackgroundImage("tiger_bkg.png", BGIMG_FILLFRAME);
$graph->SetShadow();
// Use an integer X-scale
$graph->SetScale("intlin");
// Set title and subtitle
$graph->title->Set("Combined bar and line plot");
$graph->subtitle->Set("(\"left\" aligned bars)");
// Use built in font
$graph->title->SetFont(FF_FONT1, FS_BOLD);
// Make the margin around the plot a little bit bigger
// then default
$graph->img->SetMargin(40, 120, 40, 40);
// Slightly adjust the legend from it's default position in the
// top right corner to middle right side
$graph->legend->Pos(0.05, 0.5, "right", "center");
// Create a red line plot
$p1 = new Plot\LinePlot($datay, $datax);
$p1->SetColor("red");
$p1->SetLegend("Status one");
예제 #3
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.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);
// We set the x-scale min/max values to avoid empty space
// on the side of the plot
$graph->SetScale('intlin', 0, 0, min($xdata), max($xdata));
$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 DateScaleUtils class)');
// 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);
// Get manual tick every second year
list($tickPos, $minTickPos) = $dateUtils->getTicks($xdata, DSUTILS_YEAR2);
$graph->xaxis->SetTickPositions($tickPos, $minTickPos);
예제 #4
0
    // We only make one pushpin another color
    if ($x == 54) {
        return array(false, false, false, 'red', 0.8);
    } else {
        return array(false, false, false, 'green', 0.8);
    }
}
// Data arrays
$datax = array(10, 20, 30, 40, 54, 60, 70, 80);
$datay = array(12, 23, 65, 18, 84, 28, 86, 44);
// Setup the graph
$graph = new Graph\Graph(400, 270);
// We add a small 1pixel left,right,bottom margin so the plot area
// doesn't cover the frame around the graph.
$graph->img->SetMargin(1, 1, 1, 1);
$graph->SetScale('linlin', 0, 100, 0, 100);
// We don't want any axis to be shown
$graph->xaxis->Hide();
$graph->yaxis->Hide();
// Use a worldmap as the background and let it fill the plot area
$graph->SetBackgroundImage(WORLDMAP, BGIMG_FILLPLOT);
// Setup a nice title with a striped bevel background
$graph->title->Set("Pushpin graph");
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 16);
$graph->title->SetColor('white');
$graph->SetTitleBackground('darkgreen', TITLEBKG_STYLE1, TITLEBKG_FRAME_BEVEL);
$graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED, 'blue', 'darkgreen');
// Finally create the lineplot
$lp = new Plot\LinePlot($datay, $datax);
$lp->SetColor('lightgray');
// We want the markers to be an image
예제 #5
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_utils.inc.php';
$f = new FuncGenerator('cos($i)', '$i*$i*$i');
list($xdata, $ydata) = $f->E(-M_PI, M_PI, 25);
$graph = new Graph\Graph(350, 430);
$graph->SetScale("linlin");
$graph->SetShadow();
$graph->img->SetMargin(50, 50, 60, 40);
$graph->SetBox(true, 'black', 2);
$graph->SetMarginColor('white');
$graph->SetColor('lightyellow');
$graph->SetAxisStyle(AXSTYLE_BOXIN);
$graph->xgrid->Show();
//$graph->xaxis->SetLabelFormat('%.0f');
$graph->img->SetMargin(50, 50, 60, 40);
$graph->title->Set("Function plot");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->subtitle->Set("(BOXIN Axis style)");
$graph->subtitle->SetFont(FF_FONT1, FS_NORMAL);
$lp1 = new Plot\LinePlot($ydata, $xdata);
$lp1->SetColor("blue");
$lp1->SetWeight(2);
$graph->Add($lp1);
$graph->Stroke();
<?php

// 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);
예제 #7
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
$datay = array(20, 10, 35, 5, 17, 35, 22);
// Setup the graph
$graph = new Graph\Graph(400, 250);
$graph->SetScale("intlin", 0, $aYMax = 50);
$theme_class = new UniversalTheme();
$graph->SetTheme($theme_class);
$graph->SetBox(false);
$graph->title->Set('Step Line');
$graph->ygrid->Show(true);
$graph->xgrid->Show(false);
$graph->yaxis->HideZeroLabel();
$graph->ygrid->SetFill(true, '#FFFFFF@0.5', '#FFFFFF@0.5');
$graph->SetBackgroundGradient('blue', '#55eeff', GRAD_HOR, BGRAD_PLOT);
$graph->xaxis->SetTickLabels(array('A', 'B', 'C', 'D', 'E', 'F', 'G'));
// Create the line
$p1 = new Plot\LinePlot($datay);
$graph->Add($p1);
$p1->SetFillGradient('yellow', 'red');
$p1->SetStepStyle();
$p1->SetColor('#808000');
// Output line
$graph->Stroke();
예제 #8
0
        $aSunspots[] = trim($split[1]);
    }
}
$year = array();
$ydata = array();
readsunspotdata('yearssn.txt', $year, $ydata);
// Just keep the last 20 values in the arrays
$year = array_slice($year, -20);
$ydata = array_slice($ydata, -20);
// 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,
// text = txt scale for the X-axis
// int = integer scale for the Y-axis
$graph->SetScale('textint');
// Setup a title for the graph
$graph->title->Set('Sunspot example');
// Setup titles and X-axis labels
$graph->xaxis->title->Set('(year)');
$graph->xaxis->SetTickLabels($year);
// Setup Y-axis title
$graph->yaxis->title->Set('(# sunspots)');
// Create the bar plot
$barplot = new Plot\BarPlot($ydata);
// Add the plot to the graph
$graph->Add($barplot);
// Display the graph
$graph->Stroke();
예제 #9
0
    $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);
// Adjust the start time for an "even" 5 minute, i.e. 5,10,15,20,25, ...
$graph->xaxis->scale->SetTimeAlign(MINADJ_5);
예제 #10
0
// Now get labels at the start of each month
$dateUtils = new DateScaleUtils();
list($tickPositions, $minTickPositions) = $dateUtils->GetTicks($datax);
// We add some grace to the end of the X-axis scale so that the first and last
// data point isn't exactly at the very end or beginning of the scale
$grace = 400000;
$xmin = $datax[0] - $grace;
$xmax = $datax[$n - 1] + $grace;
//
// The code to setup a very basic graph
//
$graph = new Graph\Graph(400, 200);
//
// We use an integer scale on the X-axis since the positions on the X axis
// are assumed to be UNI timestamps
$graph->SetScale('intlin', 0, 0, $xmin, $xmax);
$graph->title->Set('Basic example with manual ticks');
$graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12);
//
// 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->SetTickPositions($tickPositions, $minTickPositions);
// The labels should be formatted at dates with "Year-month"
$graph->xaxis->SetLabelFormatString('My', true);
// Use Ariel font
$graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 9);
// Add a X-grid
$graph->xgrid->Show();
예제 #11
0
        $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', 0, 0, 0, max($year) - min($year) + 1);
// 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();
예제 #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();
예제 #13
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_log.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_scatter.php';
$ab2 = array(1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 12.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0, 75.0, 100.0, 125.0, 150.0);
$mn2 = array(0.5, 0.5, 0.5, 0.5, 0.8, 0.8, 0.8, 0.8, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 5.0, 5.0, 5.0);
$rhos = array(30.0, 31.0, 32.0, 34.0, 35.5, 37.5, 38.0, 39.5, 41.5, 43.0, 41.0, 42.0, 42.5, 45.0, 49.0, 53.5, 58.0, 66.5, 75.0, 81.0, 89.0);
// Create the graph.
$graph = new Graph\Graph(500, 300);
$graph->SetScale("loglog");
$graph->SetY2Scale("lin");
$graph->y2axis->SetColor("blue", "blue");
$graph->img->SetMargin(50, 70, 40, 50);
$graph->title->Set("Geoelektrik");
$graph->xaxis->title->Set("Auslage ab/2 [m]");
$graph->yaxis->title->Set("rho_s [Ohm m]");
$graph->y2axis->title->Set("mn/2 [m]");
$graph->y2axis->title->SetColor("blue");
$graph->y2axis->SetTitleMargin(35);
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xgrid->Show(true, true);
$graph->ygrid->Show(true, true);
// Create the linear plot
$lineplot = new Plot\LinePlot($rhos, $ab2);
$lineplot->SetWeight(1);
$lineplot->mark->SetType(MARK_FILLEDCIRCLE);
예제 #14
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_log.php';
require_once 'jpgraph/jpgraph_error.php';
$xdata = array(2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 12.0, 15.0, 20.0, 25.0, 30.0, 40.0, 50.0, 60.0, 75.0, 100.0, 125.0, 150.0, 175.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 800.0, 950.0, 1200.0, 1500.0, 2000.0, 2500.0);
$ydata = array(270.0, 280.0, 330.0, 340.0, 410.0, 420.0, 550.0, 560.0, 670.0, 680.0, 770.0, 780.0, 930.0, 940.0, 1010.0, 1020.0, 1040.0, 1050.0, 980.0, 990.0, 860.0, 870.0, 720.0, 730.0, 590.0, 600.0, 370.0, 380.0, 330.0, 340.0, 320.0, 330.0, 320.0, 330.0, 300.0, 310.0, 305.0, 315.0, 310.0, 320.0, 315.0, 325.0, 300.0, 310.0, 270.0, 280.0, 240.0, 250.0, 200.0, 210.0, 150.0, 160.0, 120.0, 130.0, 50.0, 60.0, 30.0, 40.0, 15.0, 20.0, 8.0, 10.0, 7.0, 9.0, 8.0, 10.0);
$graph = new Graph\Graph(500, 300);
$graph->SetScale("linlog");
$graph->img->SetMargin(40, 20, 20, 40);
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->Set("ab/2");
$graph->yaxis->title->Set("rho_s");
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->ygrid->Show(true, true);
$graph->xgrid->Show(true, true);
$errorplot = new Plot\ErrorPlot($ydata, $xdata);
$graph->Add($errorplot);
$graph->Stroke();
예제 #15
0
    }
    foreach ($lines as $line => $datarow) {
        $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)');
// Setup Y-axis title
$graph->yaxis->title->Set('(# sunspots)');
// Create the linear plot
$lineplot = new Plot\LinePlot($ydata);
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
예제 #16
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');
예제 #17
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
$datay1 = array(4, 26, 12, 18, 8, 22);
$datay2 = array(12, 9, 42, 8, 20, 19);
// Setup the graph
$graph = new Graph\Graph(300, 200);
$graph->SetMarginColor('white');
$graph->SetScale("textlin", 0, 50);
$graph->SetMargin(30, 50, 30, 30);
// We must have the frame enabled to get the gradient
// However, we don't want the frame line so we set it to
// white color which makes it invisible.
$graph->SetFrame(true, 'white');
// Setup a background gradient image
$graph->SetBackgroundGradient('blue', 'navy:0.5', GRAD_HOR, BGRAD_PLOT);
// Setup the tab title
$graph->tabtitle->Set(' 3rd Division ');
$graph->tabtitle->SetFont(FF_ARIAL, FS_BOLD, 13);
// Setup x,Y grid
$graph->xgrid->Show();
$graph->xgrid->SetColor('gray@0.5');
$graph->xaxis->SetTickLabels($gDateLocale->GetShortMonth());
$graph->ygrid->SetColor('gray@0.5');
// Setup color for axis and labels on axis
$graph->xaxis->SetColor('orange', 'black');
$graph->yaxis->SetColor('orange', 'black');
// Ticks on the outsid
$graph->xaxis->SetTickSide(SIDE_DOWN);
예제 #18
0
$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);
//
$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);
예제 #19
0
<?php

// 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');
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40, 30, 40, 40);
// Create a bar pot
$bplot = new Plot\BarPlot($datay);
$graph->Add($bplot);
// Create and add a new text
$txt = new Text('This is a text');
$txt->SetPos(10, 20);
$txt->SetColor('darkred');
$txt->SetFont(FF_FONT2, FS_BOLD);
$txt->SetBox('yellow', 'navy', 'gray@0.5');
$graph->AddText($txt);
// Setup the titles
$graph->title->Set("A simple bar graph");
$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
예제 #20
0
            $h = sqrt($d1 * $d1 + $d2 * $d2);
            $t = -$d2 / $h;
            $ac = acos($t);
            if ($y < $poley) {
                $ac += M_PI;
            }
            $a = $ac * 180 / M_PI;
        }
        $datax[] = $x;
        $datay[] = $y;
        $angle[] = $a;
    }
}
// Setup the graph
$graph = new Graph\Graph(300, 200);
$graph->SetScale("intlin", 0, 100, 0, 10);
$graph->SetMarginColor('lightblue');
// ..and titles
$graph->title->Set("Field plot");
// Setup the field plot
$fp = new FieldPlot($datay, $datax, $angle);
// Setup formatting callback
$fp->SetCallback('FldCallback');
// First size argument is length (in pixels of arrow)
// Second size argument is roughly size of arrow. Arrow size is specified as
// an integer in the range [0,9]
$fp->arrow->SetSize(20, 2);
$fp->arrow->SetColor('navy');
$graph->Add($fp);
// .. and output
$graph->Stroke();
예제 #21
0
    if ($i % 2) {
        $tickLabels[$i] = $i . '/2' . SymChar::Get('pi');
    } else {
        $tickLabels[$i] = $i / 2 . SymChar::Get('pi');
    }
}
$n = count($datax);
$xmin = $datax[0];
$xmax = $datax[$n - 1];
//
// The code to setup a very basic graph
//
$graph = new Graph\Graph(400, 200);
// We use an integer scale on the X-axis since the positions on the X axis
// are assumed to be UNI timestamps
$graph->SetScale('linlin', 0, 0, $xmin, $xmax);
$graph->title->Set('Example with manual tick labels');
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
$graph->title->SetColor('white');
// Setup a abackground gradient
$graph->SetBackgroundGradient('darkred:0.7', 'black', 2, BGRAD_MARGIN);
$graph->SetPlotGradient('black', 'darkred:0.8', 2);
// 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);
예제 #22
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;
 }
예제 #23
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();
예제 #24
0
<?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();
예제 #25
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_scatter.php';
// Make a circle with a scatterplot
$steps = 16;
for ($i = 0; $i < $steps; ++$i) {
    $a = 2 * M_PI / $steps * $i;
    $datax[$i] = cos($a);
    $datay[$i] = sin($a);
}
$graph = new Graph\Graph(350, 230);
$graph->SetScale('linlin');
$graph->SetShadow();
$graph->SetAxisStyle(AXSTYLE_BOXOUT);
$graph->img->SetMargin(50, 50, 60, 40);
$graph->title->Set('Linked scatter plot');
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->subtitle->Set('(BOXOUT Axis style)');
$graph->subtitle->SetFont(FF_FONT1, FS_NORMAL);
// 10% top and bottom grace
$graph->yscale->SetGrace(5, 5);
$graph->xscale->SetGrace(1, 1);
$sp1 = new ScatterPlot($datay, $datax);
$sp1->mark->SetType(MARK_FILLEDCIRCLE);
$sp1->mark->SetFillColor('red');
$sp1->SetColor('blue');
$sp1->mark->SetWidth(4);
$sp1->link->Show();
$sp1->link->SetStyle('dotted');
예제 #26
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();
예제 #27
0
<?php

// 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
예제 #28
0
}
$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();