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();
}
Example #2
0
function plotGraph($data)
{
    //Define the object
    $plot = new PHPlot();
    $example_data = $data;
    $plot->SetDataValues($example_data);
    $plot->SetDataType('data-data');
    //Set titles
    $plot->SetTitle("temp and humi");
    $plot->SetXTitle('time');
    $plot->SetYTitle('Y Data');
    $legend = array('temp', 'humi');
    $plot->SetLegend($legend);
    $plot->SetXDataLabelAngle(90);
    //$plot->SetXGridLabelType("time");
    $plot->SetXTickLabelPos('xaxis');
    $plot->SetXTickPos('plotdown');
    $plot->SetXLabelType('time', '%H:%M');
    $plot->TuneXAutoTicks(10, 'date');
    //	$plot->SetXTickIncrement(.5);
    //$plot->SetXTickIncrement(60 * 24);
    $plot->SetPlotType('lines');
    //$plot->SetPlotAreaWorld(strtotime('00:00'), null, strtotime('23:59'), null);
    $plot->SetDrawXGrid(true);
    //Draw it
    $plot->DrawGraph();
}
 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 #4
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;
}
Example #5
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();
 function servicios_años($param, $año_inicial, $año_final)
 {
     $this->autoLayout = false;
     $this->autoRender = false;
     $total_solicitudes = 0;
     // Obtenemos los años existentes, segun el parámetro de configuración.
     $param_año = '';
     if ($param == 'rango') {
         if ($año_inicial == $año_final) {
             $años[] = array(array('year' => $año_inicial));
         } else {
             $param_año = 'AND YEAR(solucionada)>= ' . $año_inicial . ' AND YEAR(solucionada)<= ' . $año_final;
         }
     }
     if (!isset($años)) {
         $años = $this->Solicitud->query("SELECT YEAR(solucionada) AS year FROM solicitudes WHERE estado='s' " . $param_año . " GROUP BY YEAR(solucionada)");
     }
     if (!empty($años)) {
         $total = array();
         foreach ($años as $año) {
             //$cantidad_solicitudes = $this->Solicitud->query("SELECT tipo_servicio, COUNT(*) AS cuenta FROM solicitudes WHERE estado='s' AND YEAR(solucionada)=".$año[0]['year']);
             $cantidad_solicitudes = $this->Solicitud->query("SELECT tipo_servicio FROM solicitudes WHERE estado='s' AND YEAR(solucionada)=" . $año[0]['year']);
             // Recreamos el arreglo de cant_solicitudes
             $cuentas = array('1' => 0, '2' => 0, '3' => 0);
             foreach ($cantidad_solicitudes as $cant_tipo_solicitud) {
                 $ts = split(',', $cant_tipo_solicitud['solicitudes']['tipo_servicio']);
                 for ($i = 0; $i < count($ts); $i++) {
                     switch ($ts[$i]) {
                         case '1':
                             ++$cuentas[1];
                             break;
                         case '2':
                             ++$cuentas[2];
                             break;
                         case '3':
                             ++$cuentas[3];
                             break;
                     }
                 }
             }
             for ($i = 0; $i < 3; $i++) {
                 $cant_solicitudes[$i] = array('solicitudes' => array('tipo_servicio' => $i + 1), 0 => array('cuenta' => $cuentas[$i + 1]));
             }
             $total[$año[0]['year']] = $cant_solicitudes;
             for ($j = 0; $j < count($cant_solicitudes); $j++) {
                 $total_solicitudes += $cant_solicitudes[$j][0]['cuenta'];
             }
         }
         if (!empty($total)) {
             $arreglo_plot = array();
             foreach ($total as $año => $arreglo_año) {
                 // se construye el array para el PHPlot.
                 $ts_1 = $ts_2 = $ts_3 = 0;
                 for ($i = 0; $i < count($arreglo_año); $i++) {
                     switch ($arreglo_año[$i]['solicitudes']['tipo_servicio']) {
                         case '1':
                             $ts_1 = $arreglo_año[$i][0]['cuenta'];
                             break;
                         case '2':
                             $ts_2 = $arreglo_año[$i][0]['cuenta'];
                             break;
                         case '3':
                             $ts_3 = $arreglo_año[$i][0]['cuenta'];
                             break;
                     }
                 }
                 $arreglo_plot[] = array($año, $ts_1, $ts_2, $ts_3);
             }
             $plot = new PHPlot();
             $plot->SetDataValues($arreglo_plot);
             $plot->SetDataType('text-data');
             // Fuentes
             $plot->SetUseTTF(true);
             $plot->SetFontTTF('legend', 'FreeSans.ttf', 9);
             $plot->SetFontTTF('title', 'FreeSans.ttf', 14);
             $plot->SetFontTTF('y_label', 'FreeSans.ttf', 10);
             $plot->SetFontTTF('x_label', 'FreeSans.ttf', 10);
             $plot->SetFontTTF('y_title', 'FreeSans.ttf', 14);
             $plot->SetFontTTF('x_title', 'FreeSans.ttf', 12);
             // Titulos
             $plot->SetTitle("\nSolicitudes de\nservicio por años\nTOTAL: " . $total_solicitudes);
             $plot->SetXTitle('AÑOS');
             $plot->SetYTitle('# SOLICITUDES');
             // Etiquetas
             $plot->SetXTickLabelPos('none');
             $plot->SetXTickPos('none');
             $plot->SetYTickLabelPos('none');
             $plot->SetYTickPos('none');
             $plot->SetYDataLabelPos('plotin');
             $plot->SetDrawXGrid(true);
             // Leyenda
             $leyenda = array('Mantenimiento Preventivo', 'Mantenimiento Correctivo', 'Calibraciones/Certificados');
             $plot->SetLegend($leyenda);
             $plot->SetLegendPixels(414, 0);
             $plot->SetDataColors(array('beige', 'YellowGreen', 'SkyBlue'));
             $plot->SetPlotType('bars');
             $plot->SetShading(7);
             $plot->DrawGraph();
         }
     }
 }
