Exemplo n.º 1
1
$base_time = mktime(0, 0, 12, 6, 30, 2004);
$interval = 60 * 60;
$data = array();
# This is a quadratic from 0,0 to 50,20 to 100,0:
for ($i = 0; $i <= 100; $i++) {
    if ($i % 24 == 0) {
        $t = $base_time + $i * $interval;
    } else {
        $t = '';
    }
    $data[] = array($t, $i, $i * (0.8 - 0.008 * $i));
}
$p = new PHPlot(800, 600);
$p->SetTitle('Date X labels - 8 hour ticks, 24 hour labels');
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotAreaWorld(0, 0, 100, 20);
$p->SetXLabelType('time');
# For example:
# %Y-%m-%d  2004-12-31
# %b %Y     Dec 2004
# %b %d, %Y Dec 31, 2004
# %d %b     31 Dec
$p->SetXTimeFormat('%m/%d %H:%M');
# Turn off X tick labels, use our data labels only:
$p->SetXTickLabelPos('none');
# But we can use the tick marks themselves if we make them line up right.
$p->SetXTickIncrement(8);
$p->SetDrawXGrid(True);
$p->SetPlotType('lines');
$p->DrawGraph();
Exemplo n.º 2
0
function plotBarData($dataArray, $title)
{
    $data = array(array('Jan', 40, 2, 4), array('Feb', 30, 3, 4), array('Mar', 20, 4, 4), array('Apr', 10, 5, 4), array('May', 3, 6, 4), array('Jun', 7, 7, 4), array('Jul', 10, 8, 4), array('Aug', 15, 9, 4), array('Sep', 20, 5, 4), array('Oct', 18, 4, 4), array('Nov', 16, 7, 4), array('Dec', 14, 3, 4));
    $data = $dataArray;
    $plot = new PHPlot(400, 300);
    $plot->SetIsInline(true);
    $plot->SetOutputFile($title . '.png');
    $plot->SetImageBorderType('plain');
    $plot->SetPlotType('bars');
    //$plot->SetPlotType('stackedbars');
    //$plot->SetPlotType('lines');
    $plot->SetDataType('text-data');
    //$plot->SetDataType('data-data');
    $plot->SetPlotAreaWorld(NULL, -10, NULL, 35);
    $plot->SetDataValues($data);
    $plot->SetDataColors(array('red', 'blue', 'green', 'yellow'));
    # Main plot title:
    $plot->SetTitle($title);
    # No 3-D shading of the bars:
    $plot->SetShading(0);
    # Make a legend for the 3 data sets plotted:
    $plot->SetLegend(array('min', 'avg', 'max'));
    //$plot->SetLegendPosition(0, 0, 'image', 0, 0, 35, 5);
    # Turn off X tick labels and ticks because they don't apply here:
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');
    $plot->DrawGraph();
}
Exemplo n.º 3
0
<?php

