Exemplo n.º 1
4
function test_case($case)
{
    global $cases, $test_verbose, $n_tests, $n_pass, $n_fail, $test_save;
    $n_tests++;
    extract($cases[$case]);
    $title = "Test case {$n_tests}: {$data_type} (should match {$like})";
    # Make a data array that is valid (but not necessarily reasonable)
    # for any data type. One works for all except pie chart.
    if (!empty($pie)) {
        $plot_type = 'pie';
        $data = array(array('', 1), array('', 1), array('', 2));
    } else {
        $plot_type = 'lines';
        # Valid for text-data, data-data, and data-data-error:
        $data = array(array('', 1, 2, 2, 2), array('', 2, 4, 1, 1), array('', 3, 5, 2, 2));
    }
    $p1 = new PHPlot(400, 300);
    $p1->SetFailureImage(False);
    $p1->SetPrintImage(False);
    $p1->SetDataValues($data);
    $p1->SetDataType($data_type);
    // Alias data type
    $p1->SetPlotType($plot_type);
    $p1->DrawGraph();
    $p1_image = $p1->EncodeImage('raw');
    if ($test_save) {
        file_put_contents("dta-{$case}a_{$data_type}.png", $p1_image);
    }
    $p2 = new PHPlot(400, 300);
    $p2->SetFailureImage(False);
    $p2->SetPrintImage(False);
    $p2->SetDataValues($data);
    $p2->SetDataType($like);
    // Base data type - alias should match this
    $p2->SetPlotType($plot_type);
    $p2->DrawGraph();
    $p2_image = $p2->EncodeImage('raw');
    if ($test_save) {
        file_put_contents("dta-{$case}b_{$like}.png", $p2_image);
    }
    if ($p1_image == $p2_image) {
        $n_pass++;
        if ($test_verbose) {
            echo "Pass: {$title}\n";
        }
    } else {
        $n_fail++;
        echo "FAIL - Image Mismatch: {$title}\n";
    }
}
Exemplo n.º 2
1
function graficoBarra($data, $archivo = "", $meta_data = array('titulo' => 'Sin Título', 'tituloX' => 'Eje X', 'tituloY' => 'Eje Y', 'color' => 'SkyBlue', 'width' => 800, 'height' => 600, 'angle' => 45), $legend = array("Datos"))
{
    # Objeto que crea el gráfico y su tama?o
    $plot = new PHPlot($meta_data['width'], $meta_data['height']);
    $plot->SetImageBorderType('plain');
    # Setea el archivo donde se guarda la imagen generada y no permite la visualización inmediata
    $plot->SetPrintImage(false);
    $plot->SetFileFormat("jpg");
    $plot->SetOutputFile($archivo);
    $plot->SetIsInline(true);
    # Envio de datos
    $plot->SetDataValues($data);
    # Tipo de gráfico y datos
    $plot->SetDataType("text-data");
    $plot->SetPlotType("bars");
    # Setiando el True type font
    //$plot->SetTTFPath(TTFPath);
    //$plot->SetUseTTF(TRUE);
    $plot->SetAxisFontSize(2);
    $plot->SetVertTickIncrement(7);
    //$plot->SetXTickLength(7);
    //$plot->SetDataColors($meta_data['color']);
    $plot->SetDataColors(array($meta_data['color'], 'red', 'white'));
    $plot->SetLegendPixels(1, 1);
    $plot->SetLegend($legend);
    # Etiquetas del eje Y:
    $plot->SetYTitle($meta_data['tituloY']);
    $plot->SetYDataLabelPos('plotin');
    # Título principal del gráfico:
    $plot->SetTitle($meta_data['titulo']);
    # Etiquetas eje X:
    $plot->SetXTitle($meta_data['tituloX']);
    if (isset($meta_data['angle'])) {
        $plot->SetXLabelAngle($meta_data['angle']);
    } else {
        $plot->SetXLabelAngle(45);
    }
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');
    # Método que dibuja el gráfico
    $plot->DrawGraph();
    $plot->PrintImage();
}
Exemplo n.º 3
0
function make_plot($plot_type, $data_type, $nx, $ny)
{
    $plot = new PHPlot(1280, 1024);
    $plot->SetPrintImage(False);
    $plot->SetFailureImage(False);
    $plot->SetDataType($data_type);
    $plot->SetDataValues(make_data_array($plot_type, $data_type, $nx, $ny, 100));
    $plot->SetPlotType($plot_type);
    $plot->SetTitle("Serialize/Unserialize Tests\n{$plot_type} - {$data_type}");
    $plot->SetXTickIncrement(5);
    $plot->SetYTickIncrement(10);
    $plot->SetPlotBorderType('full');
    $plot->SetDrawXGrid(True);
    $plot->SetDrawYGrid(True);
    $plot->SetXTitle('X Axis Title');
    $plot->SetYTitle('Y Axis Title');
    # Select data labels or tick labels based on data type:
    if ($data_type == 'data-data') {
        $plot->SetXDataLabelPos('none');
        $plot->SetXTickLabelPos('plotdown');
        $plot->SetXTickPos('plotdown');
    } elseif ($data_type == 'text-data') {
        $plot->SetXDataLabelPos('plotdown');
        $plot->SetXTickLabelPos('none');
        $plot->SetXTickPos('none');
    } elseif ($data_type == 'data-data-yx') {
        $plot->SetYDataLabelPos('none');
        $plot->SetYTickLabelPos('plotleft');
        $plot->SetYTickPos('plotleft');
    } elseif ($data_type == 'text-data-yx') {
        $plot->SetYDataLabelPos('plotleft');
        $plot->SetYTickLabelPos('none');
        $plot->SetYTickPos('none');
    }
    return $plot;
}
Exemplo n.º 4
0
  license@systemsmanager.net so we can mail you a copy immediately.