Example #7
0
File: test.php Project: jcmwc/fleet
<?php

# PHPlot Example - Horizontal Stacked Bars
require_once 'phplot.php';
$column_names = array('Beef', 'Fish', 'Pork', 'Chicken', 'Butter', 'Cheese', 'Ice Cream');
//                   |       |       |       |       |       |       |
$data = array(array('1910', 48.5, 11.2, 38.2, 11.0, 18.4, 3.9, 1.9), array('1930', 33.7, 10.2, 41.1, 11.1, 17.6, 4.7, 9.699999999999999), array('1950', 44.6, 11.9, 43.0, 14.3, 10.9, 7.7, 17.4), array('1970', 79.59999999999999, 11.7, 48.1, 27.4, 5.4, 11.4, 17.8), array('1990', 63.9, 14.9, 46.4, 42.4, 4.0, 24.6, 15.8));
$plot = new PHPlot(800, 500);
$plot->SetImageBorderType('plain');
// Improves presentation in the manual
$plot->SetTitle("U.S. Annual Per-Capita Consumption\n" . "of Selected Meat and Dairy Products");
$plot->SetLegend($column_names);
#  Move the legend to the lower right of the plot area:
$plot->SetLegendPixels(700, 300);
$plot->SetDataValues($data);
$plot->SetDataType('text-data-yx');
$plot->SetPlotType('stackedbars');
$plot->SetXTitle('Pounds Consumed Per Capita');
#  Show data value labels:
$plot->SetXDataLabelPos('plotstack');
#  Rotate data value labels to 90 degrees:
$plot->SetXDataLabelAngle(90);
#  Format the data value labels with 1 decimal place:
$plot->SetXDataLabelType('data', 1);
#  Specify a whole number for the X tick interval:
$plot->SetXTickIncrement(20);
#  Disable the Y tick marks:
$plot->SetYTickPos('none');
$plot->DrawGraph();
Example #8
0
    # Explicit X or Y, no error bars
    $data = array(array('A', 0, 0, 0), array('B', 1, 1, 2), array('H', 7, 7, 14), array('D', 3, 3, 6), array('F', 5, 5, 10), array('C', 2, 2, 4), array('G', 6, 6, 12), array('E', 4, 4, 8));
} elseif (!$implied_x && $error_bars) {
    # Explicit X, error bars
    $data = array(array('A', 0, 0, 1, 0, 0, 0, 0), array('B', 1, 1, 1, 1, 2, 1, 1), array('H', 7, 7, 1, 1, 14, 1, 1), array('D', 3, 3, 1, 0, 6, 0, 0), array('F', 5, 5, 1, 1, 10, 1, 0), array('C', 2, 2, 0, 1, 4, 1, 1), array('G', 6, 6, 1, 1, 12, 0, 1), array('E', 4, 4, 0, 0, 8, 1, 1));
} else {
    fwrite(STDERR, "Error: Unknown data type or not decoded: {$data}-type\n");
    exit(1);
}
$p = new PHPlot(800, 800);
$p->SetTitle("Testing PHPlot ({$plot_type}, {$data_type})");
$p->SetDataType($data_type);
$p->SetDataValues($data);
$p->SetPlotType($plot_type);
if ($horizontal) {
    $p->SetXTitle('X Axis - Dependent variable');
    $p->SetYTitle('Y Axis - Independent variable');
    $p->SetXDataLabelPos('plotin');
    // Tick labels left, Axis Data labels right, so both can be seen.
    $p->SetYTickLabelPos('plotleft');
    $p->SetYDataLabelPos('plotright');
} else {
    $p->SetXTitle('X Axis - Independent variable');
    $p->SetYTitle('Y Axis - Dependent variable');
    $p->SetYDataLabelPos('plotin');
    // Tick labels below, Axis Data labels above, so both can be seen.
    $p->SetXTickLabelPos('plotdown');
    $p->SetXDataLabelPos('plotup');
}
# Customizations for error plots:
if ($error_bars) {
Example #9
0
     $WhereClause .= " salesperson='" . $_POST['SalesmanCode'] . "' AND";
 }
 if ($_POST['GraphOn'] == 'Customer') {
     $GraphTitle .= ' ' . _('For Customers from') . ' ' . $_POST['ValueFrom'] . ' ' . _('to') . ' ' . $_POST['ValueTo'];
     $WhereClause .= "  cust >='" . $_POST['ValueFrom'] . "' AND cust <='" . $_POST['ValueTo'] . "' AND";
 }
 if ($_POST['GraphOn'] == 'StockID') {
     $GraphTitle .= ' ' . _('For Items from') . ' ' . $_POST['ValueFrom'] . ' ' . _('to') . ' ' . $_POST['ValueTo'];
     $WhereClause .= "  stockid >='" . $_POST['ValueFrom'] . "' AND stockid <='" . $_POST['ValueTo'] . "' AND";
 }
 $WhereClause = "WHERE " . $WhereClause . " salesanalysis.periodno>='" . $_POST['FromPeriod'] . "' AND salesanalysis.periodno <= '" . $_POST['ToPeriod'] . "'";
 $SQL = "SELECT salesanalysis.periodno,\n\t\t\t\tperiods.lastdate_in_period,\n\t\t\t\tSUM(CASE WHEN budgetoractual=1 THEN " . $SelectClause . " ELSE 0 END) AS sales,\n\t\t\t\tSUM(CASE WHEN  budgetoractual=0 THEN " . $SelectClause . " ELSE 0 END) AS budget\n\t\tFROM salesanalysis INNER JOIN periods ON salesanalysis.periodno=periods.periodno " . $WhereClause . "\n\t\tGROUP BY salesanalysis.periodno,\n\t\t\tperiods.lastdate_in_period\n\t\tORDER BY salesanalysis.periodno";
 $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);
