Exemplo n.º 1
0
<?php

# $Id$
# PHPlot Example: Two plots on one image
require_once 'phplot.php';
$data1 = array(array('1981', 5996), array('1982', 5113), array('1983', 5051), array('1984', 5437), array('1985', 5067), array('1986', 6224), array('1987', 6678), array('1988', 7402), array('1989', 8061), array('1990', 8018), array('1991', 7627), array('1992', 7888), array('1993', 8620), array('1994', 8996), array('1995', 8835), array('1996', 9478), array('1997', 10162), array('1998', 10708), array('1999', 10852), array('2000', 11459));
$data2 = array(array('1981', 595), array('1982', 815), array('1983', 739), array('1984', 722), array('1985', 781), array('1986', 785), array('1987', 764), array('1988', 815), array('1989', 859), array('1990', 857), array('1991', 1001), array('1992', 950), array('1993', 1003), array('1994', 942), array('1995', 949), array('1996', 981), array('1997', 1003), array('1998', 945), array('1999', 940), array('2000', 1040));
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
# Disable auto-output:
$plot->SetPrintImage(0);
# There is only one title: it is outside both plot areas.
$plot->SetTitle('US Petroleum Import/Export');
# Set up area for first plot:
$plot->SetPlotAreaPixels(80, 40, 740, 350);
# Do the first plot:
$plot->SetDataType('text-data');
$plot->SetDataValues($data1);
$plot->SetPlotAreaWorld(NULL, 0, NULL, 13000);
$plot->SetDataColors(array('blue'));
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->SetYTickIncrement(1000);
$plot->SetYTitle("IMPORTS\n1000 barrels/day");
$plot->SetPlotType('bars');
$plot->DrawGraph();
# Set up area for second plot:
$plot->SetPlotAreaPixels(80, 400, 740, 550);
# Do the second plot:
$plot->SetDataType('text-data');
$plot->SetDataValues($data2);
Exemplo n.º 2
0
foreach ($data as $row) {
    $legend[] = $row[0] . ' = ' . $row[1];
}
# Common setup for all plots on the image:
$plot = new PHPlot(800, 625);
$plot->SetTitle('Multiple pie charts');
$plot->SetPrintImage(False);
$plot->SetBackgroundColor('wheat');
$plot->SetDrawPlotAreaBackground(True);
$plot->SetPlotType('pie');
$plot->SetDataType($data_type);
$plot->SetDataValues($data);
$plot->SetPlotBorderType('full');
#$plot->SetLabelScalePosition(0.50);
# Plot 1 - upper left
$plot->SetPlotAreaPixels(4, 25, 398, 323);
$plot->SetPieLabelType('label');
$plot->SetPlotBgColor('plum');
$plot->DrawGraph();
# Plot 2 - upper right
$plot->SetPlotAreaPixels(402, 25, 797, 323);
$plot->SetPieLabelType('index');
$plot->SetPlotBgColor('salmon');
$plot->DrawGraph();
# Plot 3 - lower left
$plot->SetPlotAreaPixels(4, 327, 398, 623);
$plot->SetPieLabelType('');
// Reset to default
$plot->SetDrawPlotAreaBackground(False);
$plot->DrawGraph();
# Plot 4 - lower right
Exemplo n.º 3
0
# A TrueType font to use:
$font = $phplot_test_ttfdir . $phplot_test_ttfonts['sansbold'];
extract($tp);
// Import test parameters
$data = array(array('', 0, 0, 0, 0), array('', 1, 1, 2, 3), array('', 2, 2, 4, 6), array('', 3, 3, 6, 9));
$legend = array('Plot Line 1', 'Longer label for Plot Line 2', 'line 3');
$p = new PHPlot(800, 600);
if (!empty($title)) {
    // $title can be set empty for special case
    if (!empty($suffix)) {
        $title .= "\n" . $suffix;
    }
    $p->SetTitle($title);
}
// Use smaller window, offset, so legend position is more apparent.
$p->SetPlotAreaPixels(100, 80, 700, 480);
$p->SetLegend($legend);
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotType('lines');
$p->SetXDataLabelPos('none');
$p->SetXTickIncrement(1.0);
$p->SetYTickIncrement(1.0);
$p->SetDrawXGrid(True);
if (isset($ttfontsize)) {
    $p->SetFontTTF('legend', $font, $ttfontsize, $ttlinespace);
}
if (isset($relto)) {
    $p->SetLegendPosition($lx, $ly, $relto, $bx, $by, $ox, $oy);
}
if (isset($callback)) {
Exemplo n.º 4
0
# This is a cubic equation with roots at -8, 2, 10
for ($x = -10; $x <= 10; $x++) {
    $data[] = array('', $x, ($x + 8) * ($x - 2) * ($x - 10));
}
$p = new PHPlot(400, 800);
$p->SetPrintImage(FALSE);
$p->SetPlotBorderType('full');
$p->SetTitle("Set/Reset Parameters Test (2)\n" . "Top: Parameters Set\n" . "Bottom: Parameters Reset");
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotType('lines');
$p->SetLegend('Y = F(X)');
$p->SetLegendPixels(100, 200);
$p->SetNumXTicks(5);
$p->SetNumYTicks(8);
$p->SetXTitle('X Axis with 5 ticks');
$p->SetYTitle('Y Axis with 8 ticks');
$p->SetXAxisPosition(-228);
$p->SetYAxisPosition(7);
$p->SetPlotAreaPixels(70, 80, 380, 400);
$p->DrawGraph();
$p->SetLegendPixels();
$p->SetNumXTicks();
$p->SetNumYTicks();
$p->SetXTitle('X Axis');
$p->SetYTitle('Y Axis');
$p->SetXAxisPosition();
$p->SetYAxisPosition();
$p->SetPlotAreaPixels(70, 450, 380, 750);
$p->DrawGraph();
$p->PrintImage();
Exemplo n.º 5
0
# Based on a posting 2010-07-16 to PHPlot forum
require_once 'phplot.php';
// First data array for Left axis graph:
$data1 = array(array('', 0, 20), array('', 1, 15), array('', 2, 8), array('', 3, 6), array('', 4, 3), array('', 5, 7), array('', 6, 14), array('', 7, 28), array('', 8, 32), array('', 9, 35));
// Second data array for Right axis graph:
$data2 = array(array('', 0, 17), array('', 1, 22), array('', 2, 30), array('', 3, 36), array('', 4, 49), array('', 5, 57), array('', 6, 67), array('', 7, 73), array('', 8, 78), array('', 9, 81));
$p = new PHPlot(800, 600);
$p->SetPrintImage(0);
// Do not output image until told
// First plot:
$p->SetDataValues($data1);
$p->SetDataType('data-data');
$p->SetPlotType('lines');
$p->SetPlotAreaWorld(NULL, 0, NULL, NULL);
// Force Y to start at 0
$p->SetPlotAreaPixels(60, 40, 740, 560);
// Force same window for both plots
$p->SetYTickPos('plotleft');
// The default
$p->SetYTickLabelPos('plotleft');
// The default
$p->SetXTickIncrement(1);
$p->SetDataColors('blue');
// Force data color
$p->SetTitle('Overlay Line Plots to get Different Y Scales');
$p->SetTitleColor('black');
$p->SetXTitle('X Axis Title');
$p->SetYTitle('Temperature', 'plotleft');
$p->SetYTitleColor('blue');
$p->DrawGraph();
// Second plot:
Exemplo n.º 6
0
<?php

# $Id$
# Testing phplot - Fix for SetPlotAreaPixels with pie charts.
require_once 'phplot.php';
$data = array();
$legend = array();
for ($i = 0; $i < 15; $i++) {
    $data[] = array('', 10 + $i);
    $legend[] = "A very long label for set {$i}";
}
$p = new PHPlot(800, 500);
$p->SetPlotAreaPixels(240, 20, 795, 495);
$p->SetLegendPixels(5, 40);
$p->SetLegend($legend);
$p->SetTitle("Pie chart, SetPlotAreaPixels, Long Labels");
$p->SetDataType('text-data-single');
$p->SetDataValues($data);
$p->SetPlotType('pie');
# Color background so we can see what's what:
$p->SetDrawPlotAreaBackground(True);
$p->SetPlotBgColor('gray');
$p->DrawGraph();
Exemplo n.º 7
0
     $graph->SetShading(0);
     $graph->SetPlotAreaWorld(NULL, 0);
 }
 if (count($stat['legend']) > 0) {
     foreach ($stat['legend'] as $key => $val) {
         if (strlen($val) > 23) {
             $stat['legend'][$key] = substr($val, 0, 20) . '...';
         }
     }
     $graph->SetLegend($stat['legend']);
 }
 if ($stat['legend_x'] && $stat['legend_y']) {
     $graph->SetLegendPixels($stat['legend_x'], $stat['legend_y']);
 }
 if ($stat['graphtype'] == 'pie') {
     $graph->SetPlotAreaPixels(150, 0, $stat['xsize'], $stat['ysize']);
     $graph->SetLegendPixels(1, 30);
     $graph->SetShading(0);
     if ($stype == 'experience_avg_experimentclass') {
         $graph->SetPieLabelType('value');
     }
 }
 $graph->SetTitle($stat['title']);
 if ($stat['xtitle']) {
     $graph->SetXTitle($stat['xtitle'], 'plotdown');
 }
 // plotup, plotdown, both, none
 if ($stat['ytitle']) {
     $graph->SetYTitle($stat['ytitle'], 'plotleft');
 }
 // plotleft, plotright, both, plotin, none
