Exemplo n.º 1
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();
}
Exemplo n.º 2
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.º 3
0
<?php

# $Id$
# Testing phplot - data-data ordering
require_once 'phplot.php';
# 10 lines, one for each shape:
$data = array(array('', 1, 20), array('', 2, 2), array('', 3, 19), array('', 4, 3), array('', 6, 4), array('', 7, 17), array('', 8, 5), array('', 9, 16), array('', 5, 18), array('', 10, 6));
$p = new PHPlot();
$p->SetTitle('Out-of-order data-data points');
$p->SetPlotType('lines');
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotAreaWorld(0, 0, 12, 25);
$p->SetXTickIncrement(1);
$p->SetYTickIncrement(1);
# We don't use the data labels (all set to '') so might as well turn them off:
$p->SetXDataLabelPos('none');
# Draw both grids:
$p->SetDrawXGrid(True);
$p->SetDrawYGrid(True);
# The default
$p->DrawGraph();
Exemplo n.º 4
0
require_once 'phplot.php';
$np = $tp['nlines'];
$data = array();
for ($i = 1; $i <= 20; $i++) {
    $row = array('', $i);
    for ($j = 1; $j <= $np; $j++) {
        $row[] = $i + $j;
    }
    $data[] = $row;
}
$p = new PHPlot(800, 600);
$p->SetTitle($tp['title'] . $tp['suffix']);
$p->SetDataType('data-data');
$p->SetDataValues($data);
$p->SetPlotAreaWorld(0, 0, 21, 40);
$p->SetXTickIncrement(1);
$p->SetYTickIncrement(5);
# Options:
if (isset($tp['LWidths'])) {
    $p->SetLineWidths($tp['LWidths']);
}
if (isset($tp['DStyle'])) {
    $p->SetDefaultDashedStyle($tp['DStyle']);
}
if (isset($tp['LStyles'])) {
    $p->SetLineStyles($tp['LStyles']);
}
$p->SetDrawXGrid(False);
$p->SetDrawYGrid(False);
$p->SetPlotType('lines');
$p->DrawGraph();
Exemplo n.º 5
0
        }
        $data[] = $row;
    }
} else {
    // Regular plot that works with text-data data type:
    $data_type = 'text-data';
    for ($pt = 0; $pt < $n_x; $pt++) {
        $row = array(strftime('%b', mktime(12, 12, 12, $pt + 1, 1, 2000)));
        for ($r = 0; $r < $groups; $r++) {
            $row[] = mt_rand(0, $max_y);
        }
        $data[] = $row;
    }
}
$plot = new PHPlot();
$plot->SetTitle($title . $suffix);
$plot->SetDataType($data_type);
$plot->SetDataValues($data);
$plot->SetPlotType($plottype);
$plot->SetPlotAreaWorld(0, 0, $n_x, $max_y);
# Position data labels:
$plot->SetXDataLabelPos($labelpos);
# Turn data label lines on or off:
$plot->SetDrawXDataLabelLines($labellines);
# Turn off Tick labels and X Tick marks - they aren't used.
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
# Don't draw grids, so we can see the data lines.
$plot->SetDrawXGrid(False);
$plot->SetDrawYGrid(False);
$plot->DrawGraph();
Exemplo n.º 6
0
# Printing helper
function prif($name, &$var, $before = '')
{
    return "{$before} {$name}=" . (isset($var) ? $var : "n/a");
}
# Auto title:
$title = 'X/Y Tick Anchors' . (empty($subtitle) ? "\n" : " - {$subtitle}\n") . prif('X tick anchor', $x_tick_anchor) . prif('Y tick anchor', $y_tick_anchor, ',') . prif('X tick inc.', $x_tick_step, ',') . prif('Y tick inc.', $y_tick_step, ',');
$data = array();
for ($x = $start; $x <= $stop; $x += $delta) {
    $data[] = array('', $x, $x);
}
$plot = new PHPlot(800, 600);
$plot->SetTitle($title);
$plot->SetPlotType('lines');
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetDrawXGrid(True);
$plot->SetDrawYGrid(True);
if (isset($x_tick_step)) {
    $plot->SetXTickIncrement($x_tick_step);
}
if (isset($y_tick_step)) {
    $plot->SetYTickIncrement($y_tick_step);
}
if (isset($x_tick_anchor)) {
    $plot->SetXTickAnchor($x_tick_anchor);
}
if (isset($y_tick_anchor)) {
    $plot->SetYTickAnchor($y_tick_anchor);
}
$plot->DrawGraph();
Exemplo n.º 7
0
$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) {
    case 'x':
        $graph->SetDrawXGrid(TRUE);
        $graph->SetDrawYGrid(FALSE);
        break;
    case 'y':
        $graph->SetDrawXGrid(FALSE);
        $graph->SetDrawYGrid(TRUE);
        break;
    case 'both':
        $graph->SetDrawXGrid(TRUE);
        $graph->SetDrawYGrid(TRUE);
        break;
    case 'none':
        $graph->SetDrawXGrid(FALSE);
        $graph->SetDrawYGrid(FALSE);
}
$graph->SetXTickLabelPos($which_xtick_label_pos);
 function costo_externo_interno_año($id_oficina, $año)
 {
     $this->autoLayout = false;
     $this->autoRender = false;
     $this->loadModel('CentroCosto');
     $sql_oficina = '';
     if ($id_oficina != 0) {
         $sql_oficina = " AND Cencos_id='" . $id_oficina . "' ";
         $cenco = $this->CentroCosto->find('first', array('fields' => array('CentroCosto.Cencos_nombre'), 'conditions' => array('CentroCosto.Cencos_id' => $id_oficina)));
         $subtitulo_oficina = 'la dependencia ' . mb_convert_case($cenco['CentroCosto']['Cencos_nombre'], MB_CASE_TITLE, "UTF-8");
     } else {
         $subtitulo_oficina = 'todas las dependencias';
     }
     $meses = $this->Solicitud->query("SELECT MONTH(solucionada) AS mes FROM solicitudes WHERE estado='s' " . $sql_oficina . " AND YEAR(solucionada)=" . $año . " GROUP BY MONTH(solucionada)");
     if (!empty($meses)) {
         // Inicializamos el arreglo en ceros (para los meses ke no tienen solicitudes).
         $totales = array();
         for ($i = 1; $i <= 12; $i++) {
             $totales[$i][0][0] = array('costo_i' => 0, 'costo_e' => 0);
         }
         foreach ($meses as $mes) {
             $costos_e_i = $this->Solicitud->query("SELECT SUM(costo_externo) AS costo_e, SUM(costo_interno) AS costo_i FROM solicitudes WHERE estado='s' AND YEAR(solucionada)=" . $año . " AND MONTH(solucionada)=" . $mes[0]['mes']);
             $totales[$mes[0]['mes']] = $costos_e_i;
         }
         if (!empty($totales)) {
             $total_costo_interno = $total_costo_externo = 0;
             $i = 0;
             $arreglo_plot = array();
             foreach ($totales as $mes => $arreglo_mes) {
                 // se construye el array para el PHPlot.
                 if (count($arreglo_mes) > 0) {
                     $arreglo_plot[$i] = array($this->meses[$mes], $arreglo_mes[0][0]['costo_i'], $arreglo_mes[0][0]['costo_e']);
                     $total_costo_interno += $arreglo_mes[0][0]['costo_i'];
                     $total_costo_externo += $arreglo_mes[0][0]['costo_e'];
                 } else {
                     $arreglo_plot[$i] = array($this->meses[$mes], 0, 0);
                 }
                 $i++;
             }
             $plot = new PHPlot(1790, 500);
             $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', 9);
             $plot->SetFontTTF('x_label', 'FreeSans.ttf', 10);
             $plot->SetFontTTF('y_title', 'FreeSans.ttf', 14);
             $plot->SetFontTTF('x_title', 'FreeSans.ttf', 12);
             // Titulos
             $plot->SetTitle("\nTotal de costos internos/externos\n" . "de " . $subtitulo_oficina . " en el año " . $año . "\n TOTAL Costo Interno = \$" . $total_costo_interno . "\n" . "TOTAL Costo Externo = \$" . $total_costo_externo);
             $plot->SetYTitle('$ COSTO');
             // Etiquetas
             $plot->SetXTickLabelPos('none');
             $plot->SetXTickPos('none');
             $plot->SetYTickLabelPos('none');
             $plot->SetYTickPos('none');
             $plot->SetYDataLabelPos('plotin');
             $plot->SetDrawXGrid(true);
             // Leyenda
             $leyenda = array('Costo Interno', 'Costo Externo');
             $plot->SetLegend($leyenda);
             $plot->SetLegendPixels(27, 0);
             $plot->SetDataColors(array('beige', 'YellowGreen'));
             $plot->SetPlotType('bars');
             $plot->SetShading(5);
             $plot->DrawGraph();
         }
     }
 }