Example #10
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();
Example #11
0
<?php

# $Id$
# Testing phplot - Title Colors. Case 1 - 3 different colors (main, X, Y)
# Other scripts can set $c1, $c2, and/or $c3 to a color or NULL to set the
# main, X, and/or Y titles, then include this script.
require_once 'phplot.php';
if (empty($c1) && empty($c2) && empty($c3)) {
    $c1 = 'red';
    $c2 = 'blue';
    $c3 = 'green';
}
$subtitle = 'Main: ' . (empty($c1) ? 'default' : $c1) . ', X: ' . (empty($c2) ? 'default' : $c2) . ', Y: ' . (empty($c3) ? 'default' : $c3);
$data = array(array('A', 0), array('B', 1), array('C', 2));
$p = new PHPlot(600, 600);
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitle("Title color test\n{$subtitle}");
$p->SetXTitle("Title color test - X title", 'both');
$p->SetYTitle("Title color test - Y title", 'both');
if (!empty($c1)) {
    $p->SetTitleColor($c1);
}
if (!empty($c2)) {
    $p->SetXTitleColor($c2);
}
if (!empty($c3)) {
    $p->SetYTitleColor($c3);
}
$p->DrawGraph();
Example #12
0
# 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();
$p->SetLegendPixels();
$p->SetNumXTicks();
$p->SetNumYTicks();
$p->SetXTitle('X Axis');
$p->SetYTitle('Y Axis');
$p->SetXAxisPosition();
$p->SetYAxisPosition();
$p->SetPlotAreaPixels(70, 450, 380, 750);
$p->DrawGraph();
$p->PrintImage();
Example #13
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');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitle('Vertical Bar Plot With Labels');
$p->SetXTitle('Independent Variable');
$p->SetYTitle('Dependent Variable');
$p->SetXDataLabelPos('plotdown');
$p->SetXTickPos('none');
$p->SetYDataLabelPos('plotin');
$p->SetPlotAreaWorld(NULL, 0, NULL, 40);
$p->SetYTickIncrement(5);
$p->SetImageBorderType('plain');
$p->DrawGraph();
Example #14
0
function guifi_stats_chart05($nmonths)
{
    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;
    }
    if (isset($_GET['zone'])) {
        $zone_id = $_GET['zone'];
        if ($zone_id == "3671") {
            $zone_id = "0";
        }
    } else {
        $zone_id = "0";
    }
    $vsql = "select COUNT(*) as num, MONTH(FROM_UNIXTIME(timestamp_created)) as mes, YEAR(FROM_UNIXTIME(timestamp_created)) as ano \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 YEAR(FROM_UNIXTIME(timestamp_created)),MONTH(FROM_UNIXTIME(timestamp_created)) ";
    $result = db_query($vsql);
    $inicial = 5;
    $nreg = $inicial;
    $tot = 0;
    $ano = 2004;
    $mes = 5;
    $items = 2004;
    $label = "a";
    $n = 0;
    $med = 0;
    $datos = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $today = getdate();
    if ($nmonths == 0) {
        $nmonths = 12;
    }
    $max = 0;
    while ($record = db_fetch_object($result)) {
        if ($record->ano >= 2004) {
            if ($mes == 12) {
                $mes = 1;
                $ano++;
            } else {
                $mes++;
            }
            if ($ano == $today[year] && $mes >= $today[mon]) {
                if ($mes == 1) {
                    $mes = 12;
                    $ano--;
                } else {
                    $mes--;
                }
                break;
            }
            while ($ano < $record->ano || $mes < $record->mes) {
                $nreg++;
                if ($mes == 6) {
                    $label = $ano;
                } else {
                    $label = '';
                }
                if ($n == 0) {
                    $tot += $record->num;
                } else {
                    $tot = $record->num;
                }
                $tot2 = fmediacalc($tot, $datos, $n, $nmonths);
                $data[] = array("{$label}", $nreg, $tot2);
                if (floor($tot2) > $max) {
                    $max = floor($tot2);
                }
                if ($mes == 12) {
                    $mes = 1;
                    $ano++;
                } else {
                    $mes++;
                }
            }
            $tot += $record->num;
            $nreg++;
            if ($mes == 6) {
                $label = $ano;
            } else {
                $label = '';
            }
            if ($n == 0) {
                $tot += $record->num;
            } else {
                $tot = $record->num;
            }
            $tot2 = fmediacalc($tot, $datos, $n, $nmonths);
            $data[] = array("{$label}", $nreg, $tot2);
            if (floor($tot2) > $max) {
                $max = floor($tot2);
            }
        } else {
            $tot += $record->num;
        }
    }
    while ($mes < 12) {
        $nreg++;
        $mes++;
        if ($mes == 6) {
            $label = $ano;
        } else {
            $label = '';
        }
        $data[] = array("{$label}", $nreg, "");
    }
    if ($tot <= 10) {
        $inc = 1;
    } else {
        $vlen = strlen($max);
        $vini = substr($max, 0, 1);
        $inc = str_pad($vini, $vlen - 1, "0");
    }
    $items = ($ano - $items + 1) * 12;
    $shapes = array('none');
    $plot = new PHPlot($gwidth, $gheight);
    $plot->SetPlotAreaWorld(0, 0, $items, NULL);
    $plot->SetFileFormat('png');
    $plot->SetDataType("data-data");
    $plot->SetDataValues($data);
    $plot->SetPlotType("linepoints");
    $plot->SetYTickIncrement($inc);
    $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->SetTTFPath($gDirTTFfonts);
    $plot->SetFontTTF('title', 'Vera.ttf', 12);
    if (isset($_GET['title'])) {
        $plot->SetTitle("guifi.net      \n" . t($_GET['title']));
    } else {
        if ($zone_id == "0") {
            $plot->SetTitle("guifi.net      \n" . t('Nodes per month, ' . "{$nmonths}" . ' months average'));
        } else {
            $plot->SetTitle("guifi.net    " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Nodes per month, ' . "{$nmonths}" . ' months average'));
        }
    }
    $plot->SetXTitle(t('Years'));
    $plot->SetYTitle(t('Working nodes'));
    $plot->SetDrawXDataLabelLines(FALSE);
    $plot->SetXLabelAngle(0);
    $plot->SetXLabelType('custom', 'guifi_stats_chart05_LabelFormat');
    $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->SetXTickLabelPos('none');
    $plot->SetXDataLabelPos('plotdown');
    $plot->SetIsInline(TRUE);
    $plot->DrawGraph();
}
Example #15
0
<?php