include "/usr/lib/phplot/phplot.php";
include "/usr/lib/phplot/rgb.inc.php";
include "/tmp/plot.data.php";
// Test data
//$cvs_data = array(
//	array( "", "2000/03/15", 750),
//	array("", "2010/04/18", 1700),
//	array("", "2015/05/19", 2000),
//	array("", "2030/06/20", 400)
//	);
$graph = new PHPlot(238, 220);
$graph->SetIsInline("1");
$graph->SetDataType("text-data");
$graph->SetPlotType("bars");
$graph->SetDataValues($cvs_data);
// Specify plotting area details
$graph->SetImageArea(238, 220);
$graph->SetPlotAreaPixels(55, 20, 208, 190);
$graph->SetPrecisionY("0");
$graph->SetVertTickIncrement("100");
$graph->SetTickLength("5");
$graph->SetTitleFontSize("2");
$graph->SetPlotBgColor(204, 204, 204);
$graph->SetPlotBorderType("left");
$graph->SetBackgroundColor($ColorArray["gray80"]);
// Define the X axis
$graph->SetXLabel("Date");
// Define the Y axis
$graph->SetDataColors(array("blue", "red"), array("black"));
$graph->SetFileFormat("png");
$graph->DrawGraph();
Exemplo n.º 9
0
# no-callback behavior, but presence of a callback changes
# how colors are allocated.
function sdc($img, $unused, $row, $col)
{
    return $col;
}
$title = "Multiplot vs data colors, type {$plot_type}";
$p = new PHPlot(800, 800);
if ($do_callback) {
    $p->SetCallback('data_color', 'sdc');
    $title .= ", with data_color callback";
}
$p->SetPrintImage(False);
$p->SetTitle($title);
$p->SetPlotType($plot_type);
$p->SetLineStyles('solid');
$p->SetDataType('text-data');
$p->SetPlotAreaWorld(0, 0, 4, 10);
$p->SetPlotAreaPixels(60, 60, 339, 339);
$p->SetDataValues($data3);
$p->DrawGraph();
$p->SetPlotAreaPixels(460, 60, 739, 339);
$p->SetDataValues($data2);
$p->DrawGraph();
$p->SetPlotAreaPixels(60, 460, 339, 739);
$p->SetDataValues($data3);
$p->DrawGraph();
$p->SetPlotAreaPixels(460, 460, 739, 739);
$p->SetDataValues($data2);
$p->DrawGraph();
$p->PrintImage();
Exemplo n.º 10
0
$plot->SetXTickPos('none');
$plot->SetXDataLabelPos('none');
$plot->SetPrintImage(False);
$plot->SetImageBorderType('solid');
# Sub-plot area limits for Y (in pixels):
$py1 = 55;
$py2 = 355;
# Pixel limits for X:
$pdx = 195;
// Approx plot_width / 4 sub-plots
$px_l = 40;
// Left offset
$px_r = 5;
// Right inset
# Sub-plot (1) shows the initial plot range = date range.
$plot->SetPlotAreaPixels($px_l, $py1, $pdx - $px_r, $py2);
$plot->SetXTitle('(1) Initial Range');
# Disable zero magnet and range adjustment:
$plot->TuneYAutoRange(0, 'R', 0);
$plot->DrawGraph();
# Sub-plot (2) shows the plot range after zero magnet.
$plot->SetPlotAreaPixels($pdx + $px_l, $py1, 2 * $pdx - $px_r, $py2);
$plot->SetXTitle('(2) Zero Magnet');
#  Reset to auto-range, auto-axis:
$plot->SetPlotAreaWorld(NULL, NULL, NULL, NULL);
$plot->SetXAxisPosition(NULL);
#  Set zero magnet on, leave range adjust off:
$plot->TuneYAutoRange(1, 'R', 0);
$plot->DrawGraph();
# Sub-plot (3) shows the plot range after end adjust / increase range.
$plot->SetPlotAreaPixels(2 * $pdx + $px_l, $py1, 3 * $pdx - $px_r, $py2);
Exemplo n.º 11
0
        break;
}
// Common setup:
$plot = new PHPlot(460, 600);
$plot->SetPrintImage(False);
$plot->SetTitle("Multiple Plots, X,Y label format\n{$subtitle}");
$plot->SetPlotType('linepoints');
$plot->SetDataValues($data);
$plot->SetDataType('data-data');
$plot->SetYDataLabelPos('plotin');
// Enable both X tick and X data labels, but with data labels above.
$plot->SetXDataLabelPos('plotup');
$plot->SetXTickLabelPos('plotdown');
$plot->SetPlotBorderType('full');
// Plot #1:
$plot->SetPlotAreaPixels(NULL, 80, NULL, 305);
if (isset($fmt[1]['x'])) {
    $plot->SetXLabelType('printf', $fmt[1]['x']);
}
if (isset($fmt[1]['y'])) {
    $plot->SetYLabelType('printf', $fmt[1]['y']);
}
if (isset($fmt[1]['xd'])) {
    $plot->SetXDataLabelType('printf', $fmt[1]['xd']);
}
if (isset($fmt[1]['yd'])) {
    $plot->SetYDataLabelType('printf', $fmt[1]['yd']);
}
$plot->DrawGraph();
// Plot #2:
$plot->SetPlotAreaPixels(NULL, 345, NULL, 570);
Exemplo n.º 12
0
$p->SetPlotBorderType('full');
$p->SetLegend(array('Path A', 'Path B', 'Path C', 'Path D'));
switch ($legend_positioning) {
    case 'world':
        $p->SetLegendWorld(0.1, 35);
        break;
    case 'pixels':
        $p->SetLegendPixels(50, 50);
        break;
    case 'plotrelative':
        # This places the upper left corner of the legend box at an offset of
        # (5,5) from the upper left corner of the plot area.
        $p->SetLegendPosition(0, 0, 'plot', 0, 0, 5, 5);
        break;
        # No default: Default is to not position the legend and let it default.
}
# Draw n_across * n_down plots:
$plot_area_y1 = $plot_area_margin;
for ($iy = 0; $iy < $n_down; $iy++) {
    $plot_area_x1 = $plot_area_margin;
    $plot_area_y2 = $plot_area_y1 + $plot_area_height;
    for ($ix = 0; $ix < $n_across; $ix++) {
        $plot_area_x2 = $plot_area_x1 + $plot_area_width;
        $p->SetPlotAreaPixels($plot_area_x1, $plot_area_y1, $plot_area_x2, $plot_area_y2);
        $p->DrawGraph();
        $plot_area_x1 = $plot_area_x2 + $plot_area_margin;
    }
    $plot_area_y1 = $plot_area_y2 + $plot_area_margin;
}
# Now output the completed image
$p->PrintImage();
Exemplo n.º 13
0
# PHPlot test: Two plots on image with auto-scaling
require_once 'phplot.php';
$data1 = array(array('', 0, 10, 50), array('', 1, 20, 40), array('', 2, 30, 20), array('', 3, 40, 0));
$data2 = array(array('', 0, 10, 80), array('', 1, 20, 40), array('', 2, 90, 20), array('', 3, 40, 10), array('', 7, 50, 5), array('', 9, 0, 0));
$p = new PHPlot(800, 600);
$p->SetPrintImage(0);
// Do not output image until told
// First plot:
$p->SetDataValues($data1);
$p->SetDataType('data-data');
$p->SetPlotType('lines');
$p->SetTitle('Two plots with auto scaling');
$p->SetXTitle('X Axis Title 1');
$p->SetYTitle('Y Axis Title 1');
$p->SetXTickIncrement(0.5);
$p->SetPlotAreaPixels(50, 50, 350, 550);
$p->DrawGraph();
// Second plot:
$p->SetDataValues($data2);
$p->SetDataType('data-data');
$p->SetPlotType('lines');
$p->SetXTitle('X Axis Title 2');
$p->SetYTitle('Y Axis Title 2');
$p->SetXTickIncrement(NULL);
// Reset to auto tick calculation
$p->SetPlotAreaWorld();
// Resets scale to auto
$p->SetPlotAreaPixels(450, 50, 750, 550);
$p->DrawGraph();
// Now output the completed image
$p->PrintImage();
Exemplo n.º 14
0
$plot->SetFontTTF('title', $font, 14);
$plot->SetFontTTF('x_title', $font, 14);
$plot->SetFontTTF('y_title', $font, 10);
# Disable auto-output:
$plot->SetPrintImage(0);
$title = "Test {$n_plots} Plots with TTF Title (sequence {$title_sequence})";
$y1 = $title_space;
// Top of plot area
for ($i = 0; $i < $n_plots; $i++) {
    if ($i == $title_sequence) {
        $plot->SetTitle($title);
    }
    $y2 = $y1 + $height_of_each_plot;
    // Bottom of plot area
    # fwrite(STDERR, "Plot $i area: min=(80, $y1) : max=(740, $y2)\n");
    $plot->SetPlotAreaPixels(80, $y1, 740, $y2);
    $plot->SetDataType('text-data');
    $plot->SetDataValues($report[$i]);
    $plot->SetPlotAreaWorld(NULL, 0, NULL, $max_x);
    $plot->SetDataColors(array('blue'));
    $plot->SetXTickLabelPos('none');
    $plot->SetXDataLabelPos('plotdown');
    $plot->SetXTickPos('plotdown');
    $plot->SetYTickIncrement(1);
    $plot->SetXTitle("Chart {$i} X Values");
    $plot->SetYTitle("Chart {$i} Y Values");
    $plot->SetPlotType('bars');
    $plot->DrawGraph();
    $y1 = $y2 + $space_below_plots;
    // Start next plot below last plot
}
<?php