Exemplo n.º 9
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();
}
Exemplo n.º 10
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();
}
Exemplo n.º 11
0
 function graficarDemandaPronosticoError($oData)
 {
     $sql = "select\r\n\t\t\t\tdate_format(c1.fecha_fin, '%d/%m/%Y') fecha_fin, \r\n\t\t\t\tcantidad_demandada, \r\n\t\t\t\tprediccion, \r\n\t\t\t\terror,\r\n\t\t\t\tsenial \r\n\t\t\t\tfrom (\r\n\t\t\t\t\tselect\r\n\t\t\t\t\tfecha_fin, \r\n\t\t\t\t\tcantidad_demandada, \r\n\t\t\t\t\tprediccion, \r\n\t\t\t\t\terror, \r\n\t\t\t\t\tsenial \r\n\t\t\t\t\tfrom predicciones t1 \r\n\t\t\t\t\tinner join periodos t2 on t1.id_periodo = t2.id_periodo \r\n\t\t\t\t\twhere id_producto= " . $oData["id_producto"] . " \r\n\t\t\t\t\torder by fecha_fin asc) c1";
     $rs = getRS($sql);
     $data = array();
     $nro = getNrosRows($rs);
     $flag = 1;
     if ($nro) {
         while ($row = getRow($rs)) {
             if ($flag) {
                 $inicio = $row['fecha_fin'];
                 $flag = 0;
             }
             $nro--;
             if ($nro == 0) {
                 $fin = $row['fecha_fin'];
             }
             $data[] = array('', $row['cantidad_demandada'], $row['prediccion'], $row['error'], $row['senial']);
         }
     }
     $plot = new PHPlot(800, 465);
     //$plot->SetImageBorderType('plain');
     $plot->SetPlotType('lines');
     //tipo de gráfico
     $plot->SetDataType('text-data');
     $plot->SetDataValues($data);
     $plot->SetTitle('Demanda real, predicción, error y señal de rastreo. Periodo ' . $inicio . ' al ' . $fin);
     //Título
     $plot->SetLegend(array('Demanda real', 'Pronóstico', 'Error', 'Señal de rastreo'));
     //Referencia
     $plot->SetLineWidths(2);
     //ancho de la linea
     $plot->SetLineStyles("solid");
     //estilo de la linea
     $plot->SetDataColors(array('green', 'blue', 'red', 'purple'));
     $plot->SetXTickLabelPos('none');
     $plot->SetXTickPos('none');
     # Draw both grids:
     $plot->SetDrawXGrid(True);
     $plot->SetDrawYGrid(True);
     $plot->DrawGraph();
 }