# $Id$
# PHPlot bug 1813071: Wrong title height for multi-line TTF text
# Note: This overlaps the title_text* tests somewhat, but with more fonts.
require_once 'phplot.php';
require 'config.php';
# Font info
$data = array(array('A', -3, 6), array('B', -2, 4), array('C', -1, 2), array('D', 0, 0), array('E', 1, -2), array('F', 2, -4), array('G', 3, -6));
$p = new PHPlot(800, 800);
$p->SetTTFPath($phplot_test_ttfdir);
$p->SetDefaultTTFont($phplot_test_ttfonts['sans']);
$p->SetFont('title', $phplot_test_ttfonts['serifbolditalic'], 14);
$p->SetFont('x_title', $phplot_test_ttfonts['sansbold'], 10);
$p->SetFont('y_title', $phplot_test_ttfonts['serifbold'], 10);
$p->SetTitle("TrueType Text Title\nLine 2 of title\nLine 3 of title\nLine 4");
$p->SetXTitle("X Axis Tile\nLine 2\nLine 3\nLine 4");
$p->SetYTitle("Y Axis Tile\nLine 2\nLine 3\nLine 4");
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetXDataLabelPos('none');
$p->SetXTickIncrement(1.0);
$p->SetYTickIncrement(1.0);
$p->SetPlotType('lines');
$p->DrawGraph();
Example #16
0
    $p->SetFont('y_title', '', 12);
    $p->SetFont('x_label', '', 12);
    $p->SetFont('y_label', '', 12);
    $p->SetFont('generic', '', 14);
} elseif ($tp['use_gdf']) {
    $p->SetFont('legend', '4');
    $p->SetFont('title', '5');
    $p->SetFont('x_title', '3');
    $p->SetFont('y_title', '3');
    $p->SetFont('x_label', '2');
    $p->SetFont('y_label', '2');
    $p->SetFont('generic', '2');
}
# All axis, all labels, both sides
$p->SetTitle($tp['title'] . $tp['suffix']);
$p->SetLegend(array('Legend 1', 'Legend 2', 'Legend 3'));
$p->SetXTitle('X Axis Title Here', 'both');
$p->SetYTitle('Y Axis Title Here', 'both');
$p->SetXTickLabelPos('none');
$p->SetXTickPos('none');
$p->SetXDataLabelPos('both');
$p->SetYTickLabelPos('both');
$p->SetYTickPos('both');
$p->SetYDataLabelPos('plotin');
if (isset($tp['x_label_angle'])) {
    $p->SetXLabelAngle($tp['x_label_angle']);
}
if (isset($tp['y_label_angle'])) {
    $p->SetYLabelAngle($tp['y_label_angle']);
}
$p->DrawGraph();
Example #17
0
<?php

