Example #1
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();
}
 public function renderLot()
 {
     $grafico = new PHPlot(800, 600);
     $grafico->SetFileFormat("jpg");
     $grafico->SetIsInline(True);
     #Indicamos o títul do gráfico e o título dos dados no eixo X e Y do mesmo
     $grafico->SetTitle($this->data->titulo);
     $grafico->SetXTitle($this->data->eixoX);
     $grafico->SetYTitle($this->data->eixoY);
     #passamos o tipo de gráfico escolhido
     if (!$this->data->tipoLot) {
         $this->data->tipoLot = 'bars';
     }
     $grafico->SetPlotType($this->data->tipoLot);
     switch ($this->data->tipoLot) {
         case 'pie':
             $grafico->SetPieLabelType('index', 'custom', 'mycallback');
             $grafico->SetDataType('text-data-single');
             break;
         case 'stackedbars':
             $grafico->SetDataType('text-data-yx');
             break;
         case 'bubbles':
             $grafico->SetDataType('data-data-xyz');
             break;
     }
     $grafico->SetLegend($column_names);
     #Definimos os dados do gráfico
     switch ($this->data->tipoLot) {
         case 'pie':
             $dados = array(array($this->data->x1, $this->data->y11), array($this->data->x2, $this->data->y21), array($this->data->x3, $this->data->y31), array($this->data->x4, $this->data->y41));
             break;
         default:
             $dados = array(array($this->data->x1, $this->data->y11, $this->data->y12, $this->data->y13), array($this->data->x2, $this->data->y21, $this->data->y22, $this->data->y23), array($this->data->x3, $this->data->y31, $this->data->y32, $this->data->y33), array($this->data->x4, $this->data->y41, $this->data->y42, $this->data->y43));
             break;
     }
     $grafico->SetDataValues($dados);
     #Salvamos o gráfico
     $caminho = \Manager::getFilesPath();
     $fileName = uniqid() . '.jpg';
     $grafico->SetOutputFile($caminho . '/' . $fileName);
     $grafico->SetIsInline(True);
     $grafico->DrawGraph();
     #obtemos o endereco do grafico
     $this->data->locate = \Manager::getDownloadURL('files', basename($fileName), true);
 }
Example #3
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();
<?php

/* $Id: inline_image.php,v 1.2 2004-05-04 15:23:45 alex Exp $ */
if (!isset($_GET['which_title'])) {
    echo <<<EOF
<pre>
           *************************************************
           * This file is meant to be called only from the *
           *                   <a href="test_setup.php">test page</a>                   *
           * It will fail if called by itself.             *
           *************************************************
</pre>
EOF;
    exit;
}
// From PHP 4.?, register_globals is off, take it into account (MBD)
include '../phplot.php';
$graph = new PHPlot();
include './data.php';
$graph->SetTitle("{$_GET['which_title']}");
$graph->SetDataValues($example_data);
$graph->SetIsInline('1');
$graph->SetFileFormat("{$_GET['which_format']}");
$graph->DrawGraph();
Example #5
0
$title = array("Lines plot");
if ($tp['truecolor']) {
    $p = new PHPlot_truecolor(1024, 768);
    $title[] = "Truecolor";
} else {
    $p = new PHPlot(1024, 768);
    $title[] = "Palette Color";
}
$p->SetCallback('draw_setup', 'pre_plot');
$p->SetCallback('draw_all', 'post_plot');
# Reload data colors and apply alpha to all:
if (isset($tp['alpha'])) {
    $p->SetDataColors(NULL, NULL, $tp['alpha']);
    $title[] = "Alpha=" . $tp['alpha'];
}
$p->SetFileFormat($tp['output']);
$title[] = strtoupper($tp['output']) . ' Output';
if ($tp['antialias']) {
    $title[] = "Antialiased";
}
if ($tp['noalphablend']) {
    $title[] = "No alpha blending";
}
if (isset($tp['gamma'])) {
    $title[] = "Gamma=" . $tp['gamma'];
}
if ($tp['savealpha']) {
    $title[] = "Save alpha";
}
$p->SetTitle(implode(', ', $title));
$p->SetDataType('data-data');
Example #6
0
<?php