Exemplo n.º 12
0
# PHPlot Example - Horizontal Bars
require_once 'phplot.php';
$data = array(array('San Francisco CA', 20.11), array('Reno NV', 7.5), array('Phoenix AZ', 8.300000000000001), array('New York NY', 49.7), array('New Orleans LA', 64.2), array('Miami FL', 52.3), array('Los Angeles CA', 13.2), array('Honolulu HI', 18.3), array('Helena MT', 11.3), array('Duluth MN', 31.0), array('Dodge City KS', 22.4), array('Denver CO', 15.8), array('Burlington VT', 36.1), array('Boston MA', 42.5), array('Barrow AL', 4.2));
$plot = new PHPlot(800, 800);
$plot->SetImageBorderType('plain');
// Improves presentation in the manual
$plot->SetTitle("Average Annual Precipitation (inches)\n" . "Selected U.S. Cities");
$plot->SetBackgroundColor('gray');
#  Set a tiled background image:
$plot->SetPlotAreaBgImage('images/drop.png', 'centeredtile');
#  Force the X axis range to start at 0:
$plot->SetPlotAreaWorld(0);
#  No ticks along Y axis, just bar labels:
$plot->SetYTickPos('none');
#  No ticks along X axis:
$plot->SetXTickPos('none');
#  No X axis labels. The data values labels are sufficient.
$plot->SetXTickLabelPos('none');
#  Turn on the data value labels:
$plot->SetXDataLabelPos('plotin');
#  No grid lines are needed:
$plot->SetDrawXGrid(FALSE);
#  Set the bar fill color:
$plot->SetDataColors('salmon');
#  Use less 3D shading on the bars:
$plot->SetShading(2);
$plot->SetDataValues($data);
$plot->SetDataType('text-data-yx');
$plot->SetPlotType('bars');
$plot->DrawGraph();
 function solicitudes_reparacion_por_operario($id_operario, $año)
 {
     $this->loadModel('ReparacionSolicitud');
     $this->loadModel('Funcionario');
     $meses = $this->ReparacionSolicitud->query("SELECT MONTH(archivada) AS mes FROM reparacion_solicitudes WHERE estado='a' AND ejecutada=1 AND YEAR(archivada)=" . $año . " GROUP BY MONTH(archivada)");
     if (!empty($meses)) {
         // Inicializamos el arreglo en ceros (para los meses ke no tienen solicitudes).
         $total = array();
         for ($i = 1; $i <= 12; $i++) {
             $total[$i][0][0] = array('cuenta' => 0);
         }
         foreach ($meses as $mes) {
             $cant_solicitudes = $this->ReparacionSolicitud->query("SELECT COUNT(*) AS cuenta FROM reparacion_solicitudes WHERE id_funcionario=" . $id_operario . " AND estado='a' AND ejecutada=1 AND YEAR(archivada)=" . $año . " AND MONTH(archivada)=" . $mes[0]['mes']);
             $total[$mes[0]['mes']] = $cant_solicitudes;
         }
         if (!empty($total)) {
             $operario = $this->Funcionario->find('first', array('conditions' => array('Funcionario.id' => $id_operario), 'fields' => array('Funcionario.nombre')));
             foreach ($total as $mes => $arreglo_mes) {
                 $arreglo_plot[] = array($this->meses[$mes], $arreglo_mes[0][0]['cuenta']);
             }
             $plot = new PHPlot(890, 450);
             $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);
             // Titulos
             $plot->SetTitle("\nSolicitudes de reparación\natendidas por " . mb_convert_case($operario['Funcionario']['nombre'], MB_CASE_TITLE, "UTF-8"));
             $plot->SetXTitle('AÑO ' . $año);
             $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('Solicitudes de Reparación');
             $plot->SetLegend($leyenda);
             $plot->SetLegendPixels(703, 0);
             $plot->SetPlotType('bars');
             $plot->SetShading(7);
             $plot->DrawGraph();
         }
     }
 }