# PHPlot example - horizontal thinbarline plot (impulse plot)
require_once 'phplot.php';
$data = array(array('', 79, 33.18), array('', 13, 22.62), array('', 71, 41.18), array('', 8, 14.72), array('', 48, 49.92), array('', 46, 49.68), array('', 90, 18.0), array('', 15, 25.5), array('', 73, 39.42), array('', 30, 42.0), array('', 24, 36.48), array('', 85, 25.5), array('', 14, 24.08), array('', 3, 5.82), array('', 98, 3.92), array('', 39, 47.58), array('', 70, 42.0), array('', 16, 26.88), array('', 81, 30.78), array('', 40, 48.0), array('', 44, 49.28));
$plot = new PHPlot(800, 400);
$plot->SetImageBorderType('plain');
// Improves presentation in the manual
$plot->SetUseTTF(True);
$plot->SetTitle('Experimental Results');
$plot->SetXTitle('Density (g/cm&#179;)');
// 179=superscript 3
$plot->SetYTitle('Temperature (&#176;C)');
// 176=degrees
$plot->SetPlotType('thinbarline');
$plot->SetDataType('data-data-yx');
$plot->SetDataValues($data);
$plot->SetPlotAreaWorld(0, 0, 50, 100);
$plot->SetLineWidths(4);
$plot->DrawGraph();
Example #18
0
require_once 'phplot.php';
$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 (1)\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->SetXTickIncrement(5.0);
$p->SetYTickIncrement(50.0);
$p->SetXTitle('X Axis');
$p->SetYTitle('Y Axis');
$p->SetXAxisPosition(-228);
$p->SetYAxisPosition(7);
$p->SetPlotAreaPixels(70, 80, 380, 400);
$p->DrawGraph();
$p->SetLegendPixels();
$p->SetXTickIncrement();
$p->SetYTickIncrement();
$p->SetXAxisPosition();
$p->SetYAxisPosition();
$p->SetPlotAreaPixels(70, 450, 380, 750);
$p->DrawGraph();
$p->PrintImage();
Example #19
0
<?php