# PHPlot Example - Horizontal linepoints plot with Y Data Label Lines
require_once 'phplot.php';
$data = array(array("SEA\nLEVEL", 0, ''), array('100m', 1, 10), array('200m', 2, 22), array('300m', 3, 30), array('400m', 4, 46), array('500m', 5, 53), array('600m', 6, 65), array('700m', 7, 70), array('800m', 8, 50), array('900m', 9, 35));
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
// Improves presentation in the manual
$plot->SetTitle('Wind Speed at Altitude');
$plot->SetDataType('data-data-yx');
$plot->SetDataValues($data);
$plot->SetPlotType('linepoints');
$plot->SetPlotAreaWorld(0, 0, 100, 10);
$plot->SetDrawYDataLabelLines(True);
$plot->SetXTitle('Wind Speed');
$plot->SetYTitle('Altitude');
$plot->SetYTickLabelPos('none');
$plot->SetYTickPos('none');
$plot->SetXDataLabelPos('plotin');
$plot->SetDrawXGrid(False);
$plot->SetDrawYGrid(False);
$plot->DrawGraph();
Exemplo n.º 4
0
#   Y2 = cos(x)
$end = M_PI * 2.0;
$delta = $end / 20.0;
$data = array();
for ($x = 0; $x <= $end; $x += $delta) {
    $data[] = array('', $x, sin($x), cos($x));
}
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('lines');
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
# Main plot title:
$plot->SetTitle('Line Plot, Sin and Cos');
# Make a legend for the 2 functions:
$plot->SetLegend(array('sin(t)', 'cos(t)'));
# Select a plot area and force ticks to nice values:
$plot->SetPlotAreaWorld(0, -1, 6.8, 1);
# Even though the data labels are empty, with numeric formatting they
# will be output as zeros unless we turn them off:
$plot->SetXDataLabelPos('none');
$plot->SetXTickIncrement(M_PI / 8.0);
$plot->SetXLabelType('data');
$plot->SetPrecisionX(3);
$plot->SetYTickIncrement(0.2);
$plot->SetYLabelType('data');
$plot->SetPrecisionY(1);
# Draw both grids:
$plot->SetDrawXGrid(True);
$plot->SetDrawYGrid(True);
$plot->DrawGraph();
Exemplo n.º 5
0
}
# Function to plot:
function f($x)
{
    if ($x == 0) {
        return 0;
    }
    return 5 + 8 * sin(200 * M_PI / $x);
}
$data = array();
for ($x = 0; $x < 500; $x++) {
    $data[] = array('', $x, f($x));
}
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
// For presentation in the manual
$plot->SetTitle("Example {$case}");
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetPlotType('lines');
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
# Set the plot range.  This was not needed before PHPlot-6.0.0, when the
# default behavior demonstrated the need for setting a Y tick anchor at 0.
# But starting with PHPlot-6.0.0, the default behavior improved, so this
# example no longer shows the need for the tick anchor without forcing it.
$plot->SetPlotAreaWorld(NULL, -3.5, NULL, 13.5);
if (isset($set_anchor)) {
    $plot->SetYTickAnchor($set_anchor);
}
$plot->DrawGraph();
Exemplo n.º 6
0
# resetting attributes.
# Reference: Bug report 2839457
require_once 'phplot.php';
$data = array(array('', -1000, 1000), array('', -500, 23456), array('', 0, 800), array('', 500, 234100), array('', 1000, 1234567), array('', 1500, 100000), array('', 2000, 1901000), array('', 2500, 999999));
$title = "Test Attribute Resets:\n";
if (empty($test_resets)) {
    $title .= 'Baseline - red border, formatted labels';
} else {
    $title .= 'Reset to no border, no label formatting';
}
$plot = new PHPlot(400, 400);
$plot->SetTitle($title);
$plot->SetPlotType('lines');
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetPlotAreaWorld(-1000, 0);
$plot->SetXDataLabelPos('none');
$plot->SetXTickIncrement(500);
$plot->SetXLabelType('data', 0, '', 'M');
$plot->SetYTickIncrement(200000);
$plot->SetYLabelType('data', 2);
$plot->SetImageBorderType('raised');
$plot->SetImageBorderColor('red');
$plot->SetDrawXGrid(False);
$plot->SetDrawYGrid(False);
# Set $test_resets=True and include this file to test resets:
if (!empty($test_resets)) {
    # Reset to no border:
    $plot->SetImageBorderType('none');
    # Reset X to no formatting using empty string:
    $plot->SetXLabelType('');
Exemplo n.º 7
0
}
$tp = array_merge(array('title' => "Miscellaneous Options\nColor Map, Line Spacing, Dashed Grid", 'suffix' => " (baseline)", 'colormap' => NULL, 'datacolors' => NULL, 'linespacing' => NULL, 'dashedgrid' => True), $tp);
require_once 'phplot.php';
#                          Land area in 10^6 sq km
#
$data = array(array('Monday', 10, 23, 7, 15), array('Tuesday', 25, 7, 12, 9), array('Wednesday', 8, 15, 18, 15), array('Thursday', 16, 9, 26, 16), array('Friday', 20, 25, 21, 14));
$plot = new PHPlot(800, 600);
$plot->SetPlotType('bars');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
# Options:
if (isset($tp['linespacing'])) {
    $plot->SetLineSpacing($tp['linespacing']);
}
if (isset($tp['colormap'])) {
    $plot->SetRGBArray($tp['colormap']);
}
if (isset($tp['datacolors'])) {
    $plot->SetDataColors($tp['datacolors']);
    $plot->SetErrorBarColors($tp['datacolors']);
}
$plot->SetDrawDashedGrid($tp['dashedgrid']);
$plot->SetTitle($tp['title'] . "\n" . $tp['suffix']);
$plot->SetLegend(array('Data Set 1', 'Data Set 2', 'Data Set 3', 'Data Set 4'));
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->SetDrawXGrid(True);
$plot->SetDrawYGrid(True);
$plot->SetPlotAreaWorld(NULL, 0, NULL, 30);
$plot->SetNumYTicks(30);
$plot->DrawGraph();
Exemplo n.º 8
0
# this script. The parameters are shown in the defaults array below:
if (!isset($tp)) {
    $tp = array();
}
$tp = array_merge(array('title' => 'Long X labels', 'suffix' => "", 'MaxLen' => 35, 'angle' => 90, 'TTF' => False, 'FontSize' => NULL, 'FontName' => 'sans'), $tp);
require_once 'phplot.php';
$data = array();
for ($len = 5; $len <= $tp['MaxLen']; $len += 5) {
    $data[] = array(str_repeat('Label', $len / 5), $len);
}
$p = new PHPlot(800, 600);
$p->SetTitle($tp['title'] . $tp['suffix']);
$p->SetDataType('text-data');
$p->SetDataValues($data);
# Fix Y ticks
$p->SetPlotAreaWorld(NULL, 0, NULL, NULL);
$p->SetYTickIncrement(5);
# Font:
if ($tp['TTF']) {
    # Using TrueType fonts: Set path and default font.
    $p->SetTTFPath($phplot_test_ttfdir);
    $font = $phplot_test_ttfonts[$tp['FontName']];
    $p->SetDefaultTTFont($font);
    # Now select label font with size (if supplied):
    if (empty($tp['FontSize'])) {
        $p->SetFont('x_label', $font);
    } else {
        $p->SetFont('x_label', $font, $tp['FontSize']);
    }
} else {
    # Using GD fonts:
Exemplo n.º 9
0
$tp = array_merge(array('title' => 'Lines', 'suffix' => ' (1 line, default styles)', 'nlines' => 1, 'LWidths' => NULL, 'LStyles' => NULL, 'DStyle' => NULL), $tp);
require_once 'phplot.php';
$np = $tp['nlines'];
$data = array();
for ($i = 1; $i <= 20; $i++) {
    $row = array('', $i);
    for ($j = 1; $j <= $np; $j++) {
        $row[] = $i + $j;
    }
    $data[] = $row;
}
$p = new PHPlot(800, 600);
$p->SetTitle($tp['title'] . $tp['suffix']);
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotAreaWorld(0, 0, 21, 40);
$p->SetXTickIncrement(1);
$p->SetYTickIncrement(5);
# Options:
if (isset($tp['LWidths'])) {
    $p->SetLineWidths($tp['LWidths']);
}
if (isset($tp['DStyle'])) {
    $p->SetDefaultDashedStyle($tp['DStyle']);
}
if (isset($tp['LStyles'])) {
    $p->SetLineStyles($tp['LStyles']);
}
$p->SetDrawXGrid(False);
$p->SetDrawYGrid(False);
$p->SetPlotType('lines');
Exemplo n.º 10
0
    $y0 = 4 * min($v) - 2;
    $y1 = 4 * max($v) + 2;
}
# Auto title:
$title = (empty($horizontal) ? "Vertical" : "Horizontal") . " Stacked Bars" . " with Zero-Length Segments\n";
if (!isset($shading)) {
    $title .= "Default shading";
} elseif ($shading == 0) {
    $title .= "Unshaded";
} else {
    $title .= "Shading: {$shading}";
}
$title .= isset($axis) ? ", Axis moved to {$axis}" : ", default axis position";
$plot = new PHPlot($width, $height);
$plot->SetTitle($title);
$plot->SetPlotType('stackedbars');
$plot->SetDataValues($data);
$plot->SetDataType($datatype);
call_user_func(array($plot, "Set{$dep}DataLabelPos"), 'plotstack');
call_user_func(array($plot, "Set{$ind}TickLabelPos"), 'none');
call_user_func(array($plot, "Set{$ind}TickPos"), 'none');
call_user_func(array($plot, "Set{$ind}DataLabelPos"), $labelposition);
call_user_func(array($plot, "Set{$ind}LabelAngle"), $labelangle);
$plot->SetPlotAreaWorld($x0, $y0, $x1, $y1);
if (isset($shading)) {
    $plot->SetShading($shading);
}
if (isset($axis)) {
    call_user_func(array($plot, "Set{$ind}AxisPosition"), $axis);
}
$plot->DrawGraph();
Exemplo n.º 11
0
$graph->SetYDataLabelPos($which_ydata_label_pos);
// Please remember that angles other than 90 are taken as 0 when working fith fixed fonts.
$graph->SetXLabelAngle($which_xlabel_angle);
$graph->SetYLabelAngle($which_ylabel_angle);
//$graph->SetLineStyles(array("dashed","dashed","solid","solid"));
$graph->SetPointShape($which_point);
$graph->SetPointSize($which_point_size);
$graph->SetDrawBrokenLines($which_broken);
// Some forms in format_chart.php don't set this variable, suppress errors.
@$graph->SetErrorBarShape($which_error_type);
$graph->SetXAxisPosition($which_xap);
$graph->SetYAxisPosition($which_yap);
$graph->SetPlotBorderType($which_btype);
if ($maxy_in) {
    if ($which_data_type = "text-data") {
        $graph->SetPlotAreaWorld(0, $miny_in, count($data), $maxy_in);
    }
}
/*
//Even more settings

	$graph->SetPlotAreaWorld(0,100,5.5,1000);
	$graph->SetPlotAreaWorld(0,-10,6,35);
	$graph->SetPlotAreaPixels(150,50,600,400);

    $graph->SetDataColors(
	        array("blue","green","yellow","red"),  //Data Colors
            array("black")							//Border Colors
    );  

    $graph->SetPlotBgColor(array(222,222,222));
Exemplo n.º 12
0
# 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:
$plot->PrintImage();
Exemplo n.º 13
0
    $tp = array();
}
$tp = array_merge(array('c' => 10, 't' => 1, 'ar' => FALSE), $tp);
require_once 'phplot.php';
# Extract all test parameters as local variables:
extract($tp);
$title = "Log/Log Axis Test\nPlotting: XY = {$c}\n" . "Tick step: " . (empty($t) ? "Auto" : $t) . ", " . "Range: " . ($ar ? "Auto" : "Manually set");
# Plot X*Y=C
$data = array();
for ($x = 1; $x <= $c; $x++) {
    $data[] = array('', $x, $c / $x);
}
$p = new PHPlot(800, 600);
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetTitle($title);
$p->SetXScaleType('log');
$p->SetYScaleType('log');
if (empty($t)) {
    $p->SetXTickIncrement($t);
    $p->SetYTickIncrement($t);
}
if (!$ar) {
    $p->SetPlotAreaWorld(0, 1, $c + 1, $c + 1);
}
$p->SetXTickAnchor(0);
$p->SetYTickAnchor(0);
$p->SetDrawXGrid(True);
$p->SetDrawYGrid(True);
$p->SetPlotType('lines');
$p->DrawGraph();
Exemplo n.º 14
0
$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
}
$plot->PrintImage();
Exemplo n.º 15
0
<?php

# PHPlot Example: Point chart with error bars
require_once 'phplot.php';
$data = array(array('', 1, 23.5, 5, 5), array('', 2, 20.1, 3, 3), array('', 3, 19.1, 2, 2), array('', 4, 16.8, 3, 3), array('', 5, 18.4, 4, 6), array('', 6, 20.5, 3, 2), array('', 7, 23.2, 4, 4), array('', 8, 23.1, 5, 2), array('', 9, 24.5, 2, 2), array('', 10, 28.1, 2, 2));
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('points');
$plot->SetDataType('data-data-error');
$plot->SetDataValues($data);
# Main plot title:
$plot->SetTitle('Points Plot With Error Bars');
# Set data range and tick increments to get nice even numbers:
$plot->SetPlotAreaWorld(0, 0, 11, 40);
$plot->SetXTickIncrement(1);
$plot->SetYTickIncrement(5);
# Draw both grids:
$plot->SetDrawXGrid(True);
$plot->SetDrawYGrid(True);
# Is default
# Set some options for error bars:
$plot->SetErrorBarShape('tee');
# Is default
$plot->SetErrorBarSize(10);
$plot->SetErrorBarLineWidth(2);
# Use a darker color for the plot:
$plot->SetDataColors('brown');
$plot->SetErrorBarColors('brown');
# Make the points bigger so we can see them:
$plot->SetPointSizes(10);
$plot->DrawGraph();
<?php

require 'phplot/phplot.php';
require 'mem_image.php';
$graph = new PHPlot(500, 300);
$graph->SetDataType('data-data');
//Specify some data
$data = array(array('', 2000, 750), array('', 2010, 1700), array('', 2015, 2000), array('', 2020, 1800), array('', 2025, 1300), array('', 2030, 400));
$graph->SetDataValues($data);
//Specify plotting area details
$graph->SetPlotType('lines');
$graph->SetTitleFontSize('2');
$graph->SetTitle('Social Security trust fund asset estimates, in $ billions');
$graph->SetMarginsPixels(null, null, 40, null);
$graph->SetPlotAreaWorld(2000, 0, 2035, 2000);
$graph->SetPlotBgColor('white');
$graph->SetPlotBorderType('left');
$graph->SetBackgroundColor('white');
$graph->SetDataColors(array('red'), array('black'));
//Define the X axis
$graph->SetXLabel('Year');
$graph->SetXTickIncrement(5);
//Define the Y axis
$graph->SetYTickIncrement(500);
$graph->SetPrecisionY(0);
$graph->SetLightGridColor('blue');
//Disable image output
$graph->SetPrintImage(false);
//Draw the graph
$graph->DrawGraph();
$pdf = new PDF_MemImage();
Exemplo n.º 17
0
//Must be called before SetDataValues
$graph->SetNewPlotAreaPixels(90, 40, 540, 190);
$graph->SetDataValues($example_data);
$graph->SetXGridLabelType("time");
$graph->SetXDataLabelAngle(90);
$graph->SetXLabel("");
$graph->SetYLabel("Price");
$graph->SetVertTickIncrement(20);
$graph->SetHorizTickIncrement(2679000);
$graph->SetXTimeFormat("%b %y");
$graph->SetPlotType("lines");
$graph->SetErrorBarShape("line");
$graph->SetPointShape("halfline");
$graph->SetYScaleType("log");
$graph->SetLineWidth(1);
$graph->SetPlotAreaWorld(883634400, 1, 915095000, 140);
$graph->DrawGraph();
//Now do the second chart on the image
unset($example_data);
$graph->SetPrintImage(1);
//Now draw the image
$graph->SetYScaleType("linear");
include "./data_date.php";
$graph->SetDataType("data-data");
//Must be called before SetDataValues
$graph->SetDataValues($example_data);
$graph->SetNewPlotAreaPixels(90, 260, 540, 350);
$graph->SetDataValues($example_data);
$graph->SetXGridLabelType("time");
$graph->SetXDataLabelAngle(90);
$graph->SetXLabel("");
Exemplo n.º 18
0
$tp = array_merge(array('title' => 'Transparent Background', 'suffix' => " (default)", 'FFormat' => NULL), $tp);
require_once 'phplot.php';
$data = array(array('', -4, -64, 16, 40), array('', -3, -27, 9, 30), array('', -2, -8, 4, 20), array('', -1, -1, 1, 10), array('', 0, 0, 0, 0), array('', 1, 1, 1, -10), array('', 2, 8, 4, -20), array('', 3, 27, 9, -30), array('', 4, 64, 16, -40));
$p = new PHPlot();
# File format GIF or PNG, to test transparency:
if (isset($tp['FFormat'])) {
    $p->SetFileFormat($tp['FFormat']);
}
# Background color will be transparent:
$p->SetBackgroundColor('yellow');
$p->SetTransparentColor('yellow');
$p->SetTitle($tp['title'] . $tp['suffix']);
$p->SetDataType('data-data');
$p->SetDataValues($data);
# We don't use the data labels (all set to '') so might as well turn them off:
$p->SetXDataLabelPos('none');
# Need to set area and ticks to get reasonable choices.
$p->SetPlotAreaWorld(-4, -70, 4, 80);
$p->SetXTickIncrement(1);
$p->SetYTickIncrement(10);
# Don't use dashes for 3rd line:
$p->SetLineStyles('solid');
# Make the lines thicker:
$p->SetLineWidths(3);
# Draw both grids:
$p->SetDrawXGrid(True);
$p->SetDrawYGrid(True);
# And a legend:
$p->SetLegend(array('x^3', 'x^2', '-10x'));
$p->SetPlotType('lines');
$p->DrawGraph();
Exemplo n.º 19
0
    $data[] = array($array_exibir['usuario'], $array_exibir['hora']);
    $i++;
}
# Create a PHPlot object which will make an 800x400 pixel image:
$p = new PHPlot(800, 400);
# Use TrueType fonts:
//$p->SetDefaultTTFont('./arial.ttf');
# Set the main plot title:
$p->SetTitle('PHPlot Customer Satisfaction (estimated)');
# Select the data array representation and store the data:
$p->SetDataType('text-data');
$p->SetDataValues($data);
# Select the plot type - bar chart:
$p->SetPlotType('bars');
# Define the data range. PHPlot can do this automatically, but not as well.
$p->SetPlotAreaWorld(0, 0, 9, 100);
# Select an overall image background color and another color under the plot:
$p->SetBackgroundColor('#ffffcc');
$p->SetDrawPlotAreaBackground(True);
$p->SetPlotBgColor('#ffffff');
# Draw lines on all 4 sides of the plot:
$p->SetPlotBorderType('full');
# Set a 3 line legend, and position it in the upper left corner:
$p->SetLegend(array('Features', 'Bugs', 'Happy Users'));
$p->SetLegendWorld(0.1, 95);
# Turn data labels on, and all ticks and tick labels off:
$p->SetXDataLabelPos('plotdown');
$p->SetXTickPos('none');
$p->SetXTickLabelPos('none');
$p->SetYTickPos('none');
$p->SetYTickLabelPos('none');
Exemplo n.º 20
0
<?php

//Include the code
include "../phplot.php";
//Define the object and get background image 0cars.jpg
//////NOTE! THIS EXAMPLE WILL ONLY WORK IF YOU HAVE
//////JPEG SUPPORT ENABLED. (Use a different file as a background
//////if you have png or gif enabled.
$graph = new PHPlot(500, 223, "", "0cars.jpg");
//Set some data
$example_data = array(array("55", 5), array("60", 10), array("65", 20), array("70", 30), array("75", 25), array("80", 10));
$graph->SetDataValues($example_data);
//Set up some nice formatting things
$graph->SetTitle("Speed Histogram");
$graph->SetXLabel("Miles per Hour");
$graph->SetYLabel("Percent of Cars");
$graph->SetVertTickIncrement(5);
$graph->SetPlotAreaWorld(0, 0, 6, 35);
//Make the margins nice for the background image
$graph->SetMarginsPixels(80, 35, 35, 70);
//Set up some color and printing options
$graph->background_done = 1;
//The image background we get from 0cars.jpg
$graph->SetDrawPlotAreaBackground(0);
//Plot Area background we get from the image
$graph->SetDataColors(array("white"), array("black"));
//Set Output format
$graph->SetFileFormat("png");
//Draw it
$graph->DrawGraph();
Exemplo n.º 21
0
        }
        $data[] = $row;
    }
} else {
    // Regular plot that works with text-data data type:
    $data_type = 'text-data';
    for ($pt = 0; $pt < $n_x; $pt++) {
        $row = array(strftime('%b', mktime(12, 12, 12, $pt + 1, 1, 2000)));
        for ($r = 0; $r < $groups; $r++) {
            $row[] = mt_rand(0, $max_y);
        }
        $data[] = $row;
    }
}
$plot = new PHPlot();
$plot->SetTitle($title . $suffix);
$plot->SetDataType($data_type);
$plot->SetDataValues($data);
$plot->SetPlotType($plottype);
$plot->SetPlotAreaWorld(0, 0, $n_x, $max_y);
# Position data labels:
$plot->SetXDataLabelPos($labelpos);
# Turn data label lines on or off:
$plot->SetDrawXDataLabelLines($labellines);
# Turn off Tick labels and X Tick marks - they aren't used.
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
# Don't draw grids, so we can see the data lines.
$plot->SetDrawXGrid(False);
$plot->SetDrawYGrid(False);
$plot->DrawGraph();
Exemplo n.º 22
0
# PHPlot / contrib / color_range : Example
# $Id$
# This is a bar chart with a color gradient for the bars in each group.
require_once 'phplot.php';
require_once 'color_range.php';
$bars_per_group = 10;
$x_values = 4;
mt_srand(1);
$data = array();
for ($i = 0; $i < $x_values; $i++) {
    $row = array($i);
    for ($j = 0; $j < $bars_per_group; $j++) {
        $row[] = mt_rand(0, 100);
    }
    $data[] = $row;
}
$p = new PHPlot(800, 600);
$p->SetTitle('Example - Bar Chart with gradient colors');
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotAreaWorld(0, 0, $x_values, 100);
# This isn't necessary, as we do know how many data sets (bars_per_group):
$n_data = count_data_sets($data, 'text-data');
# Make a gradient color map:
$colors = color_range($p->SetRGBColor('SkyBlue'), $p->SetRGBColor('DarkGreen'), $n_data);
$p->SetDataColors($colors);
$p->SetXTickLabelPos('none');
$p->SetXTickPos('none');
$p->SetPlotType('bars');
$p->DrawGraph();
Exemplo n.º 23
0
<?php

# Typical bars with labels, for manual.
require_once 'phplot.php';
$data = array(array('First', 10), array('Second', 20), array('Third', 30));
$p = new PHPlot(400, 300);
$p->SetDataType('text-data-yx');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitle('Horizontal Bar Plot With Labels');
$p->SetXTitle('Dependent Variable');
$p->SetYTitle('Independent Variable');
$p->SetYDataLabelPos('plotleft');
$p->SetYTickPos('none');
$p->SetXDataLabelPos('plotin');
$p->SetPlotAreaWorld(0, NULL, 40, NULL);
$p->SetXTickIncrement(5);
$p->SetImageBorderType('plain');
$p->DrawGraph();
Exemplo n.º 24
0
}
# The variable $plot_type can be set in another script as well.
if (empty($plot_type)) {
    $plot_type = 'linepoints';
}
# Use data labels to display only the points we want,
# but specify the same values for X to get the correct
# spacing.
$data = array(array('1990', 1990, 41308, 21015, 62634), array('1995', 1995, 44310, 13883, 61529), array('2000', 2000, 46772, 9000, 59421), array('2004', 2004, 46887, 7738, 57754), array('2006', 2006, 45441, 6888, 53179), array('2008', 2008, 42757, 5840, 49115));
$legend_text = array('Morning Papers', 'Evening Papers', 'Sunday Papers');
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
// Improves presentation in the manual
$plot->SetTitle("US Daily Newspaper Circulation\n" . $plot_type . ' plot with SetLegendUseShapes(' . ($use_shapes ? 'True' : 'False') . ')');
$plot->SetPlotType($plot_type);
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetPlotAreaWorld(1988, 0, 2010, 80000);
$plot->SetYTickIncrement(10000);
$plot->SetLegend($legend_text);
$plot->SetXTickPos('none');
$plot->SetDrawXDataLabelLines(True);
$plot->SetLegendUseShapes($use_shapes);
// Use color boxes or shapes
$plot->SetPointSizes(12);
// Make points bigger for visibility
$plot->SetLineStyles('solid');
// Make all lines solid
$plot->SetLineWidths(2);
// Make all lines thicker
$plot->DrawGraph();
Exemplo n.º 25
0
$data1 = array(array('Dec  6', 20, 24, 19, 22), array('Dec  7', 22, 26, 20, 26), array('Dec  8', 26, 28, 22, 24), array('Dec  9', 24, 30, 22, 28), array('Dec 10', 28, 30, 15, 18));
$n_points = count($data1);
// Second data array contains two lines, calculated from above.
// 1st is opening prices, 2nd is middle of the daily range = (low+high)/2.
$data2 = array();
for ($i = 0; $i < $n_points; $i++) {
    $data2[] = array('', $data1[$i][1], ($data1[$i][2] + $data1[$i][3]) / 2);
}
$p = new PHPlot(800, 600);
$p->SetPrintImage(0);
// Do not output image until told
// First plot:
$p->SetDataValues($data1);
$p->SetDataType('text-data');
$p->SetPlotType('ohlc');
$p->SetPlotAreaWorld(NULL, 0);
// For Y to start at 0
$p->SetXTickPos('none');
$p->SetTitle('OHLC and Line Plot Overlay');
$p->SetXTitle('Date', 'plotdown');
$p->SetYTitle('Security Price', 'plotleft');
$p->SetDrawPlotAreaBackground(True);
$p->SetPlotBgColor('PeachPuff');
$p->SetMarginsPixels(50, 50, 50, 50);
$p->DrawGraph();
// Second plot:
$p->SetDrawPlotAreaBackground(False);
$p->SetDataValues($data2);
$p->SetDataType('text-data');
$p->SetPlotType('lines');
$p->SetDataColors(array('red', 'orange'));
Exemplo n.º 26
0
# To get a repeatable test with 'random' data:
mt_srand(1);
# Need a base date/time: Can't just use 0 due to UTC/local differences:
$base_time = mktime(0, 0, 0, 1, 1, 2000);
# Twenty minutes:
$interval = 20 * 60;
# Random data at intervals:
$data = array();
$t = $base_time;
for ($i = 1; $i <= 12; $i++) {
    $data[] = array('', $t, mt_rand(0, 100));
    $t += $interval;
}
$p = new PHPlot(600, 400);
$p->SetTitle('Meaningless Data with Time X Tick Labels');
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetXLabelType('time');
$p->SetXTimeFormat('%H:%M');
$p->SetXTitle('Elapsed Time (hours:minutes)');
# Turn off X data labels, use tick labels only:
$p->SetXDataLabelPos('none');
$p->SetXTickLabelPos('plotdown');
# Even though tick values are given, it makes up its own unless:
$p->SetXTickIncrement($interval);
$p->SetDrawXGrid(True);
# Set the Y min and max, since the data is 0:100
$p->SetPlotAreaWorld(NULL, 0, NULL, 100);
$p->SetYTitle('Meaningless Value');
$p->SetPlotType('lines');
$p->DrawGraph();
Exemplo n.º 27
0
# PHPlot Example - Horizontal Error Plot
require_once 'phplot.php';
# The experimental results as a series of temperature measurements:
$results = array(98, 102, 100, 103, 101, 105, 110, 108, 109);
# The accuracy of our measuring equipment is +/- 5%
$error_factor = 0.05;
# Convert the experimental results to a PHPlot data array for error plots.
function reduce_data($results, $error_factor)
{
    # Use the average of measurements to approximate the error amount:
    $err = $error_factor * array_sum($results) / count($results);
    # Build the 'data-data-yx-error' data array:
    $data = array();
    $i = 1;
    foreach ($results as $value) {
        $data[] = array("Sample {$i}", $i++, $value, $err, $err);
    }
    return $data;
}
$plot = new PHPlot(800, 600);
$plot->SetTitle('Experiment Results');
$plot->SetXTitle('Melting Temperature (degrees C)');
$plot->SetDataValues(reduce_data($results, $error_factor));
$plot->SetDataType('data-data-yx-error');
$plot->SetPlotType('points');
$plot->SetYTickPos('none');
$plot->SetImageBorderType('plain');
// Improves presentation in the manual
$plot->SetPlotAreaWorld(80);
$plot->DrawGraph();
Exemplo n.º 28
0
<?php

# $Id$
# Testing phplot - data-data ordering
require_once 'phplot.php';
# 10 lines, one for each shape:
$data = array(array('', 1, 20), array('', 2, 2), array('', 3, 19), array('', 4, 3), array('', 6, 4), array('', 7, 17), array('', 8, 5), array('', 9, 16), array('', 5, 18), array('', 10, 6));
$p = new PHPlot();
$p->SetTitle('Out-of-order data-data points');
$p->SetPlotType('lines');
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotAreaWorld(0, 0, 12, 25);
$p->SetXTickIncrement(1);
$p->SetYTickIncrement(1);
# We don't use the data labels (all set to '') so might as well turn them off:
$p->SetXDataLabelPos('none');
# Draw both grids:
$p->SetDrawXGrid(True);
$p->SetDrawYGrid(True);
# The default
$p->DrawGraph();
Exemplo n.º 29
0
# $Id$
# Testing phplot - Points
require_once 'phplot.php';
# This array is used for both the point shapes and legend:
$shapes = array('circle', 'cross', 'diamond', 'dot', 'halfline', 'line', 'plus', 'rect', 'triangle', 'trianglemid');
# 10 lines, one for each shape:
$data = array(array('', 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), array('', 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), array('', 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), array('', 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), array('', 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), array('', 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), array('', 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), array('', 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17), array('', 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), array('', 10, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19));
$p = new PHPlot();
$p->SetTitle('Points plots, 10 lines/10 shapes');
$p->SetDataType('data-data');
$p->SetDataValues($data);
# We don't use the data labels (all set to '') so might as well turn them off:
$p->SetXDataLabelPos('none');
# Need to set area and ticks to get reasonable choices.
#  Increase X range to make room for the legend.
$p->SetPlotAreaWorld(0, 0, 13, 20);
$p->SetXTickIncrement(1);
$p->SetYTickIncrement(2);
# Need 10 different colors; defaults are not different:
$p->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'brown', 'lavender', 'pink', 'orange'));
# Show all 10 shapes:
$p->SetPointShapes($shapes);
# Also show that as the legend:
$p->SetLegend($shapes);
# Make the points bigger so we can see them:
$p->SetPointSizes(10);
# Draw both grids:
$p->SetDrawXGrid(True);
$p->SetDrawYGrid(True);
# The default
$p->SetPlotType('points');
Exemplo n.º 30
-1
<?php

# $Id$
# PHPlot test: Box plot, with image map area outlines shown.
# This produces a plot image with the areas that would be in an image map
# outlined. It does not produce HTML or an image map.
require_once 'phplot.php';
$data = array(array('A', 1, 10, 12, 15, 17, 20), array('B', 2, 5, 10, 16, 20, 24, 2, 3, 4), array('C', 3, 12, 13, 14, 15, 16, 20), array('D', 4, 10, 11, 12, 13, 14), array('E', 5, 12, 12, 15, 18, 20), array('F', 6, 12, 14, 16, 18, 18), array('G', 7, 10, 10, 15, 20, 20));
$data_type = 'data-data';
$plot_type = 'boxes';
$title = "PHPlot Test: {$plot_type} plot with image map areas outlined";
# Callback for 'data_points': Outline the area
function store_map($im, $passthru, $shape, $row, $col, $x1, $y1, $x2, $y2)
{
    static $color = NULL;
    if (!isset($color)) {
        $color = imagecolorallocate($im, 255, 0, 0);
    }
    imagesetthickness($im, 3);
    imagerectangle($im, $x1, $y1, $x2, $y2, $color);
    imagesetthickness($im, 1);
}
$plot = new PHPlot(800, 600);
$plot->SetTitle($title);
$plot->SetImageBorderType('plain');
$plot->SetDataValues($data);
$plot->SetDataType($data_type);
$plot->SetPlotType($plot_type);
$plot->SetPlotAreaWorld(0, 0, 8, 25);
$plot->SetCallback('data_points', 'store_map');
$plot->DrawGraph();