*/
include DIR_WS_CLASSES . 'phplot.php';
$year = $_GET['year'] ? $_GET['year'] : date('Y');
$month = $_GET['month'] ? $_GET['month'] : date('n');
$days = date('t', mktime(0, 0, 0, $month)) + 1;
$stats = array();
for ($i = 1; $i < $days; $i++) {
    $stats[] = array($i, '0', '0');
}
$banner_stats_query = smn_db_query("select dayofmonth(banners_history_date) as banner_day, banners_shown as value, banners_clicked as dvalue from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . $banner_id . "' and month(banners_history_date) = '" . $month . "' and year(banners_history_date) = '" . $year . "'");
while ($banner_stats = smn_db_fetch_array($banner_stats_query)) {
    $stats[$banner_stats['banner_day'] - 1] = array($banner_stats['banner_day'], $banner_stats['value'] ? $banner_stats['value'] : '0', $banner_stats['dvalue'] ? $banner_stats['dvalue'] : '0');
}
$graph = new PHPlot(600, 350, 'images/graphs/banner_daily-' . $banner_id . '.' . $banner_extension);
$graph->SetFileFormat($banner_extension);
$graph->SetIsInline(1);
$graph->SetPrintImage(0);
$graph->SetSkipBottomTick(1);
$graph->SetDrawYGrid(1);
$graph->SetPrecisionY(0);
$graph->SetPlotType('lines');
$graph->SetPlotBorderType('left');
$graph->SetTitleFontSize('4');
$graph->SetTitle(sprintf(TEXT_BANNERS_DAILY_STATISTICS, $banner['banners_title'], strftime('%B', mktime(0, 0, 0, $month)), $year));
$graph->SetBackgroundColor('white');
$graph->SetVertTickPosition('plotleft');
$graph->SetDataValues($stats);
$graph->SetDataColors(array('blue', 'red'), array('blue', 'red'));
$graph->DrawGraph();
$graph->PrintImage();
Exemplo n.º 5
0
# $Id$
# PHPlot test: Overlay OHLC chart with lines
# From PHPlot forum 2010-12-20
require_once 'phplot.php';
// First data array for OHLC data: Date, Open, High, Low, Close
$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();
Exemplo n.º 6
0
    // Demonstration data: Title (and tool-tip text), alt text, URL:
    $title = "Segment {$segment}";
    $alt = "Region for segment {$segment}";
    $href = "example_{$segment}.html";
    // Make a comma-separated list of coordinates, for the image map:
    $coords = implode(',', $points);
    // Generate the image map area:
    $image_map .= "  <area shape=\"poly\" coords=\"{$coords}\"" . " title=\"{$title}\" alt=\"{$alt}\" href=\"{$href}\">\n";
}
# Data for pie chart
$data = array(array('', 1), array('', 2), array('', 3), array('', 2), array('', 5));
$plot = new PHPlot(800, 600);
// Disable error images, since this script produces HTML:
$plot->SetFailureImage(False);
// Disable automatic output of the image:
$plot->SetPrintImage(False);
// Set up the rest of the plot:
$plot->SetTitle("'{$plot_type}' plot with image map");
$plot->SetImageBorderType('plain');
$plot->SetDataValues($data);
$plot->SetDataType($data_type);
$plot->SetPlotType($plot_type);
// Set the data_points callback which will generate the image map:
$plot->SetCallback('data_points', 'store_map');
// Produce the graph; this also creates the image map via callback:
$plot->DrawGraph();
$data_url = $plot->EncodeImage();
$html = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     "http://www.w3.org/TR/html4/loose.dtd">
<html>
Exemplo n.º 7
0
if ($title_sequence >= $n_plots) {
    $title_sequence = $n_plots - 1;
}
// Set title before last plot.
# Fake some data:
for ($i = 0; $i < $n_plots; $i++) {
    $report[$i] = array(array('Alpha', $i), array('Beta', 1.5 * $i), array('Gamma', 2 * $i));
}
$max_x = 2 * ($n_plots - 1) + 1;
$image_height = $n_plots * ($height_of_each_plot + $space_below_plots) + $title_space;
$plot = new PHPlot(800, $image_height);
$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'));
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();
$pdf->AddPage();
$pdf->GDImage($graph->img, 30, 20, 140);
$pdf->Output();
Exemplo n.º 9
0
} else {
    $message .= $text;
}
if (!empty($extra_chars)) {
    $message .= str_repeat(' Test', (int) ($extra_chars / 5));
}
$p = new PHPlot(800, 600);
if (!empty($use_gdfont)) {
    $p->SetFontGD('generic', 5);
} elseif (!empty($use_ttfont)) {
    $p->SetTTFPath($phplot_test_ttfdir);
    $p->SetFontTTF('generic', $phplot_test_ttfonts['serifitalic'], 14);
}
if (!empty($set_bgcolor)) {
    $p->SetBackgroundColor('yellow');
}
if (!empty($set_bgimage)) {
    $p->SetBgImage('images/bubbles.png', 'tile');
}
if (!empty($set_border)) {
    $p->SetImageBorderWidth(3);
    $p->SetImageBorderColor('red');
    $p->SetImageBorderType('raised');
}
if (!empty($noprint)) {
    $p->SetPrintImage(False);
}
$p->DrawMessage($message, $options);
if (!empty($noprint)) {
    echo $p->EncodeImage('raw');
}
Exemplo n.º 10
0
start a tick mark at the bottom of the range. This is the expected
behavior, even though it results in unusual numbers along the Y axis.
In a real application, you would probably do one of the following to make
more reasonable tick mark values:
    SetPlotAreaWorld() - have PHPlot re-calculate the range and tick values
Or
    SetYTickAnchor(0) - force a tick at Y=0; this moves all the ticks to
whole numbers.
*/
$data = array();
# 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();
Exemplo n.º 11
0
$data = $stateSalesArray;
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('none');
$plot->SetPlotType('bars');
$plot->SetFont('x_label', 4, 3);
$plot->SetFont('y_label', 4, 3);
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
$plot->SetDataColors("#ffbb33");
# Main plot title:
$plot->SetTitle('State Wise Report');
# Make a legend for the 3 data sets plotted:
$plot->SetLegend(array('Total Amount (INR)'));
# Turn off X tick labels and ticks because they don't apply here:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
//Draw it
$plot->SetPrintImage(false);
$plot->DrawGraph();
?>
<img src="<?php 
echo $plot->EncodeImage();
?>
" style="width:46%;height:350px;display:inline-block;float:right;">
<hr style="visibility: hidden;clear:both">
<br><br><br>
<div id="reportTable" style="display:block;clear:both; margin-top:3%;">
</div>