Exemplo n.º 1
0
function draw_graph($example_data, $attribute)
{
    require_once 'phplot.php';
    $plot = new PHPlot_truecolor(800, 800);
    $plot->SetTitle('Distribution of ' . $attribute);
    $plot->SetImageBorderType('plain');
    // Improves presentation in the manual
    $plot->SetDataValues($example_data);
    $plot->SetPlotType('linepoints');
    $plot->SetDrawYDataLabelLines(True);
    $plot->SetXTitle("Selected Dates");
    $plot->SetYTitle($attribute);
    $plot->DrawGraph();
}
Exemplo n.º 2
0
<?php

# $Id$
# PHPlot test: Truecolor linepoints, looking at point shapes
require_once 'phplot.php';
# Array of all point shapes as of PHPlot-5.1.0:
$point_shapes = array('halfline', 'line', 'plus', 'cross', 'rect', 'circle', 'dot', 'diamond', 'triangle', 'trianglemid', 'delta', 'yield', 'star', 'hourglass', 'bowtie', 'target', 'box', 'home', 'up', 'down');
$n = count($point_shapes);
$data = array();
for ($x = 0; $x < 4; $x++) {
    $row = array('', $x);
    for ($i = 0; $i < $n; $i++) {
        $row[] = ($i + 1) / 3 * $x;
    }
    $data[] = $row;
}
$p = new PHPlot_truecolor(1000, 800);
$p->SetTitle("Truecolor linespoint plot with all point shapes");
$p->SetDataType('data-data');
$p->SetDataValues($data);
# Reload data colors and apply alpha to all:
$p->SetDataColors(NULL, NULL, 60);
$p->SetLineWidths(3);
$p->SetLineStyles('solid');
$p->SetPointSizes(16);
$p->SetPointShapes($point_shapes);
$p->SetPlotType('linepoints');
$p->DrawGraph();
Exemplo n.º 3
0
# PHPlot test: Truecolor pie chart without shading
# Parameters that can be set externally:
if (!isset($shading)) {
    $shading = 0;
}
// Shading, empty string to omit
if (!isset($alpha)) {
    $alpha = 50;
}
// Default data colors alpha, NULL to skip
require_once 'phplot.php';
$data = array();
for ($i = 0; $i < 16; $i++) {
    $data[] = array('', 1);
}
$p = new PHPlot_truecolor(800, 800);
if ($shading === '') {
    $d_shading = "default shading";
} elseif ($shading === 0) {
    $d_shading = "no shading";
} else {
    $d_shading = "shading={$shading}";
}
$p->SetTitle("Truecolor Piechart with alpha={$alpha}, {$d_shading}");
$p->SetDataType('text-data-single');
$p->SetDataValues($data);
if (isset($alpha)) {
    $p->SetDataColors(NULL, NULL, $alpha);
}
$p->SetPlotType('pie');
if ($shading !== '') {
Exemplo n.º 4
0
# Make some pseudo-random data.
mt_srand(1);
$data = array();
$value = 10;
for ($i = 0; $i < 500; $i++) {
    $data[] = array('', $i, $value);
    $value = max(0, $value + mt_rand(-9, 10));
}
# Make a color gradient array of blue:
$colors = array();
for ($b = 32; $b <= 255; $b += 2) {
    $colors[] = array(0, 0, $b);
}
for ($b = 255; $b >= 32; $b -= 2) {
    $colors[] = array(0, 0, $b);
}
# Use a truecolor plot image in order to get more colors.
$plot = new PHPlot_truecolor(800, 600);
$plot->SetImageBorderType('plain');
// Improves presentation in the manual
$plot->SetPlotType('thinbarline');
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetLineWidths(2);
$plot->SetDataColors($colors);
$plot->SetXTickPos('none');
$plot->SetPlotAreaWorld(0, 0, 500, NULL);
$plot->SetTitle('Meaningless Data with Color Gradient');
# Establish the function 'getcolor' as a data color selection callback.
$plot->SetCallback('data_color', 'getcolor');
$plot->DrawGraph();
Exemplo n.º 5
0
# Parameters that can be set externally:
if (!isset($shading)) {
    $shading = 0;
}
// Shading, empty string to omit
if (!isset($alpha)) {
    $alpha = 50;
}
// Default data colors alpha, NULL to skip
if (!isset($plottype)) {
    $plottype = 'bars';
}
// bars or stackedbars
require_once 'phplot.php';
$data = array(array('Spring', 10, 20, 40, 45, 60), array('Summer', 15, 22, 40, 55, 80), array('Fall', 20, 24, 47, 65, 83), array('Winter', 20, 24, 47, 65, 83));
$p = new PHPlot_truecolor(800, 800);
if ($shading === '') {
    $d_shading = "default shading";
} elseif ($shading === 0) {
    $d_shading = "no shading";
} else {
    $d_shading = "shading={$shading}";
}
$p->SetTitle("Truecolor {$plottype} chart with alpha={$alpha}, {$d_shading}");
$p->SetDataType('text-data');
$p->SetDataValues($data);
if (isset($alpha)) {
    $p->SetDataColors(NULL, NULL, $alpha);
}
$p->SetPlotType($plottype);
if ($shading !== '') {
Exemplo n.º 6
0
<?php

# $Id$
# PHPlot test: Truecolor stacked area plot
require_once 'phplot.php';
$data = array(array('A', 2, 3, 1, 3, 2, 1), array('B', 4, 1, 5, 0, 4, 2), array('C', 2, 3, 1, 3, 2, 3), array('D', 4, 1, 5, 0, 4, 4));
$p = new PHPlot_truecolor(800, 800);
$p->SetTitle("Truecolor Stacked Area chart with alpha channel");
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetDataColors(NULL, NULL, 60);
// Set alpha for all
$p->SetPlotType('stackedarea');
$p->SetDrawXGrid(True);
$p->SetXTickLabelPos('none');
$p->SetXTickPos('none');
$p->DrawGraph();
Exemplo n.º 7
0
<?php

# $Id$
# PHPlot test - transparency - truecolor, set transparent then set background
require_once 'phplot.php';
$data = array(array('A', 6), array('B', 4), array('C', 2), array('D', 0));
$p = new PHPlot_truecolor();
$p->SetTitle('Truecolor, Set transparent, Set background color');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitleColor('green');
// For contrast vs black/clear background
$p->SetTransparentColor('yellow');
$p->SetBackgroundColor('yellow');
$p->DrawGraph();
Exemplo n.º 8
0
<?php

# $Id$
# PHPlot test: Truecolor area plot, alpha gradient
require_once 'phplot.php';
$data = array(array('', 90, 60, 45, 40, 20, 0), array('', 100, 80, 55, 40, 22, 15), array('', 83, 65, 47, 47, 24, 20));
$colors = array('red:100', 'red:80', '#ff00003c', 'red:40', 'red:20', 'red');
$p = new PHPlot_truecolor(800, 800);
$p->SetTitle("Truecolor Area chart with red alpha gradient");
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetDataColors($colors);
$p->SetPlotType('area');
$p->SetDrawXGrid(True);
$p->SetXTickLabelPos('none');
$p->SetXTickPos('none');
$p->DrawGraph();
Exemplo n.º 9
0
function plot_histogram($image_filename, $param)
{
    extract($param);
    $histo = get_histogram($image_filename);
    if (empty($histo)) {
        return;
    }
    for ($i = 0; $i < 256; $i++) {
        $data[$i] = array('', $histo[$i]);
    }
    $p = new PHPlot_truecolor($plot_image_width, $plot_image_height);
    $p->SetFileFormat('jpg');
    $p->SetBgImage($image_filename, 'scale');
    $p->SetDataType('text-data');
    $p->SetDrawXAxis(False);
    $p->SetDrawYAxis(False);
    $p->SetDataValues($data);
    $p->SetXDataLabelPos('none');
    $p->SetXTickLabelPos('none');
    $p->SetYTickLabelPos('none');
    $p->SetXTickPos('none');
    $p->SetYTickPos('none');
    $p->SetDrawYGrid(False);
    $p->SetDataColors($histogram_color, NULL, $histogram_alpha);
    $p->SetPlotType('thinbarline');
    if ($draw_border) {
        $p->SetGridColor($border_color);
        $p->SetPlotBorderType('full');
    } else {
        $p->SetPlotBorderType('none');
    }
    # Compute the position of the histogram plot within the image.
    $hx0 = (int) ($hx * $plot_image_width);
    $hy0 = (int) ($hy * $plot_image_height);
    $hx1 = (int) ($h_width * $plot_image_width) + $hx0;
    $hy1 = (int) ($h_height * $plot_image_height) + $hy0;
    $p->SetPlotAreaPixels($hx0, $hy0, $hx1, $hy1);
    $p->DrawGraph();
}
Exemplo n.º 10
0
// Y range
$max_z = 100;
// Z range
$alpha = 80;
// Alpha (transparency) for data colors. 0=opaque, 127=clear.
$data = array();
mt_srand(1);
for ($x = 0; $x < $n_x; $x++) {
    $row = array('', mt_rand(0, $max_x - 1));
    // Label and X value
    for ($y = 0; $y < $n_y; $y++) {
        $row[] = mt_rand(0, $max_y - 1);
        // Y value
        $row[] = mt_rand(0, $max_z - 1);
        // Z value
    }
    $data[] = $row;
}
$legend = array();
for ($y = 0; $y < $n_y; $y++) {
    $legend[] = "Data Set {$y}";
}
$p = new PHPlot_truecolor(800, 600);
$p->SetTitle("Bubble Plot - Random data, Truecolor\nTranslucent (alpha={$alpha}) bubbles");
$p->SetDataColors(NULL, NULL, $alpha);
$p->SetDataType('data-data-xyz');
$p->SetPlotType('bubbles');
$p->SetDataValues($data);
$p->SetLegend($legend);
$p->SetPlotAreaWorld(0, 0, $max_x, $max_y);
$p->DrawGraph();
Exemplo n.º 11
0
<?php

# $Id$
# PHPlot test - transparency - truecolor, set data color then set transparent
require_once 'phplot.php';
$data = array(array('A', 6), array('B', 4), array('C', 2), array('D', 0));
$p = new PHPlot_truecolor();
$p->SetTitle('Truecolor, Set data color, Set transparent');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetDataColors('yellow');
$p->SetTransparentColor('yellow');
$p->DrawGraph();
Exemplo n.º 12
0
<?php

# $Id$
# PHPlot test: Truecolor points plot, big overlapped dots
require_once 'phplot.php';
mt_srand(0);
$data = array();
for ($i = 0; $i < 20; $i++) {
    $row = array('', $i);
    for ($j = 0; $j < 30; $j++) {
        $row[] = mt_rand(0, 100) / 10.0;
    }
    $data[] = $row;
}
$p = new PHPlot_truecolor(800, 600);
$p->SetTitle('Truecolor Points plot with varying size poionts');
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetDataColors(NULL, NULL, 90);
$p->SetLineWidths(3);
$p->SetLineStyles('solid');
$p->SetPointShapes('dot');
$p->SetPointSizes(array(10, 15, 20, 25, 30));
$p->SetPlotType('points');
$p->SetXTickIncrement(1);
$p->SetYTickIncrement(1);
$p->DrawGraph();