///////////////////////////////////////////////
//This file is meant only to be called from the
//testing function quick_start.php. It will fail
//if called by itself.
//////////////////////////////////////////////
include "../phplot.php";
$graph = new PHPlot();
include "./data.php";
$graph->SetTitle("{$which_title}");
$graph->SetDataValues($example_data);
$graph->SetIsInline("1");
$graph->SetFileFormat("{$file_format}");
$graph->DrawGraph();
Example #7
0
# $Id$
# Testing phplot - Transparent, GIF output (it works with PNG too)
# This really needs to be displayed in a browser above something to see.
# This is a parameterized test. Other scripts can set $tp and then include
# this script. The parameters are shown in the defaults array below:
if (!isset($tp)) {
    $tp = array();
}
$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');
Example #8
0
    }
}
////////////////////////////////////////////////
//Required Settings
include "../phplot.php";
$graph = new PHPlot($xsize_in, $ysize_in);
$graph->SetDataType($which_data_type);
// Must be first thing
$graph->SetDataValues($data);
//Optional Settings (Don't need them)
//	$graph->SetTitle("This is a\n\rmultiple line title\n\rspanning three lines.");
$graph->SetTitle($title);
$graph->SetXTitle($xlbl, $which_xtitle_pos);
$graph->SetYTitle($ylbl, $which_ytitle_pos);
$graph->SetLegend(array("A", "Bee", "Cee", "Dee"));
$graph->SetFileFormat($which_fileformat);
$graph->SetPlotType($which_plot_type);
$graph->SetUseTTF($which_use_ttf);
$graph->SetYTickIncrement($which_yti);
$graph->SetXTickIncrement($which_xti);
$graph->SetXTickLength($which_xtl);
$graph->SetYTickLength($which_ytl);
$graph->SetXTickCrossing($which_xtc);
$graph->SetYTickCrossing($which_ytc);
$graph->SetXTickPos($which_xtick_pos);
$graph->SetYTickPos($which_ytick_pos);
$graph->SetShading($which_shading);
$graph->SetLineWidth($which_line_width);
$graph->SetErrorBarLineWidth($which_errorbar_line_width);
$graph->SetDrawDashedGrid($which_dashed_grid);
switch ($which_draw_grid) {
    global $frame_rate;
    # Map 8 seconds of frames into 360 degrees (360/8 = 45 degrees/second)
    $theta = deg2rad(45 * $x / $frame_rate);
    return array('', sin($theta), cos($theta));
}
# Create an initial data array with no values. New values will be
# shifted in to the end. This is text-data format; the X values
# are implicit and ignored (not plotted).
for ($i = 0; $i < $n_rows; $i++) {
    $data[$i] = array('', '', '');
}
# Create and configure the PHPlot object:
$plot = new PHPlot(640, 480);
$plot->SetDataType('text-data');
$plot->SetPlotType('lines');
$plot->SetFileFormat('jpg');
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->SetXDataLabelPos('none');
# Don't draw the initial, empty values:
$plot->SetDrawBrokenLines(True);
# Force the Y range, or it will use the first frame to calculate:
$plot->SetPlotAreaWorld(NULL, $min_y, NULL, $max_y);
$plot->SetPrintImage(False);
# Main loop:
$plot->StartStream();
$timestamp = microtime(TRUE);
for ($frame = 0; $run_forever || $frame < $n_frames; $frame++) {
    # Set PHP timeout so it won't terminate the script early.
    set_time_limit(60);
    # Discard the oldest data row, and shift in the new row:
Example #10
0
function guifi_stats_chart07()
{
    include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php';
    $gDirTTFfonts = drupal_get_path('module', 'guifi') . '/contrib/fonts/';
    if (isset($_GET['width'])) {
        $gwidth = $_GET['width'];
    } else {
        $gwidth = 500;
    }
    if (isset($_GET['height'])) {
        $gheight = $_GET['height'];
    } else {
        $gheight = 450;
    }
    $today = getdate();
    $year = $today[year];
    $month = $today[mon];
    $month = $month - 12;
    $n = 0;
    $tot = 0;
    if ($month < 1) {
        $year = $year - 1;
        $month = 12 + $month;
    }
    $datemin = mktime(0, 0, 0, $month, 1, $year);
    if (isset($_GET['zone'])) {
        $zone_id = $_GET['zone'];
        if ($zone_id == "0") {
            $zone_id = "0";
        }
        //"3671";
    } else {
        $zone_id = "0";
    }
    $avalue = array();
    $adata = array();
    for ($i = 0; $i < 10; $i++) {
        $adata[] = array(0, 0);
    }
    $vsql = "select sum(if(timestamp_created >= " . $datemin . ",1,0)) as num, count(*) as total, zone_id\n      from {guifi_location}\n      where status_flag='Working' ";
    if ($zone_id != "0") {
        $achilds = guifi_zone_childs($zone_id);
        $v = "";
        foreach ($achilds as $key => $child) {
            if ($v == "") {
                $v .= "zone_id=" . $child;
            } else {
                $v .= " or zone_id=" . $child;
            }
        }
        $vsql .= "AND (" . $v . ") ";
    }
    $vsql .= "GROUP BY zone_id ";
    $result = db_query($vsql);
    while ($record = db_fetch_object($result)) {
        if ($record->total >= 20) {
            $vn = $record->num / $record->total * 100;
            $vmin = 0;
            for ($i = 1; $i < 10; $i++) {
                if ($adata[$vmin][1] > $adata[$i][1]) {
                    $vmin = $i;
                }
            }
            if ($vn > $adata[$vmin][1]) {
                $adata[$vmin][0] = $record->zone_id;
                $adata[$vmin][1] = $vn;
            }
        }
    }
    for ($i = 0; $i < 10; $i++) {
        if ($adata[$i][1] != 0) {
            $avalue[$adata[$i][0]] = $adata[$i][1];
        }
    }
    arsort($avalue);
    foreach ($avalue as $key => $value) {
        if ($value != 0) {
            $data[] = array(substr(guifi_get_zone_name($key), 0, 20) . "  �", $value);
        }
    }
    $shapes = array('none');
    $plot = new PHPlot($gwidth, $gheight);
    $plot->SetPlotAreaWorld(0, 0, NULL, NULL);
    $plot->SetFileFormat('png');
    $plot->SetDataType("text-data");
    $plot->SetDataValues($data);
    $plot->SetPlotType("bars");
    $plot->SetXTickIncrement(1);
    $plot->SetSkipBottomTick(TRUE);
    $plot->SetSkipLeftTick(TRUE);
    $plot->SetTickLength(0);
    //$plot->SetXTickPos('none');
    $plot->SetYDataLabelPos('plotin');
    $plot->SetYLabelType('data', 0);
    $plot->SetTickColor('grey');
    $plot->SetTTFPath($gDirTTFfonts);
    $plot->SetFontTTF('title', 'Vera.ttf', 12);
    $plot->SetFontTTF('x_label', 'Vera.ttf', 8);
    if (isset($_GET['title'])) {
        $plot->SetTitle("guifi.net      \n" . t($_GET['title']));
    } else {
        if ($zone_id == "0") {
            $plot->SetTitle("guifi.net      \n" . t('Largest annual increase'));
        } else {
            $plot->SetTitle("guifi.net    " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Largest annual increase'));
        }
    }
    //$plot->SetXTitle(t('Zones'));
    $plot->SetYTitle(t('% increase'));
    $plot->SetXDataLabelPos('plotdown');
    //$plot->SetXLabelAngle(45);
    $plot->SetXDataLabelAngle(75);
    $plot->SetGridColor('red');
    $plot->SetPlotBorderType('left');
    $plot->SetDataColors(array('orange'));
    $plot->SetTextColor('DimGrey');
    $plot->SetTitleColor('DimGrey');
    $plot->SetLightGridColor('grey');
    $plot->SetBackgroundColor('white');
    $plot->SetTransparentColor('white');
    $plot->SetIsInline(TRUE);
    $plot->DrawGraph();
}
Example #11
0
function plot_guifi()
{
    include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php';
    $result = db_query("select COUNT(*) as num, MONTH(FROM_UNIXTIME(timestamp_created)) as mes, YEAR(FROM_UNIXTIME(timestamp_created)) as ano from {guifi_location} where status_flag='Working' GROUP BY YEAR(FROM_UNIXTIME(timestamp_created)),MONTH(FROM_UNIXTIME(timestamp_created)) ");
    $inicial = 5;
    $nreg = $inicial;
    $tot = 0;
    $ano = 2004;
    $mes = 5;
    $items = 2004;
    $label = "";
    while ($record = db_fetch_object($result)) {
        if ($record->ano >= 2004) {
            if ($mes == 12) {
                $mes = 1;
                $ano++;
            } else {
                $mes++;
            }
            while ($ano < $record->ano || $mes < $record->mes) {
                $nreg++;
                if ($mes == 6) {
                    $label = $ano;
                } else {
                    $label = '';
                }
                $data[] = array("{$label}", $nreg, $tot, '');
                if ($mes == 12) {
                    $mes = 1;
                    $ano++;
                } else {
                    $mes++;
                }
            }
            $tot += $record->num;
            $nreg++;
            if ($mes == 6) {
                $label = $ano;
            } else {
                $label = '';
            }
            $data[] = array("{$label}", $nreg, $tot, '');
        } else {
            $tot += $record->num;
        }
    }
    while ($mes < 12) {
        $nreg++;
        $mes++;
        if ($mes == 6) {
            $label = $ano;
        } else {
            $label = '';
        }
        $data[] = array("{$label}", $nreg, "");
    }
    $items = ($ano - $items + 1) * 12;
    if ($tot % 1000 < 30) {
        $data[$nreg - $inicial - 1][3] = $tot;
        $vt = floor($tot / 1000) * 1000;
        $vtitle = $vt . " " . t('Nodes') . "!!!";
        $tcolor = 'red';
    } else {
        $vtitle = t('Working nodes');
        $tcolor = 'DimGrey';
    }
    $shapes = array('none', 'circle');
    $plot = new PHPlot(200, 150);
    $plot->SetPlotAreaWorld(0, 0, $items, NULL);
    $plot->SetFileFormat('png');
    $plot->SetDataType("data-data");
    $plot->SetDataValues($data);
    $plot->SetPlotType("linepoints");
    $plot->SetYTickIncrement(2000);
    $plot->SetXTickIncrement(12);
    $plot->SetSkipBottomTick(TRUE);
    $plot->SetSkipLeftTick(TRUE);
    $plot->SetXAxisPosition(0);
    $plot->SetPointShapes($shapes);
    $plot->SetPointSizes(10);
    $plot->SetTickLength(3);
    $plot->SetDrawXGrid(TRUE);
    $plot->SetTickColor('grey');
    $plot->SetTitle($vtitle);
    $plot->SetDrawXDataLabelLines(FALSE);
    $plot->SetXLabelAngle(0);
    $plot->SetXLabelType('custom', 'Plot1_LabelFormat');
    $plot->SetGridColor('red');
    $plot->SetPlotBorderType('left');
    $plot->SetDataColors(array('orange'));
    $plot->SetTextColor('DimGrey');
    $plot->SetTitleColor($tcolor);
    $plot->SetLightGridColor('grey');
    $plot->SetBackgroundColor('white');
    $plot->SetTransparentColor('white');
    $plot->SetXTickLabelPos('none');
    $plot->SetXDataLabelPos('plotdown');
    $plot->SetIsInline(TRUE);
    $plot->DrawGraph();
}
Example #12
0
$key = 0;
for ($i = 1; $i <= 10; $i++) {
    //math
    $quejas = 0;
    $num = $i;
    $texto = $i;
    $data1[$key] = array($texto, $num);
    $key++;
    $c++;
}
$plot = new PHPlot();
$plot->SetPlotType('bars');
$plot->SetDataType('text-data');
$plot->SetShading(0);
$plot->SetDataValues($data1);
$plot->SetFileFormat('png');
$plot->SetIsInline(true);
$plot->PHPlot(1200, 550, "images/tmp/img7.png");
$plot->DrawGraph();
$img7 = "images/tmp/img7.png";
//en consesionario
/** PDF **/
$pdf = new FPDF('L', 'mm', 'Letter');
$title = 'Incidencias Generales';
$pdf->SetTitle($title);
$pdf->SetAuthor('Loop Media');
$pdf->AddPage();
//bg
$pdf->Image('images/pdf_bg.jpg', 0, 0, $pdf->w, $pdf->h);
//tittulo
$pdf->SetFont('Times', '', 42);
Example #13
0
<?php

# $Id$
# PHPlot test: Reset transparent color (fixed at 6.0.0), case 0
# Set $case to 1 and include this script to reset the transparent color.
require_once 'phplot.php';
$data = array(array('Monday', 10), array('Tuesday', 20), array('Wednesday', 30), array('Thursday', 20), array('Friday', 50), array('Saturday', 5), array('Sunday', 10));
$p = new PHPlot();
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetFileFormat('gif');
$p->SetBackgroundColor('yellow');
$p->SetTransparentColor('yellow');
$title = "Transparent Color Reset Test";
if (empty($case)) {
    $title .= "\nBaseline - Transparent background";
} else {
    $title .= "\nReset - No transparent background";
    $p->SetTransparentColor(NULL);
}
$p->SetTitle($title);
$p->DrawGraph();
Example #14
0
     $stat['data'] = array(array('no data', 0));
 }
 if (count($stat['data']) == 0) {
     $stat['data'] = array(array(NULL, NULL));
 } elseif (count($stat['data'][0]) == 1) {
     $stat['data'][0][] = 0;
 }
 foreach ($plot_defaults as $key => $value) {
     if (!isset($stat[$key])) {
         $stat[$key] = $value;
     }
 }
 //Define the object
 $graph = new PHPlot($stat['xsize'], $stat['ysize']);
 $graph->SetDataType($stat['data_type']);
 $graph->SetFileFormat($stat['file_format']);
 $graph->SetPlotType($stat['graphtype']);
 $graph->SetDefaultTTFont('../tagsets/fonts/FreeSerif.ttf');
 $graph->SetPlotBorderType('none');
 // plotleft, plotright, both, full, none
 $graph->SetBackgroundColor($stat['background_color']);
 if ($stat['graphtype'] == 'bars') {
     $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) . '...';
         }
     }