# $Id: data_table.example2.php 999 2011-08-05 19:00:48Z lbayuk $
# phplot / contrib / data_table example 2: Line plot with data table on the side
require_once 'phplot.php';
require_once 'data_table.php';
$data = array();
for ($i = 0; $i < 20; $i++) {
    $data[] = array('', $i, 2 * $i, $i * $i);
}
// The $settings array configures the data table:
$settings = array('headers' => array(NULL, 'X', '2Y', 'Y^2'), 'position' => array(640, 20), 'width' => 150, 'data' => $data, 'font' => 3);
$plot = new PHPlot(800, 600);
$plot->SetTitle('Line Plot with Data Table on Right Side');
$plot->SetDataValues($data);
$plot->SetDataType('data-data');
$plot->SetPlotType('linepoints');
$plot->SetPlotAreaPixels(NULL, NULL, 630, NULL);
$plot->SetCallback('draw_graph', 'draw_data_table', $settings);
$plot->SetLegend(array('2Y', 'Y^2'));
$plot->DrawGraph();
Exemplo n.º 16
0
# Data array for plot #1:
# Results in Y axis on left side at X=10, X axis at bottom Y=10
$data1 = array(array('', 10, 10), array('', 11, 11), array('', 12, 12));
# Data array for plot #2:
# X axis should in the middle at Y=0
# Y axis should be on left at X=-20
# But instead they stick from plot #1 at Y=10, X=10.
$data2 = array(array('', -20, -10), array('', -5, 2), array('', 30, 20));
// Common setup:
$plot = new PHPlot(460, 600);
$plot->SetTitle("Multiple Plots - axis position (case {$case})\n" . "X and Y axis positions stick from upper plot");
$plot->SetPlotType('points');
$plot->SetDataType('data-data');
$plot->SetPrintImage(False);
// Plot #1:
$plot->SetPlotAreaPixels(NULL, 60, NULL, 300);
$plot->SetPlotAreaWorld();
$plot->SetDataValues($data1);
$plot->DrawGraph();
// Plot #2:
$plot->SetPlotAreaPixels(NULL, 330, NULL, 570);
$plot->SetPlotAreaWorld();
$plot->SetDataValues($data2);
if ($case == 2) {
    $plot->SetXAxisPosition();
    // Reset to default
    $plot->SetYAxisPosition();
    // Reset to default
}
$plot->DrawGraph();
// Finish:
Exemplo n.º 17
0
# this script. The parameters are shown in the defaults array below:
if (!isset($tp)) {
    $tp = array();
}
$tp = array_merge(array('title' => 'Partial Margin Specification Test', 'suffix' => '', 'doSetMarginsPixels' => False, 'MarginsPixels' => array(NULL, NULL, NULL, NULL), 'doSetPlotAreaPixels' => False, 'PlotAreaPixels' => array(NULL, NULL, NULL, NULL)), $tp);
require_once 'phplot.php';
$data = array(array('Jan', 100, 200, 300), array('Feb', 120, 190, 240), array('Mar', 130, 180, 290), array('Apr', 140, 170, 260), array('May', 120, 160, 200), array('Jun', 130, 150, 220));
define('PLOT_WIDTH', 1024);
define('PLOT_HEIGHT', 768);
$p = new PHPlot(1024, 768);
$p->SetTitle($tp['title'] . $tp['suffix']);
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetXTickLabelPos('none');
$p->SetXTickIncrement(1.0);
$p->SetYTickIncrement(10.0);
$p->SetYTickPos('both');
$p->SetYTickLabelPos('both');
$p->SetDrawXGrid(False);
$p->SetDrawYGrid(True);
$p->SetXTitle("Two Line\nX Axis Title");
$p->SetYTitle("Three Line\nY Axis\nTitle");
$p->SetPlotAreaWorld(NULL, 0, NULL, NULL);
if ($tp['doSetMarginsPixels']) {
    $p->SetMarginsPixels($tp['MarginsPixels'][0], $tp['MarginsPixels'][1], $tp['MarginsPixels'][2], $tp['MarginsPixels'][3]);
}
if ($tp['doSetPlotAreaPixels']) {
    $p->SetPlotAreaPixels($tp['PlotAreaPixels'][0], $tp['PlotAreaPixels'][1], $tp['PlotAreaPixels'][2], $tp['PlotAreaPixels'][3]);
}
$p->DrawGraph();