# $Id$
# Test: Stacked area
require_once 'phplot.php';
# This is based on area1 with adjusted numbers.
$data = array(array('1960', 30, 10, 6, 38, 14, 2), array('1970', 20, 17, 9, 32, 2, 20), array('1980', 20, 14, 12, 27, 2, 25), array('1990', 5, 26, 15, 26, 18, 10), array('2000', 28, 0, 18, 16, 33, 5));
$plot = new PHPlot(800, 600);
$plot->SetPlotType('stackedarea');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
$plot->SetTitle('Candy Sales by Flavor');
$plot->SetPlotAreaWorld(NULL, 0, NULL, 110);
$plot->SetYTickIncrement(10);
$plot->SetYTitle('% of Total');
$plot->SetXTitle('Year');
$plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta'));
$plot->SetLegend(array('Cherry', 'Lime', 'Lemon', 'Banana', 'Apple', 'Berry'));
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->DrawGraph();
Example #20
0
<?php

# $Id$
# PHPlot Test: bug 2914403 Pie + X/Y titles: Undefined property error
# The bug was that X and Y titles were supposed to be ignored, but if
# set then an undefined property error occurred.
require_once 'phplot.php';
$data = array(array('', 50), array('', 30), array('', 20));
$plot = new PHPlot(800, 600);
$plot->SetTitle('Pie + X/Y Title Bug');
$plot->SetXTitle('Ignored X title');
$plot->SetYTitle('Ignored Y title');
$plot->SetImageBorderType('plain');
$plot->SetDataType('text-data-single');
$plot->SetDataValues($data);
$plot->SetPlotType('pie');
$plot->DrawGraph();
Example #21
0
                $data[$key] = array($data_row0[$key], $data_row1[$key], $data_row2[$key], $data_row3[$key], $data_row4[$key]);
            }
        }
    }
}
////////////////////////////////////////////////
//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);
Example #22
0
$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'));
// Must clear X and Y titles or they are drawn again, possibly with offset.
$p->SetXTitle('');
$p->SetYTitle('');
$p->DrawGraph();
Example #23
0
<?php

