Example #1
0
// Creates the bars
$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
$bplot3 = new BarPlot($datay3);
// Gets the names for the database to be used as legend on the picture
if ($stmt = $mysqli->prepare("SELECT legend1, legend2, legend3 \n                                    FROM legend\n\t\t\t\t\t\t\t\t\tWHERE tabell = 'Energi - Energiforbruk ditt areal - Kristiansand' \n\t\t\t\t\t\t\t\t\tLIMIT 1")) {
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($legend1, $legend2, $legend3);
    $stmt->fetch();
}
$bplot1->SetLegend($legend1);
$bplot2->SetLegend($legend2);
$bplot3->SetLegend($legend3);
// To gather the bar plots close to eachother
$gbarplot = new GroupBarPlot(array($bplot1, $bplot2, $bplot3));
$gbarplot->SetWidth(0.8);
$graph->Add($gbarplot);
// draws the barplots
$bplot1->value->Show();
$bplot2->value->Show();
$bplot3->value->Show();
$bplot1->value->SetFormat('%01d');
$bplot2->value->SetFormat('%01d');
$bplot3->value->SetFormat('%01d');
$bplot1->value->SetFont(FF_ARIAL, FS_BOLD, 10);
$bplot2->value->SetFont(FF_ARIAL, FS_BOLD, 10);
$bplot3->value->SetFont(FF_ARIAL, FS_BOLD, 10);
$bplot1->value->SetAngle(45);
$bplot2->value->SetAngle(45);
$bplot3->value->SetAngle(45);
 /**
  * Runs the phpOpenTracker API call.
  *
  * @param  array $parameters
  * @return mixed
  * @access public
  */
 function run($parameters)
 {
     global $lang, $c;
     $parameters['result_format'] = 'separate_result_arrays';
     // hour or weeday analysis
     $apc = "weekdays";
     if ($parameters['api_call'] == "nxhours") {
         $apc = "hours";
     }
     $apicall = array('api_call' => $apc, 'what' => $parameters["what"], 'start' => $parameters["start"], 'end' => $parameters["end"]);
     $queryValues = phpOpenTracker::get($apicall);
     for ($i = 0; $i < count($queryValues); $i++) {
         $y[$i] = $queryValues[$i]["value"];
     }
     $title = 'Analyse ';
     switch ($parameters['what']) {
         case 'visits':
             $title .= 'Visits';
             break;
         case 'pi':
             $title .= 'Page Impressions';
             break;
         case 'avg_clickstream':
             $title .= 'Average Clickstream';
             break;
         case 'avg_time':
             $title .= 'Average Online Time';
             break;
     }
     if ($apc == "hours") {
         for ($i = 0; $i < 24; $i++) {
             $x_label[$i] = sprintf("%02d", $i);
         }
         $angle = 50;
     } else {
         $x_label = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
         $angle = 30;
     }
     $graph = new Graph($parameters['width'], $parameters['height'], 'auto');
     $graph->img->SetMargin(40, 10, 20, 50);
     $graph->SetScale('textlin');
     $graph->SetMarginColor('white');
     $graph->SetFrame(0);
     $graph->xgrid->Show();
     $plot[0] = new BarPlot($y);
     $plot[0]->SetFillColor(__RED);
     $plot[0]->SetShadow();
     $plot[0]->SetWeight(0);
     $gbarplot = new GroupBarPlot($plot);
     $gbarplot->SetWidth(0.6);
     $graph->add($gbarplot);
     $graph->xaxis->SetTickLabels($x_label);
     if ($c["usettf"]) {
         $graph->xaxis->SetLabelAngle($angle);
     }
     if ($c["usettf"]) {
         $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     if ($c["usettf"]) {
         $graph->xaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     $graph->yaxis->SetColor('black');
     if ($c["usettf"]) {
         $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     if ($c["usettf"]) {
         $graph->yaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     $graph->title->Set($title);
     if ($c["usettf"]) {
         $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     $graph->img->SetAntiAliasing("white");
     $graph->Stroke();
 }
Example #3
0
/**
 * Método que sirve de reemplazo al mecanismo de paloSantoGraph y paloSantoGraphLib
 * para generar gráficos a partir de una clase que devuelve datos.
 *
 * @param   string  $module     Módulo que contiene la clase fuente de datos
 * @param   string  $class      Clase a instanciar para obtener fuente de datos
 * @param   string  $function   Método a llamar en la clase para obtener datos
 * @param   array   $arrParameters  Lista de parámetros para la invocación 
 * @param   string  $functionCB 
 */
function displayGraph($G_MODULE, $G_CLASS, $G_FUNCTION, $G_PARAMETERS, $G_FUNCTIONCB = "")
{
    //------- PARAMETROS DEL GRAPH -------
    $G_TYPE = null;
    //tipo de grafica
    $G_TITLE = null;
    //titulo
    $G_COLOR = null;
    //colores
    $G_LABEL = array();
    //etiquetas
    $G_SIZE = array();
    //tamaño
    $G_MARGIN = array();
    //margen
    $G_LEYEND_NUM_COLUMN = 1;
    $G_LEYEND_POS = array(0.05, 0.5);
    //posicion de las leyendas
    $_MSJ_ERROR = null;
    //$_MSJ_ERROR   = "Sin mensaje ERROR";
    global $_MSJ_NOTHING;
    //$_MSJ_NOTHING = "Sin mensaje NOTHING";
    $G_YDATAS = array();
    $G_ARR_COLOR = array();
    $G_ARR_FILL_COLOR = array();
    $G_ARR_LEYEND = array();
    $G_ARR_STEP = array();
    $G_SHADOW = false;
    $G_LABEL_Y = null;
    //ESTATICOS
    $G_SCALE = "textlin";
    $G_WEIGHT = 1;
    if ($G_MODULE != '') {
        require_once "modules/{$G_MODULE}/libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "modules/{$G_MODULE}/configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConfModule;
        $dsn = isset($arrConfModule["dsn_conn_database"]) ? $arrConfModule["dsn_conn_database"] : "";
    } else {
        require_once "libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConf;
        $dsn = isset($arrConf["dsn_conn_database"]) ? $arrConf["dsn_conn_database"] : "";
    }
    $oPaloClass = new $G_CLASS($dsn);
    $arrParam = $G_PARAMETERS;
    $result = call_user_func_array(array(&$oPaloClass, $G_FUNCTION), $arrParam);
    global $globalCB;
    $globalCB = NULL;
    if ($G_FUNCTIONCB != '') {
        $globalCB = array($oPaloClass, $G_FUNCTIONCB);
    }
    //------------------- CONTRUCCION DEL ARREGLO PARA X & Y -------------------
    global $xData;
    $xData = array();
    $yData = array();
    if (sizeof($result) != 0) {
        $isX_array = false;
        //usado en LINEPLOT, PLOT3D, BARPLOT, LINEPLOT_MULTIAXIS
        foreach ($result as $att => $arrXY) {
            //------------------ ATTRIBUTES ------------------
            if ($att == 'ATTRIBUTES') {
                foreach ($arrXY as $key => $values) {
                    //VARIABLES NECESARIAS
                    if ($key == 'LABEL_X') {
                        $G_LABEL[0] = $values;
                    } else {
                        if ($key == 'LABEL_Y') {
                            $G_LABEL[1] = $values;
                        } else {
                            if ($key == 'TITLE') {
                                $G_TITLE = $values;
                            } else {
                                if ($key == 'TYPE') {
                                    $G_TYPE = $values;
                                } else {
                                    if ($key == 'SIZE') {
                                        $G_SIZE = explode(',', $values);
                                    } else {
                                        if ($key == 'MARGIN') {
                                            $G_MARGIN = explode(',', $values);
                                        } else {
                                            if ($key == 'COLOR') {
                                                $G_COLOR = $values;
                                            } else {
                                                if ($key == 'POS_LEYEND') {
                                                    $G_LEYEND_POS = explode(',', $values);
                                                } else {
                                                    if ($key == 'NUM_COL_LEYEND') {
                                                        $G_LEYEND_NUM_COLUMN = $values;
                                                    } else {
                                                        if ($key == 'SHADOW') {
                                                            $G_SHADOW = $values;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($att == 'MESSAGES') {
                    foreach ($arrXY as $key => $values) {
                        if ($key == 'ERROR') {
                            $_MSJ_ERROR = $values;
                        } else {
                            if ($key == 'NOTHING_SHOW') {
                                $_MSJ_NOTHING = $values;
                            }
                        }
                    }
                } else {
                    if ($att == 'DATA') {
                        foreach ($arrXY as $DAT_N => $MODES) {
                            foreach ($MODES as $key => $values) {
                                /************************************************************/
                                if ($G_TYPE == 'lineplot' || $G_TYPE == 'barplot' || $G_TYPE == 'lineplot_multiaxis') {
                                    if ($key == 'VALUES') {
                                        $yData = array();
                                        foreach ($values as $x => $y) {
                                            if ($isX_array == false) {
                                                $xData[] = $x;
                                            }
                                            $yData[] = $y;
                                        }
                                        $isX_array = is_array($xData) ? true : false;
                                        $G_YDATAS[] = $yData;
                                    } else {
                                        if ($key == 'STYLE') {
                                            foreach ($values as $x => $y) {
                                                if ($x == 'COLOR') {
                                                    $G_ARR_COLOR[] = $y;
                                                } else {
                                                    if ($x == 'LEYEND') {
                                                        $G_ARR_LEYEND[] = $y;
                                                    } else {
                                                        if ($x == 'STYLE_STEP') {
                                                            $G_ARR_STEP[] = $y;
                                                        } else {
                                                            if ($x == 'FILL_COLOR') {
                                                                $G_ARR_FILL_COLOR[] = $y;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if ($G_TYPE == 'plot3d' || $G_TYPE == 'plot3d2') {
                                        if ($key == 'VALUES') {
                                            foreach ($values as $x => $y) {
                                                $yData[] = $y;
                                            }
                                            $G_YDATAS[0] = $yData;
                                        } else {
                                            if ($key == 'STYLE') {
                                                foreach ($values as $x => $y) {
                                                    if ($x == 'COLOR') {
                                                        $G_ARR_COLOR[] = $y;
                                                    } else {
                                                        if ($x == 'LEYEND') {
                                                            $xData[] = $y;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if ($G_TYPE == 'bar' || $G_TYPE == 'gauge') {
                                            if ($key == 'VALUES') {
                                                foreach ($values as $x => $y) {
                                                    $G_YDATAS[] = $y;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //*****************************************//
    //      ***** ***** ***** ***** *   *      //
    //      *     *   * *   * *   * *   *      //
    //      * *** ***** ***** ***** *****      //
    //      *   * * *   *   * *     *   *      //
    //      ***** *   * *   * *     *   *      //
    //*****************************************//
    // L I N E P L O T
    if (sizeof($G_YDATAS) >= 1) {
        // true no funciona porque cada cadena u otro valor que se retorne es valor "valido o verdadero"
        // y equivale a true, entonces para diferenciarlo verdaderamente se compara con 'true'
        $str = checkAttributes($G_TITLE, $G_TYPE, $G_LABEL_Y, $_MSJ_ERROR, $_MSJ_NOTHING);
        if ($str != 'true') {
            showError($str, $G_SIZE);
            return;
        }
        if ($G_TYPE == 'lineplot') {
            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
            if ($G_SHADOW) {
                $graph->SetShadow();
            }
            $graph->SetScale($G_SCALE);
            $graph->SetMarginColor($G_COLOR);
            $graph->title->Set($G_TITLE);
            $graph->SetFrame(true, '#999999');
            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
            $graph->img->SetAntiAliasing();
            $graph->xaxis->SetLabelFormatCallback("CallBack");
            $graph->xaxis->SetLabelAngle(90);
            $graph->xaxis->title->Set($G_LABEL[0]);
            $graph->yaxis->title->Set($G_LABEL[1]);
            $graph->xgrid->Show();
            $graph->legend->SetFillColor("#fafafa");
            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
            $graph->legend->SetColor("#444444", "#999999");
            $arr_lineplot = array();
            foreach ($G_YDATAS as $num => $yDatas) {
                $lineplot = new LinePlot($yDatas);
                if ($G_ARR_STEP[$num] == true) {
                    $lineplot->SetStepStyle();
                }
                if ($G_ARR_FILL_COLOR[$num] == true) {
                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                }
                $lineplot->SetColor($G_ARR_COLOR[$num]);
                $lineplot->SetWeight($G_WEIGHT);
                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                $arr_lineplot[] = $lineplot;
            }
            foreach ($arr_lineplot as $num => $yDatas) {
                $graph->Add($yDatas);
            }
            if (sizeof($xData) > 100) {
                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
            }
            $graph->Stroke();
        } else {
            if ($G_TYPE == 'plot3d') {
                $graph = new PieGraph($G_SIZE[0], $G_SIZE[1], "auto");
                if ($G_SHADOW) {
                    $graph->SetShadow();
                }
                $dataMarginColor = isset($result["ATTRIBUTES"]["MARGIN_COLOR"]) ? $result["ATTRIBUTES"]["MARGIN_COLOR"] : "#999999";
                $dataSizePie = isset($result["ATTRIBUTES"]["SIZE_PIE"]) ? $result["ATTRIBUTES"]["SIZE_PIE"] : "80";
                $graph->SetMarginColor($G_COLOR);
                $graph->SetFrame(true, $dataMarginColor);
                $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                $graph->legend->SetFillColor("#fafafa");
                $graph->legend->SetColor("#444444", "#999999");
                $graph->legend->SetShadow('gray@0.6', 4);
                $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                $graph->title->Set($G_TITLE);
                $pieplot3d = new PiePlot3d($G_YDATAS[0]);
                $pieplot3d->SetSliceColors($G_ARR_COLOR);
                $pieplot3d->SetCenter(0.4);
                $pieplot3d->SetSize($dataSizePie);
                $pieplot3d->SetAngle(45);
                $pieplot3d->SetStartAngle(45);
                $pieplot3d->value->SetColor('black');
                //color a los porcentages
                $pieplot3d->SetEdge('black');
                //da color al contorno y separacion del pastel
                $pieplot3d->SetLegends($xData);
                $graph->Add($pieplot3d);
                $graph->Stroke();
            } else {
                if ($G_TYPE == 'plot3d2') {
                    if (!function_exists('displayGraph_draw_pie3d')) {
                        function displayGraph_draw_pie3d($canvasx, $ydata, $arrcolor)
                        {
                            $canvasy = $canvasx;
                            $escala = $canvasx / 320.0;
                            $iAnchoPastel = 256 * $escala;
                            $iAltoPastel = 155 * $escala;
                            $iPosCentroX = 141 * $escala;
                            $iPosCentroY = 91 * $escala;
                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasy * 250 / 320);
                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                            imagefill($thumb, 0, 0, $transparent);
                            // Asignar colores de imagen
                            $imgcolor = array();
                            foreach ($arrcolor as $i => $sHtmlColor) {
                                $r = $g = $b = 0;
                                sscanf($sHtmlColor, "#%02x%02x%02x", $r, $g, $b);
                                $imgcolor[$i] = imagecolorallocate($thumb, $r, $g, $b);
                            }
                            $colorTexto = imagecolorallocate($thumb, 0, 0, 0);
                            // Mostrar el gráfico de pastel
                            if (!function_exists('displayGraph_pie')) {
                                function displayGraph_pie($thumb, $x, $y, $w, $h, $ydata, $G_ARR_COLOR, $colorTexto)
                                {
                                    $iTotal = array_sum($ydata);
                                    $iFraccion = 0;
                                    $etiquetas = array();
                                    for ($i = 0; $i < count($ydata); $i++) {
                                        if ($ydata[$i] >= $iTotal) {
                                            imagefilledellipse($thumb, $x, $y, $w, $h, $G_ARR_COLOR[$i]);
                                        } else {
                                            $degInicio = 360 - 45 - (int) (360.0 * ($iFraccion + $ydata[$i]) / $iTotal);
                                            $degFinal = 360 - 45 - (int) (360.0 * $iFraccion / $iTotal);
                                            imagefilledarc($thumb, $x, $y, $w, $h, $degInicio, $degFinal, $G_ARR_COLOR[$i], IMG_ARC_PIE);
                                        }
                                        $iFraccion += $ydata[$i];
                                        $degMitad = ($degInicio + $degFinal) / 2;
                                        $iPosTextoX = $x + 0.5 * ($w / 2.0) * cos(deg2rad($degMitad));
                                        $iPosTextoY = $y + 0.5 * ($h / 2.0) * sin(deg2rad($degMitad));
                                        $etiquetas[] = array($iPosTextoX, $iPosTextoY, sprintf('%.1f %%', 100.0 * $ydata[$i] / $iTotal));
                                    }
                                    /*
                                                            if (!is_null($colorTexto)) {
                                                                for ($i = 0; $i < count($ydata); $i++)
                                                                    imagestring($thumb, 5, $etiquetas[$i][0], $etiquetas[$i][1], $etiquetas[$i][2], $colorTexto);
                                                            }
                                    */
                                }
                            }
                            for ($i = (int) (60 * $escala); $i > 0; $i--) {
                                displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY + $i, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, NULL);
                            }
                            displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, $colorTexto);
                            imagealphablending($thumb, true);
                            imagesavealpha($thumb, true);
                            $source2 = imagecreatefrompng("images/pie_alpha.png");
                            imagealphablending($source2, true);
                            imagecopyresampled($thumb, $source2, 0, 0, 0, 0, 290 * $escala, 294 * $escala, 290, 294);
                            header("Content-Type: image/png");
                            imagepng($thumb);
                        }
                    }
                    displayGraph_draw_pie3d($G_SIZE[0], $G_YDATAS[0], $G_ARR_COLOR);
                } else {
                    if ($G_TYPE == 'barplot') {
                        $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                        if ($G_SHADOW) {
                            $graph->SetShadow();
                        }
                        $graph->SetScale($G_SCALE);
                        $graph->SetMarginColor($G_COLOR);
                        $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                        $graph->title->Set($G_TITLE);
                        $graph->xaxis->title->Set($G_LABEL[0]);
                        $graph->xaxis->SetLabelFormatCallback("CallBack");
                        $graph->xaxis->SetLabelAngle(90);
                        //$graph->xaxis->SetTickLabels($xData);
                        $graph->yaxis->title->Set($G_LABEL[1]);
                        $graph->legend->SetFillColor("#fafafa");
                        $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                        $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                        $arr_barplot = array();
                        foreach ($G_YDATAS as $num => $yDatas) {
                            $barplot = new BarPlot($yDatas);
                            $barplot->SetFillColor($G_ARR_COLOR[$num]);
                            $barplot->SetLegend($G_ARR_LEYEND[$num]);
                            $arr_barplot[] = $barplot;
                        }
                        $gbarplot = new GroupBarPlot($arr_barplot);
                        $gbarplot->SetWidth(0.6);
                        $graph->Add($gbarplot);
                        $graph->Stroke();
                    } else {
                        if ($G_TYPE == 'lineplot_multiaxis') {
                            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                            if ($G_SHADOW) {
                                $graph->SetShadow();
                            }
                            $inc = sizeof($G_YDATAS);
                            $graph->SetScale($G_SCALE);
                            $graph->SetFrame(true, '#999999');
                            $graph->title->Set($G_TITLE);
                            $graph->img->SetAntiAliasing();
                            $graph->xaxis->SetLabelFormatCallback("CallBack");
                            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                            $graph->SetMarginColor($G_COLOR);
                            $graph->legend->SetFillColor("#fafafa");
                            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                            $graph->xaxis->SetLabelAngle(90);
                            $graph->legend->SetColor("#444444", "#999999");
                            $graph->legend->SetShadow('gray@0.6', 4);
                            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                            foreach ($G_YDATAS as $num => $yData) {
                                $lineplot = new LinePlot($yData);
                                $lineplot->SetWeight($G_WEIGHT);
                                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                                if ($G_ARR_STEP[$num] == true) {
                                    $lineplot->SetStepStyle();
                                }
                                if ($G_ARR_FILL_COLOR[$num] == true) {
                                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                                }
                                if ($num == 0) {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->yaxis->SetColor($G_ARR_COLOR[$num]);
                                    $graph->Add($lineplot);
                                } else {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->SetYScale($num - 1, 'lin');
                                    $graph->ynaxis[$num - 1]->SetColor($G_ARR_COLOR[$num]);
                                    $graph->ynaxis[$num - 1]->SetPosAbsDelta($G_MARGIN[1] + 49 * ($num - 1));
                                    //mueve el eje Y
                                    $graph->AddY($num - 1, $lineplot);
                                }
                            }
                            if (sizeof($xData) > 100) {
                                //$graph->xaxis->SetTextLabelInterval( (int)(sizeof($xData)/8) );
                                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
                                //$graph->xaxis->SetTextTickInterval( 9*(int)(log(sizeof($xData))-1) );
                            }
                            $graph->Stroke();
                        } else {
                            if ($G_TYPE == 'bar') {
                                $g = new CanvasGraph(91, 21, 'auto');
                                $g->SetMargin(0, 0, 0, 0);
                                $g->InitFrame();
                                $xmax = 20;
                                $ymax = 20;
                                $scale = new CanvasScale($g);
                                $scale->Set(0, $G_SIZE[0], 0, $G_SIZE[1]);
                                //DUBUJA LA BARRA
                                $alto = $G_SIZE[1];
                                $ancho = $G_SIZE[0];
                                $coor_x = 0;
                                $coor_y = 0;
                                $porcentage = $G_YDATAS[0];
                                $valor = 90 * (1 - $porcentage);
                                $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                for ($i = 0; $i < $alto; $i++) {
                                    $g->img->SetColor(array(95 - 3 * $i, 138 - 3 * $i, 203 - 3 * $i));
                                    //para hacerlo 3D, degradacion
                                    $g->img->Line($coor_x, $coor_y + $i + 1, $coor_x + $ancho - $valor - 1, $coor_y + $i + 1);
                                }
                                $g->Stroke();
                            } else {
                                if ($G_TYPE == 'gauge') {
                                    if (!function_exists('displayGraph_draw_gauge')) {
                                        function displayGraph_draw_gauge($canvasx, $percent)
                                        {
                                            $escala = $canvasx / 320.0;
                                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasx * 284 / 320);
                                            if ($percent > 100) {
                                                $percent = 100.0;
                                            }
                                            if ($percent < 0) {
                                                $percent = 0.0;
                                            }
                                            $angle = -135.0 + 270 * $percent / 100.0;
                                            // COLORES
                                            $blanco = imagecolorallocate($thumb, 255, 255, 255);
                                            $dred = imagecolorallocate($thumb, 180, 0, 0);
                                            $lred = imagecolorallocate($thumb, 100, 0, 0);
                                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                                            imagefill($thumb, 0, 0, $transparent);
                                            imagealphablending($thumb, true);
                                            imagesavealpha($thumb, true);
                                            $source = imagecreatefrompng("images/gauge_base.png");
                                            imagealphablending($source, true);
                                            imagecopyresampled($thumb, $source, 0, 0, 0, 0, 285 * $escala, 285 * $escala, 285, 285);
                                            $radius = 100 * $escala;
                                            $radius_min = 12 * $escala;
                                            $centrox = 142 * $escala;
                                            $centroy = 141 * $escala;
                                            $x1 = $centrox + sin(deg2rad($angle)) * $radius;
                                            // x coord farest
                                            $x2 = $centrox + sin(deg2rad($angle - 90)) * $radius_min;
                                            $x3 = $centrox + sin(deg2rad($angle + 90)) * $radius_min;
                                            $y1 = $centroy - cos(deg2rad($angle)) * $radius;
                                            $y2 = $centroy - cos(deg2rad($angle - 90)) * $radius_min;
                                            $y3 = $centroy - cos(deg2rad($angle + 90)) * $radius_min;
                                            $arrTriangle1 = array($centrox, $centroy, $x1, $y1, $x2, $y2);
                                            $arrTriangle2 = array($centrox, $centroy, $x1, $y1, $x3, $y3);
                                            imagefilledpolygon($thumb, $arrTriangle1, 3, $lred);
                                            imagefilledpolygon($thumb, $arrTriangle2, 3, $dred);
                                            $source2 = imagecreatefrompng("images/gauge_center.png");
                                            imagealphablending($source2, true);
                                            imagecopyresampled($thumb, $source2, 121 * $escala, 120 * $escala, 0, 0, 44 * $escala, 44 * $escala, 44, 44);
                                            header("Content-Type: image/png");
                                            imagepng($thumb);
                                        }
                                    }
                                    displayGraph_draw_gauge($G_SIZE[0], $G_YDATAS[0] * 100.0);
                                } else {
                                    if ($G_TYPE == 'bar2') {
                                        $alto = 20;
                                        $ancho = 90;
                                        $coor_x = 100;
                                        $coor_y = 10;
                                        $porcentage = 0.67;
                                        $valor = 90 * (1 - $porcentage);
                                        $g = new CanvasGraph($G_LEN_X, 40, 'auto');
                                        $g->SetMargin(1, 1, 31, 9);
                                        $g->SetMarginColor('#fafafa');
                                        $g->SetColor(array(250, 250, 250));
                                        $g->InitFrame();
                                        $xmax = 20;
                                        $ymax = 20;
                                        $scale = new CanvasScale($g);
                                        $scale->Set(0, $G_LEN_X, 0, $G_LEN_Y);
                                        //DUBUJA LA BARRA
                                        $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                        $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                        $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                        $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                        for ($i = 0; $i < $alto; $i++) {
                                            $g->img->SetColor(array(95 - 4 * $i, 138 - 4 * $i, 203 - 4 * $i));
                                            //para hacerlo 3D, degradacion
                                            $g->img->Line($coor_x, $coor_y + $i, $coor_x + $ancho - $valor - 1, $coor_y + $i);
                                        }
                                        //AGREGA LABEL 1
                                        $txt = "Uso de CPU";
                                        $t = new Text($txt, 10, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        //AGREGA LABEL 2
                                        $txt = "67.64% used of 2,200.00 MHz";
                                        $t = new Text($txt, 200, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        $g->Stroke();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        showError('nothing', $G_SIZE, $G_TITLE);
    }
}
 function buildGraphic($stats)
 {
     $stat = $stats->getRequests();
     foreach ($stat as $s) {
         $mes = intval($s->getMonth());
         $ano = intval($s->getYear());
         $values[$ano][$mes] = $s->getNumberOfRequests();
     }
     /*
     "gabarito" da linha dos graficos com 12 posicoes, uma para cada mes
     os valores "-" sao considerados NULLs pelo jpgraph
     */
     $data = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
     /*
     "gabarito" para as cores das linhas do gráfico
     */
     $cores = array("blue", "yellow", "purple", "cyan", "pink", "red", "orange", "green", "black", "sienna", "darkred", "darkgreen");
     // Create the graph. These two calls are always required
     //			$graph = new Graph(700,400,"auto");
     $graph = new Graph(900, 300, "auto");
     $graph->SetScale("textlin");
     /*
     cira um array bi-dimencional contendo array(ano{array com a quantidade de acessos por mes})
     */
     $colorIndex = 0;
     $bars = array();
     foreach ($values as $ano => $meses) {
         /*
         valores será a variavel que servirá de "datasource" para a barra do grafico
         inicialmente ele eh inicializada com o gabarito, e serao preenchidos os valores
         dos meses no laço for logo abaixo
         */
         $valores = $data;
         for ($k = 0; $k <= count($valores); $k++) {
             if ($meses[$k]) {
                 $valores[$k] = $meses[$k];
             }
         }
         if (count($valores) > 12) {
             unset($valores[0]);
         }
         $valores = array_values($valores);
         /*
         aqui eu uso "Variáveis Variáveis" do PHP para poder
         inserir vária linhas no gráfico
         */
         $nome = "barplot" . $ano;
         ${$nome} = new BarPlot($valores);
         $cor = $cores[$colorIndex];
         ${$nome}->SetFillColor($cor);
         ${$nome}->SetColor($cor);
         /*configs para os valores do ponto*/
         ${$nome}->value->SetColor("darkred");
         ${$nome}->value->SetFont(FF_FONT1, FS_BOLD);
         ${$nome}->value->SetFormat("%0.1d");
         //				$$nome->SetWeight(20);
         //				$$nome->SetWidth(20);
         ${$nome}->value->Show();
         ${$nome}->value->iHideZero = true;
         ${$nome}->setLegend($ano);
         /*adicionando a linha ao grafico*/
         $colorIndex++;
         array_push($bars, ${$nome});
     }
     $gbplot = new GroupBarPlot($bars);
     $gbplot->SetWidth(0.9);
     $graph->Add($gbplot);
     $graph->yaxis->scale->SetGrace(20);
     $graph->img->SetMargin(40, 20, 20, 40);
     $graph->title->Set(ARTICLE_ACCESS);
     $graph->xaxis->title->Set(MONTHS);
     $graph->yaxis->title->Set(ACCESSES);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->SetShadow();
     $graph->xaxis->SetTickLabels(explode(",", MONTH_LIST));
     // Adjust the legend position
     //			$graph->legend->SetLayout(LEGEND_VER);
     $graph->legend->Pos(0.04, 0.092, "", "center");
     $graph->legend->SetLayout(LEGEND_HOR);
     // Display the graph
     $graph->Stroke();
 }
Example #5
0
$graph->yaxis->SetTitle("Precipitation (in)");
$graph->title->Set($cities[$station]["name"] . " [{$station}] Precipitation for " . date("M Y", $ts));
if ($hasclimate) {
    $graph->subtitle->Set("Climate Site: " . $cities[strtoupper($climate_site)]["name"] . "[" . $climate_site . "]");
}
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->Pos(0.05, 0.1, "right", "top");
if ($hasclimate && sizeof($cdiff) > 0) {
    // Create the linear plot
    $b1plot = new BarPlot($cdiff);
    $b1plot->SetFillColor("red");
    $b1plot->SetLegend("Accum Difference");
    $b2plot = new BarPlot($obs);
    $b2plot->SetFillColor("blue");
    $b2plot->SetLegend("Obs Rain");
    $g = new GroupBarPlot(array($b1plot, $b2plot));
    $g->SetAlign("left");
}
// Create the linear plot
$lp1 = new LinePlot($aobs);
$lp1->SetLegend("Actual Accum");
$lp1->SetColor("blue");
$lp1->SetWeight(2);
if ($hasclimate && sizeof($cdiff) > 0) {
    $lp2 = new LinePlot($aclimate);
    $lp2->SetLegend("Climate Accum");
    $lp2->SetColor("red");
    $lp2->SetWeight(2);
    $z = new LinePlot($zeros);
    $z->SetWeight(2);
}
Example #6
0
<?php

include "../jpgraph.php";
include "../jpgraph_bar.php";
$data1y = array(12, 8, 19, 3, 10, 5);
$data2y = array(8, 2, 11, 7, 14, 4);
// Create the graph. These two calls are always required
$graph = new Graph(310, 200, "auto");
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40, 30, 20, 40);
// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot, $b2plot));
$gbplot->SetWidth(0.9);
// ...and add it to the graPH
$graph->Add($gbplot);
$graph->title->Set("Adjusting the width");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
// Display the graph
$graph->Stroke();
 /**
  * Runs the phpOpenTracker API call.
  *
  * @param  array $parameters
  * @return mixed
  * @access public
  */
 function run($parameters)
 {
     global $c;
     $parameters['interval'] = isset($parameters['interval']) ? $parameters['interval'] : false;
     $parameters['month_names'] = isset($parameters['month_names']) ? $parameters['month_names'] : false;
     if (!$parameters['month_names']) {
         $parameters['month_names'] = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
     }
     $timestamp = time();
     $steps = array('hour' => 3600, 'day' => 86400, 'week' => 604800, 'month' => 2592000, 'year' => 31536000);
     $starttitle = '';
     $endtitle = '';
     switch ($parameters['interval']) {
         case 'hour':
             $starthour = $hour = date('H', $parameters['start']);
             $endhour = date('H', $parameters['end']);
             $starttitle .= $starthour . ':00h  ';
             $endtitle .= $endhour . ':59h  ';
         case 'day':
             $startday = $day = date('d', $parameters['start']);
             $endday = date('d', $parameters['end']);
             $starttitle .= $startday . '. ';
             $endtitle .= $endday . '. ';
         case 'week':
             $week = date('W', $parameters['start']) + 2;
         case 'month':
             $startmonth = $month = date('m', $parameters['start']);
             $endmonth = date('m', $parameters['end']);
             $starttitle .= $parameters['month_names'][$startmonth - 1] . ' ';
             $endtitle .= $parameters['month_names'][$endmonth - 1] . ' ';
         case 'year':
             $startyear = $year = date('Y', $parameters['start']);
             $endyear = date('Y', $parameters['end']);
             $starttitle .= $startyear;
             $endtitle .= $endyear;
     }
     $title = $starttitle . '   -   ' . $endtitle . ' in ' . $parameters['interval'] . "s.";
     $disp = true;
     $correct = 0;
     if ($parameters['interval'] == 'week') {
         $correct = 86400;
     }
     for ($start = $parameters['start']; $start < $parameters['end']; $start += $steps[$parameters['interval']]) {
         if ($parameters['interval'] == 'month') {
             $steps['month'] = $steps['day'] * date('t', $_start);
         }
         $end = $start + $steps[$parameters['interval']] - 1;
         if ($start <= $timestamp) {
             $apiCallParameters = array('client_id' => $parameters['client_id'], 'start' => $start + $correct, 'end' => $end + $correct, 'constraints' => $parameters['constraints'], 'interval' => '');
             for ($j = 0; $j < count($parameters["what"]); $j++) {
                 $y[$j][] = phpOpenTracker::get(array_merge(array('api_call' => $parameters["what"][$j]), $apiCallParameters));
             }
         } else {
             for ($j = 0; $j < count($parameters["what"]); $j++) {
                 $y[$j][] = 0;
             }
         }
         switch ($parameters['interval']) {
             case 'hour':
                 $x_label[] = date('H', mktime($hour, 0, 0, $startmonth, $startday, $startyear)) . ':00';
                 $disp = !$disp;
                 $hour++;
                 break;
             case 'week':
                 $x_label[] = date('W', mktime(0, 0, 0, 1, ($week - 2) * 7, $startyear));
                 $week++;
                 break;
             case 'day':
                 $x_label[] = date('d', mktime(0, 0, 0, $startmonth, $day, $startyear));
                 $day++;
                 break;
             case 'month':
                 $x_label[] = date('m', mktime(0, 0, 0, $month, 1, $startyear));
                 $month++;
                 break;
             case 'year':
                 $x_label[] = date('Y', mktime(0, 0, 0, 1, 1, $year));
                 $year++;
                 break;
         }
     }
     if ($y == null) {
         $apiCallParameters = array('client_id' => $parameters['client_id'], 'start' => $start, 'end' => $end, 'constraints' => $parameters['constraints']);
         for ($j = 0; $j < count($parameters["what"]); $j++) {
             $y[$j][] = phpOpenTracker::get(array_merge(array('api_call' => $parameters["what"][$j]), $apiCallParameters));
         }
         $x_label[] = '';
         $title = "Total";
     }
     if ($parameters['interval'] == 'hour') {
         $angle = 50;
     } else {
         $angle = 0;
     }
     $x_label = $this->clearLabels($x_label, $parameters);
     $graph = new Graph($parameters['width'], $parameters['height'], 'auto');
     $graph->img->SetMargin(40, 10, 20, 10);
     $graph->SetScale('textlin');
     $graph->SetMarginColor('white');
     $graph->SetFrame(0);
     $graph->xgrid->Show();
     for ($j = 0; $j < count($parameters["what"]); $j++) {
         $plot[$j] = new BarPlot($y[$j]);
         $plot[$j]->SetFillColor($parameters["whatcolors"][$j]);
         $plot[$j]->SetShadow();
         $plot[$j]->SetWeight(0);
     }
     $gbarplot = new GroupBarPlot($plot);
     $gbarplot->SetWidth(0.6);
     $graph->add($gbarplot);
     $graph->xaxis->SetTickLabels($x_label);
     if ($c["usettf"]) {
         $graph->xaxis->SetLabelAngle($angle);
     }
     if ($c["usettf"]) {
         $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     if ($c["usettf"]) {
         $graph->xaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     $graph->yaxis->SetColor('black');
     if ($c["usettf"]) {
         $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     if ($c["usettf"]) {
         $graph->yaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     $graph->title->Set($title);
     if ($c["usettf"]) {
         $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
     }
     $graph->img->SetAntiAliasing("white");
     $graph->Stroke();
 }
Example #8
0
$graph->title->Set("Monthly Rainfall Climatology for " . $cities[strtoupper($station)]['name']);
$subt = sprintf("Annual precip of %.2f inches over %.0f days", array_sum($climate), array_sum($days));
$graph->subtitle->Set($subt);
$graph->title->SetFont(FF_FONT1, FS_BOLD, 16);
$graph->yaxis->SetTitle("Precipitation [inches]");
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD, 12);
$graph->yaxis->SetTitleMargin(35);
$graph->yaxis->title->SetColor("blue");
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD, 12);
$graph->xaxis->SetPos("min");
$graph->xaxis->SetTitleMargin(15);
$graph->legend->Pos(0.2, 0.09);
$graph->legend->SetLayout(LEGEND_HOR);
// Create the linear plot
$bp0 = new BarPlot($climate);
$bp0->SetFillColor("blue");
$bp1 = new BarPlot($days);
$bp1->SetFillColor("red");
$z = new BarPlot($zeros);
$z->SetFillColor("red");
$gbplot = new GroupBarPlot(array($bp0, $z));
$gbplot->SetWidth(0.6);
$graph->Add($gbplot);
$gbplot2 = new GroupBarPlot(array($z, $bp1));
$gbplot2->SetWidth(0.6);
$graph->AddY2($gbplot2);
// Display the graph
$graph->Stroke();
?>

	$bplot2->value->Show();
	$bplot3->value->Show();
	$bplot4->value->Show();
	$bplot5->value->Show();
	$bplot6->value->Show();
	$bplot7->value->Show();*/
$bplot1->value->SetFont(FF_FONT0);
$bplot2->value->SetFont(FF_FONT0);
$bplot3->value->SetFont(FF_FONT0);
$bplot4->value->SetFont(FF_FONT0);
$bplot5->value->SetFont(FF_FONT0);
$bplot6->value->SetFont(FF_FONT0);
$bplot7->value->SetFont(FF_FONT0);
$bplot1->value->SetColor('black', 'darkred');
$bplot2->value->SetColor('black', 'darkred');
$bplot3->value->SetColor('black', 'darkred');
$bplot4->value->SetColor('black', 'darkred');
$bplot5->value->SetColor('black', 'darkred');
$bplot6->value->SetColor('black', 'darkred');
$bplot7->value->SetColor('black', 'darkred');
$bplot1->value->SetFormat('%d');
$bplot2->value->SetFormat('%d');
$bplot3->value->SetFormat('%d');
$bplot4->value->SetFormat('%d');
$bplot5->value->SetFormat('%d');
$bplot6->value->SetFormat('%d');
$bplot7->value->SetFormat('%d');
$gbarplot = new GroupBarPlot(array($bplot1, $bplot2, $bplot3, $bplot4, $bplot5, $bplot6, $bplot7));
$gbarplot->SetWidth(1.0);
$graph->Add($gbarplot);
$graph->Stroke();
 /** Constroi o gráfico entre periodos de anos 
 			retorna true se o grafico foi montado e false se não foi
 		**/
 function buildGraphicByYear($stats, $startYear, $lastYear)
 {
     $graficoStatus = false;
     // Para descobrir se entrou no for e vai construir um gráfico
     $stat = $stats->getRequests();
     // Pega todos os anos entre o Ano Inicial e o Ano Final
     $anos = array();
     for ($j = 0, $year = $startYear; $year <= $lastYear; $year++, $j++) {
         $anos[$j] = $year;
     }
     foreach ($stat as $s) {
         $mes = intval($s->getMonth());
         $ano = intval($s->getYear());
         $values[$ano][$mes] = $s->getNumberOfRequests();
     }
     /*
     "gabarito" da linha dos graficos com 12 posicoes, uma para cada mes
     os valores "-" sao considerados NULLs pelo jpgraph
     */
     $data = array("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
     /*
     "gabarito" para as cores das linhas do gráfico
     */
     $cores = array("blue", "yellow", "purple", "cyan", "pink", "red", "orange", "green", "black", "sienna", "darkred", "darkgreen");
     // Create the graph. These two calls are always required
     //			$graph = new Graph(700,400,"auto");
     $graph = new Graph(900, 300, "auto");
     $graph->SetScale("textlin");
     /*
     cria um array bi-dimencional contendo array(ano{array com a quantidade de acessos por mes})
     */
     $colorIndex = 0;
     $bars = array();
     foreach ($values as $ano => $meses) {
         /*
         valores será a variavel que servirá de "datasource" para a barra do grafico
         inicialmente ele eh inicializada com o gabarito, e serao preenchidos os valores
         dos meses no laço for logo abaixo
         */
         $valores = $data;
         for ($k = 0; $k <= count($valores); $k++) {
             if ($meses[$k]) {
                 $valores[$k] = $meses[$k];
             }
         }
         if (count($valores) > 12) {
             unset($valores[0]);
         }
         $valores = array_values($valores);
         /*
         aqui eu uso "Variáveis Variáveis" do PHP para poder
         inserir vária linhas no gráfico
         */
         $nome = "barplot" . $ano;
         ${$nome} = new BarPlot($valores);
         $cor = $cores[$colorIndex];
         ${$nome}->SetFillColor($cor);
         ${$nome}->SetColor($cor);
         /*configs para os valores do ponto*/
         ${$nome}->value->SetColor("darkred");
         ${$nome}->value->SetFont(FF_FONT1, FS_BOLD);
         ${$nome}->value->SetFormat("%0.1d");
         //				$$nome->SetWeight(20);
         // Arrumando para um tamanho mais amigavel
         if (count($anos) < 3) {
             ${$nome}->SetWidth(20);
         } else {
             if (count($anos) < 4) {
                 ${$nome}->SetWidth(15);
             } else {
                 if (count($anos) < 6) {
                     ${$nome}->SetWidth(10);
                 } else {
                     if (count($anos) < 8) {
                         ${$nome}->SetWidth(5);
                     } else {
                         if (count($anos) < 11) {
                             ${$nome}->SetWidth(3);
                         }
                     }
                 }
             }
         }
         ${$nome}->value->Show();
         ${$nome}->value->iHideZero = true;
         ${$nome}->setLegend($ano);
         /*adicionando a linha ao grafico*/
         $colorIndex++;
         // Somente monta o gráfico dos anos exigidos pelo usuário
         for ($i = 0; $i < count($anos); $i++) {
             if ($ano == $startYear + $i) {
                 $graficoStatus = true;
                 // entrou no for significa que o gráfico vai ser construido
                 array_push($bars, ${$nome});
             }
         }
     }
     /****************************************************************
      * Se não existir dados estatísticos para o período selecionado	*
      * Então ele constroi uma imagem com a mensagem de que não		*
      * existem dados estatísticos.									*
      *****************************************************************/
     if ($graficoStatus == false) {
         $graph = new CanvasGraph(600, 30);
         $t1 = new Text(GRAFIC_STATS_FALSE);
         $t1->Pos(0.05, 0.5);
         $t1->SetOrientation('h');
         $t1->SetFont(FF_FONT1, FS_BOLD);
         $t1->SetColor('black');
         $graph->AddText($t1);
         $graph->Stroke();
         return $graficoStatus;
     }
     $gbplot = new GroupBarPlot($bars);
     $gbplot->SetWidth(0.9);
     $graph->Add($gbplot);
     $graph->yaxis->scale->SetGrace(20);
     $graph->img->SetMargin(40, 20, 20, 40);
     $graph->title->Set(ARTICLE_ACCESS);
     $graph->xaxis->title->Set(MONTHS);
     $graph->yaxis->title->Set(ACCESSES);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->SetShadow();
     $graph->xaxis->SetTickLabels(explode(",", MONTH_LIST));
     // Adjust the legend position
     //			$graph->legend->SetLayout(LEGEND_VER);
     $graph->legend->Pos(0.04, 0.092, "", "center");
     $graph->legend->SetLayout(LEGEND_HOR);
     // Mostra o gráfico somente se, o ano que o usuario entrou existir estatisticas
     if ($graficoStatus == true) {
         $graph->Stroke();
     }
     return $graficoStatus;
 }
Example #11
0
 private function createBarGraph()
 {
     // Create the graph.
     $graph = new Graph($this->width, $this->height, "auto");
     $graph->SetScale("textlin");
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->SetFrame(false);
     // ... and add it to the graph
     //$graph->xaxis->title->Set(Prado::localize('title'));
     //$graph->xaxis->SetTickLabels($this->xdata);
     //$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     // First make the labels look right
     $graph->yaxis->SetLabelFormat('%d');
     $graph->yaxis->SetLabelSide(SIDE_LEFT);
     $graph->yaxis->SetLabelMargin(5);
     $graph->yaxis->scale->SetGrace(0.1);
     $graph->yaxis->HideZeroLabel();
     $graph->ygrid->SetFill(true, '#f2f2f2@0.5', '#cacaca@0.5');
     if ($this->shadow) {
         $graph->SetShadow();
     }
     // Create the bar plot
     $tmpArray = array();
     if ($this->numberdimensions > 1) {
         for ($ii = 1; $ii <= $this->numberpivots; $ii++) {
             for ($jj = 0; $jj < $this->numberchildren; $jj++) {
                 ${'tmpArray' . $ii . $jj} = array();
                 /*${'bplot'.$jj} = new BarPlot($this->ydata[$ii][$jj]);
                   ${'bplot'.$jj}->SetFillColor($this->colorarray[$jj]);
                   ${'bplot'.$jj}->value->Show();
                   ${'bplot'.$jj}->value->SetFormat('%d');
                   ${'bplot'.$jj}->value->SetColor("black");
                   ${'bplot'.$jj}->SetValuePos('top');
                   array_push(${'tmpArray'.$ii},${'bplot'.$jj});*/
                 array_push(${'tmpArray' . $ii . $jj}, $this->ydata[$ii][$jj]);
                 ${'bplot' . $ii . $jj} = new BarPlot(${'tmpArray' . $ii . $jj});
                 ${'bplot' . $ii . $jj}->SetFillColor($this->colorarray[$jj]);
                 ${'bplot' . $ii . $jj}->value->Show();
                 ${'bplot' . $ii . $jj}->value->SetFormat('%d');
                 ${'bplot' . $ii . $jj}->value->SetColor("black");
                 ${'bplot' . $ii . $jj}->SetValuePos('top');
                 //array_push($tmpArray,${'tmpArray'.$ii});
                 array_push($tmpArray, ${'bplot' . $ii . $jj});
             }
         }
         $gbplot = new GroupBarPlot($tmpArray);
         $gbplot->setWidth(0.9);
         $gbplot->SetLegend(Prado::localize($this->legend));
         $graph->Add($gbplot);
     } else {
         $tmpArray = array();
         for ($ii = 0; $ii < $this->numberpivots; $ii++) {
             array_push($tmpArray, $this->ydata[1][$ii]);
         }
         $bplot = new BarPlot($tmpArray);
         $bplot->value->Show();
         $bplot->value->SetFormat('%d');
         $bplot->value->SetColor("black");
         $bplot->SetValuePos('center');
         $bplot->SetWidth(0.8);
         $bplot->SetLegend(Prado::localize($this->legend));
         $graph->Add($bplot);
     }
     return $graph;
 }
Example #12
0
function getChart($exec_arr, $auto_arr, $user_arr, $testplan_name)
{
    $data1y = $exec_arr;
    $data2y = $auto_arr;
    // Create the graph. These two calls are always required
    $graph = new Graph(1500, 300, 'auto');
    $graph->SetScale("textlin");
    $theme_class = new UniversalTheme();
    $graph->SetTheme($theme_class);
    $graph->yaxis->SetTickPositions(array(20, 40, 60, 80, 100), array(10, 30, 50, 70, 90));
    $graph->SetBox(false);
    $graph->ygrid->SetFill(false);
    $graph->xaxis->SetTickLabels($user_arr);
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false, false);
    // Create the bar plots
    $b1plot = new BarPlot($data1y);
    $b2plot = new BarPlot($data2y);
    // Create the grouped bar plot
    $gbplot = new GroupBarPlot(array($b1plot, $b2plot));
    $gbplot->SetWidth(0.3);
    // ...and add it to the graPH
    $graph->Add($gbplot);
    $b1plot->SetColor("white");
    $b1plot->SetFillColor("red");
    $b1plot->SetAbsWidth(10);
    $b1plot->SetLegend("Executed");
    $b2plot->SetColor("white");
    $b2plot->SetFillColor("green");
    $b2plot->SetAbsWidth(10);
    $b2plot->SetLegend("Automated");
    $graph->title->Set("Execution Status of {$testplan_name}");
    $graph->yaxis->title->Set("value in %");
    // Display the graph
    //$graph->Stroke();
    $graph->img->SetImgFormat('jpeg');
    $fileName = "execution.jpeg";
    $graph->Stroke($fileName);
    return $fileName;
}