Пример #1
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();
}
Пример #2
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 !== '') {
    $p->SetShading($shading);
}
$p->SetXTickPos('none');
$p->DrawGraph();
Пример #3
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();