# $Id$
# Testing phplot - Default TT font (2b): Local path and named font.
# This test requires a specific font (see TEST_FONT) be present in the images/
# directory. The listed font is redistributable under the Open Fonts License.
require_once 'phplot.php';
define('TEST_FONT', 'FreeUniversal-Regular.ttf');
$data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2));
$p = new PHPlot(800, 800);
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetTitle('Local TTF path and SetFontTTF with file basename only');
$p->SetXTitle('X Axis Title');
$p->SetYTitle('Y Axis Title');
$p->SetTTFPath(getcwd() . DIRECTORY_SEPARATOR . 'images');
$p->SetFontTTF('title', TEST_FONT, 18);
$p->SetFontTTF('x_title', TEST_FONT, 14);
$p->SetFontTTF('y_title', TEST_FONT, 10);
$p->DrawGraph();
fwrite(STDERR, "OK defaultfont2b: title font=" . $p->fonts['title']['font'] . "\n");
Example #24
0
<?php

# $Id$
# Test types of label formatting 2 (custom, data:3)
require_once 'phplot.php';
function my_format($val, $arg)
{
    $m = (int) ($val / 60);
    $h = (int) ($m / 60);
    $m %= 60;
    return sprintf("%dH%dM", $h, $m);
}
$data = array();
for ($i = 0; $i < 10; $i++) {
    $data[] = array('', 4000 * $i, 1234 * $i);
}
$p = new PHPlot(800, 600);
$p->SetTitle("Label Format Test 2");
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetXDataLabelPos('none');
$p->SetXTickIncrement(2000);
$p->SetYTickIncrement(1000);
$p->SetPlotType('lines');
$p->SetXLabelType('custom', 'my_format');
$p->SetXTitle("X: custom H:M");
$p->SetYLabelType('data', 3);
$p->SetYTitle("Y: data, prec=3");
$p->DrawGraph();
Example #25
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();
Example #26
0
# 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' => 'Tick Count:', 'xmin' => 0, 'xmax' => 98, 'ymin' => 0, 'ymax' => 55, 'xti' => 10, 'yti' => 10), $tp);
require_once 'phplot.php';
# The data points don't matter at all. The range is set with SetPlotAreaWorld.
$data = array(array('', 0, 0), array('', 1, 1));
$p = new PHPlot();
$subtitle = " World: ({$tp['xmin']}, {$tp['ymin']}) :" . " ({$tp['xmax']}, {$tp['ymax']})" . " Tickstep: ({$tp['xti']}, {$tp['yti']})";
$p->SetTitle($tp['title'] . $subtitle);
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetXDataLabelPos('none');
$p->SetXTitle('X');
$p->SetYTitle('Y');
$p->SetPlotAreaWorld($tp['xmin'], $tp['ymin'], $tp['xmax'], $tp['ymax']);
$p->SetXTickIncrement($tp['xti']);
$p->SetYTickIncrement($tp['yti']);
#$p->SetSkipTopTick(False);
# Draw both grids:
$p->SetDrawXGrid(True);
$p->SetDrawYGrid(True);
# Axes on all sides:
$p->SetXTickPos('both');
$p->SetXTickLabelPos('both');
$p->SetYTickPos('both');
$p->SetYTickLabelPos('both');
$p->SetPlotBorderType('full');
$p->SetPlotType('lines');
Example #27
0
    $data[7][3] = 1;
    $data[10][1] = $data[10][2] = 0;
}
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('stackedbars');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
if ($tp['compat']) {
    # backward compatible mode
    $plot->SetTitle('Candy Sales by Month and Product');
    $plot->SetYTitle('Millions of Units');
    $plot->SetLegend(array('Chocolates', 'Mints', 'Hard Candy', 'Sugar-Free'));
} else {
    $plot->SetTitle($tp['title'] . $tp['suffix']);
    $plot->SetXTitle('Month');
    $plot->SetYTitle('Number of Units');
}
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
if (isset($tp['shading'])) {
    $plot->SetShading($tp['shading']);
}
if (isset($tp['xaxispos'])) {
    $plot->SetXAxisPosition($tp['xaxispos']);
}
if (isset($tp['ydatalabel'])) {
    $plot->SetYDataLabelPos($tp['ydatalabel']);
}
if (isset($tp['custom'])) {
    call_user_func($tp['custom'], $plot);
Example #28
0
<?php

# $Id$
# Test types of label formatting 4 (time, data:0:prefix+suffix)
require_once 'phplot.php';
$data = array();
$t = mktime(12, 0, 0, 6, 1, 2000);
for ($i = 0; $i < 12; $i++) {
    $data[] = array('', $t, $i * 13.4);
    $t += 60 * 60 * 24;
}
$p = new PHPlot(800, 600);
$p->SetTitle("Label Format 4");
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetXDataLabelPos('none');
$p->SetXTickIncrement(60 * 60 * 24);
$p->SetYTickIncrement(10);
$p->SetPlotType('lines');
$p->SetXLabelType('time', '%m/%d');
$p->SetXTitle("X: time MM/DD");
$p->SetYLabelType('data', 0, '$', '#');
$p->SetYTitle("Y: data, prec=0, prefix=\$, suffix=#");
$p->DrawGraph();
#fwrite(STDERR, print_r($p, True));
Example #29
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();
Example #30
0
<?php

//Include the code
require_once 'phplot.php';
//Define the object
$plot = new PHPlot(800, 600);
//Set titles
$plot->SetTitle("A 3-Line Plot\nMade with PHPlot");
$plot->SetXTitle('X Data');
$plot->SetYTitle('Y Data');
//Define some data
$example_data = array(array('a', 3, 4, 2), array('b', 5, '', 1), array('c', 7, 2, 6), array('d', 8, 1, 4), array('e', 2, 4, 6), array('f', 6, 4, 5), array('g', 7, 2, 3));
$plot->SetDataValues($example_data);
//Turn off X axis ticks and labels because they get in the way:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
//Draw it
$plot->DrawGraph();