Example #15
0
 $graph->SetTitle($GraphTitle);
 $graph->SetTitleColor('blue');
 $graph->SetOutputFile('companies/' . $_SESSION['DatabaseName'] . '/reports/salesgraph.png');
 $graph->SetXTitle(_('Month'));
 if ($_POST['GraphValue'] == 'Net') {
     $graph->SetYTitle(_('Sales Value'));
 } elseif ($_POST['GraphValue'] == 'GP') {
     $graph->SetYTitle(_('Gross Profit'));
 } else {
     $graph->SetYTitle(_('Quantity'));
 }
 $graph->SetXTickPos('none');
 $graph->SetXTickLabelPos('none');
 $graph->SetBackgroundColor('white');
 $graph->SetTitleColor('blue');
 $graph->SetFileFormat('png');
 $graph->SetPlotType($_POST['GraphType']);
 $graph->SetIsInline('1');
 $graph->SetShading(5);
 $graph->SetDrawYGrid(TRUE);
 $graph->SetDataType('text-data');
 $SalesResult = DB_query($SQL, $db);
 if (DB_error_no($db) != 0) {
     prnMsg(_('The sales graph data for the selected criteria could not be retrieved because') . ' - ' . DB_error_msg($db), 'error');
     include 'includes/footer.inc';
     exit;
 }
 if (DB_num_rows($SalesResult) == 0) {
     prnMsg(_('There is not sales data for the criteria entered to graph'), 'info');
     include 'includes/footer.inc';
     exit;
  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();
Example #17
0
/**
 * drawing the graph for a evaluation question
 *
 * @param array() $data
 * @param string $evalquestion_id
 */
function do_graph($data, $evalquestion_id)
{
    global $tmp_path_export, $auth, $PATH_EXPORT;
    $type = do_graph_template();
    //Define the object
    if ($type == "pie") {
        // Beim pie muss die Zeichenflaeche etwas groesser gewaehlt werden...
        $graph = new PHPlot(500, 300);
    } else {
        $graph = new PHPlot(300, 250);
    }
    if ($type == "pie") {
        // Beim pie muss das Array umgeformt werden. Bug in PHPlot?
        $tmp = array();
        $tmp2 = array();
        $legend = array();
        array_push($tmp, "Test");
        foreach ($data as $k => $d) {
            array_push($tmp, $d[1]);
            array_push($legend, $d[0]);
        }
        array_push($tmp2, $tmp);
        $data = $tmp2;
        $graph->SetLegend($legend);
    }
    //Data Colors
    $graph->SetDataColors(array("blue", "green", "yellow", "red", "PeachPuff", "orange", "pink", "lavender", "navy", "peru", "salmon", "maroon", "magenta", "orchid", "ivory"), array("black"));
    $max_x = max(array_map('next', $data));
    $graph->SetPlotAreaWorld(NULL, 0);
    // y-achse bei 0 starten
    $graph->SetPrecisionY(0);
    //anzahl kommastellen y-achse
    $graph->SetYTickIncrement($max_x < 10 ? 1 : round($max_x / 10));
    $graph->SetPlotBgColor(array(222, 222, 222));
    $graph->SetDataType("text-data");
    $graph->SetFileFormat(Config::get()->EVAL_AUSWERTUNG_GRAPH_FORMAT);
    $graph->SetOutputFile($tmp_path_export . "/evalsum" . $evalquestion_id . $auth->auth["uid"] . "." . Config::get()->EVAL_AUSWERTUNG_GRAPH_FORMAT);
    $graph->SetIsInline(true);
    $graph->SetDataValues($data);
    $graph->SetPlotType($type);
    $graph->SetXLabelAngle(count($data) < 10 ? 0 : 90);
    //$graph->SetShading(0); // kein 3D
    $graph->SetLineWidth(1);
    $graph->SetDrawXDataLabels(true);
    //Draw it
    $graph->DrawGraph();
}