<?php

// content="text/plain; charset=utf-8"
// Gantt example
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_gantt.php';
//
// The data for the graphs
//
$data = array(array(0, ACTYPE_GROUP, "Phase 1", "2001-10-26", "2001-11-23", ''), array(1, ACTYPE_NORMAL, "  Label 2", "2001-10-26", "2001-11-16", ''), array(2, ACTYPE_NORMAL, "  Label 3", "2001-11-20", "2001-11-22", ''), array(3, ACTYPE_NORMAL, "  Label 4", "2001-11-20", "2001-11-22", ''), array(4, ACTYPE_MILESTONE, "  Phase 1 Done", "2001-11-23", 'M2'));
// The constrains between the activities
$constrains = array(array(1, 2, CONSTRAIN_ENDEND), array(2, 3, CONSTRAIN_STARTEND), array(3, 4, CONSTRAIN_ENDSTART));
$progress = array(array(1, 0.4));
// Create the basic graph
$graph = new GanttGraph();
$graph->title->Set("Example with grouping and constrains");
// Setup scale
$graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK);
$graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAYWNBR);
// Add the specified activities
$graph->CreateSimple($data, $constrains, $progress);
// .. and stroke the graph
$graph->Stroke();
?>


Exemple #2
0
 public function graficar($filename)
 {
     $graph = new GanttGraph();
     $graph->SetShadow();
     $graph->SetBox();
     $dataset = $this->dataSource->getDataset();
     define('UTF-8', $locale_char_set);
     $tamanioDataset = count($dataset);
     $fecha_reg_ini = new DateTime();
     $fecha_reg_fin = new DateTime();
     $fechaInicio = new DateTime();
     $fechaFin = new DateTime();
     $data = array();
     $constrains = array();
     for ($i = 0; $i < $tamanioDataset; $i++) {
         //echo date_format(new DateTime($dataset[$i]['fecha_ini']),'Y-m-d H:i:s');
         //exit;
         if ($i == 0) {
             $fechaInicio = new DateTime($dataset[$i]['fecha_ini']);
             $fechaFin = new DateTime($dataset[$i]['fecha_fin']);
         }
         if ($fechaFin < new DateTime($dataset[$i]['fecha_ini']) && $dataset[$i]['tipo'] == 'estado_final') {
             $fechaFin = new DateTime($dataset[$i]['fecha_ini']);
         }
         $actividad = array();
         array_push($actividad, $dataset[$i]['id']);
         $prefijo = '';
         if ($dataset[$i]['tipo'] == 'proceso') {
             $tipo = ACTYPE_GROUP;
         }
         if ($dataset[$i]['tipo'] == 'estado') {
             $tipo = ACTYPE_NORMAL;
             $prefijo = '  ';
         }
         if ($dataset[$i]['tipo'] == 'obs') {
             $tipo = ACTYPE_NORMAL;
             $prefijo = '  ';
         }
         if ($dataset[$i]['tipo'] == 'estado_final') {
             $tipo = ACTYPE_MILESTONE;
             $prefijo = '  ';
         }
         //arma cabecera
         $fecha_reg_ini = new DateTime($dataset[$i]['fecha_ini']);
         $fecha_reg_fin = new DateTime($dataset[$i]['fecha_fin']);
         $resp = $dataset[$i]['funcionario'] != '' ? $dataset[$i]['funcionario'] : $dataset[$i]['depto'];
         $resp = $resp == '' ? $dataset[$i]['cuenta'] : $resp;
         //$resp = $dataset[$i]['depto'].'('.$dataset[$i]['cuenta'].") ->".$dataset[$i]['funcionario'];
         //$resp = $dataset[$i]['depto'].'('.$dataset[$i]['cuenta'].");
         $fini = $fecha_reg_ini->format('d M H:i:s');
         $ffin = $fecha_reg_fin->format('d M H:i:s');
         $start = strtotime($dataset[$i]['fecha_ini']);
         $end = strtotime($dataset[$i]['fecha_fin']);
         $days_between = round(($end - $start) / 86400);
         if ($dataset[$i]['tipo'] == 'obs') {
             $desc_principal = utf8_decode($prefijo . '  -> OBS: ' . $dataset[$i]['nombre']);
         } else {
             $desc_principal = utf8_decode($prefijo . $dataset[$i]['nombre']);
         }
         if ($dataset[$i]['tipo'] == 'estado' || $dataset[$i]['tipo'] == 'obs') {
             $tiempo = $days_between . ' dias';
         } else {
             if ($dataset[$i]['tipo'] == 'estado_final') {
                 $tiempo = '--';
                 $ffin = $fini;
             } else {
                 $resp = '--';
                 $tiempo = $days_between . ' dias';
                 $desc_principal = $desc_principal . "\n" . $dataset[$i]['descripcion'];
             }
         }
         // si el estado tiene configurado el nombre de estapa damos preferencia a este campo
         if (isset($dataset[$i]['etapa']) && $dataset[$i]['etapa'] != '') {
             $desc_principal = '  ' . $dataset[$i]['etapa'] . ' [' . trim($desc_principal) . ']';
         }
         //mostramos cuenta de usuario si existe
         if ($dataset[$i]['nombre_usuario_ai'] != '' && $dataset[$i]['nombre_usuario_ai'] != 'NULL') {
             $desc_principal = $desc_principal . ' (por AI: ' . $dataset[$i]['nombre_usuario_ai'] . ")";
         } elseif ($dataset[$i]['cuenta'] != '') {
             $desc_principal = $desc_principal . ' (por: ' . $dataset[$i]['cuenta'] . ")";
         }
         if ($dataset[$i]['disparador'] == 'no' && $dataset[$i]['estado_reg'] == 'activo' || $dataset[$i]['tipo'] == 'estado_final') {
             $desc_principal = $desc_principal . ' *****';
         }
         $cabecera = array(utf8_decode($desc_principal), utf8_decode($resp), $tiempo, $fini, $ffin);
         array_push($actividad, $tipo);
         array_push($actividad, $cabecera);
         array_push($actividad, $fecha_reg_ini->format('Y-m-d H:i:s'));
         if ($dataset[$i]['tipo'] != 'estado_final') {
             array_push($actividad, $fecha_reg_fin->format('Y-m-d H:i:s'));
         }
         array_push($actividad, utf8_decode($dataset[$i]['descripcion']));
         array_push($actividad, '#' . $dataset[$i]['id']);
         array_push($actividad, $fecha_reg_ini->format('Y-m-d H:i:s'));
         //prepara las relaciones entre tipos
         if ($dataset[$i]['tipo'] == 'estado' && $dataset[$i]['id_siguiente'] != 0) {
             array_push($constrains, array($dataset[$i]['id'], $dataset[$i]['id_siguiente'], CONSTRAIN_ENDSTART));
         }
         array_push($data, $actividad);
     }
     //definir scala en funcion al dia inicial y dia final
     $diferencia = $fechaInicio->diff($fechaFin);
     if ($diferencia->format('%m') >= 24) {
         //escala de meses
         $graph->ShowHeaders(GANTT_HYEAR);
         $sw = 1;
         $fechaFin = $fechaFin->add(new DateInterval('PT9000H'));
     } elseif ($diferencia->format('%m') >= 7) {
         //escala de meses
         $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH);
         $sw = 1;
         $fechaFin = $fechaFin->add(new DateInterval('PT29000H'));
     } elseif ($diferencia->format('%m') > 6) {
         //escala de meses
         $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH);
         $graph->scale->week->SetStyle(HOURSTYLE_HM24);
         $sw = 1;
         $fechaFin = $fechaFin->add(new DateInterval('PT6000H'));
     } elseif ($diferencia->format('%m') > 1) {
         //escala de semanas
         $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HWEEK);
         $graph->scale->week->SetStyle(HOURSTYLE_HM24);
         $sw = 2;
         $fechaFin = $fechaFin->add(new DateInterval('PT7000H'));
     } elseif ($diferencia->format('%m') > 0) {
         //escala de dias
         $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HWEEK | GANTT_HDAY);
         $graph->scale->week->SetStyle(HOURSTYLE_HM24);
         $sw = 3;
         $fechaFin = $fechaFin->add(new DateInterval('PT4600H'));
     } elseif ($diferencia->format('%m') == 0 && $diferencia->format('%d') > 1) {
         //escala de dias
         $graph->ShowHeaders(GANTT_HMONTH | GANTT_HWEEK | GANTT_HDAY | GANTT_HHOUR);
         $graph->scale->week->SetStyle(HOURSTYLE_HM24);
         $graph->scale->hour->SetInterval(12);
         $sw = 4;
         $fechaFin = $fechaFin->add(new DateInterval('PT400H'));
     } else {
         //escala de horas
         $graph->ShowHeaders(GANTT_HDAY | GANTT_HHOUR);
         $graph->scale->week->SetStyle(HOURSTYLE_HM24);
         $fechaFin = $fechaFin->add(new DateInterval('PT250H'));
         $sw = 5;
     }
     $graph->scale->actinfo->SetColTitles(array('Tipo', 'Responsable', 'Duracion', 'Inicio', 'Fin'), array(40, 100));
     // Setup a horizontal grid
     $graph->hgrid->Show();
     $graph->hgrid->SetRowFillColor('darkblue@0.9');
     $graph->SetDateRange($fechaInicio->format('Y-m-d H:i:s'), $fechaFin->format('Y-m-d H:i:s'));
     //$graph->SetDateRange('2013-06-04','2013-08-04');
     $graph->title->Set("Diagrama Gant Work Flow");
     //$graph->scale->week->SetStyle(MINUTESTYLE_MM);
     $graph->scale->week->SetFont(FF_FONT1);
     $progress = array();
     $graph->CreateSimple($data, $constrains, $progress);
     $archivo = dirname(__FILE__) . '/../../../reportes_generados/' . $filename;
     //$graph->StrokeCSIM();
     $graph->Stroke($archivo);
     /*
             
             echo ('<pre>');
             var_dump($sw);
             var_dump($fechaInicio->format('Y-m-d H:i:s'));
             var_dump($fechaFin->format('Y-m-d H:i:s'));
             
             var_dump($data);
             echo ('</pre>');
             
             echo ('<pre>');
             print_r($constrains);
             echo ('</pre>');*/
 }
 private function createGanttGraph($dataorder, $datalabel, $datastart, $dataende, $datamilestone, $dataprogress, $scale, $title, $constraitkey, $constraitvalue, $constrait, $startdate, $enddate)
 {
     // Create the graph.
     $graph = new GanttGraph($this->width, $this->height, "auto");
     $graph->scale->actinfo->SetColTitles(array('Paket'), array(30));
     //        $icon = new IconPlot( dirname(__FILE__).'/../../themes/basic/gfx/logorisklogiq.png', 0.65,0.90,1 ,40);
     //        $icon->SetAnchor( 'left', 'bottom');
     //        $graph->Add( $icon);
     $todaydate = new DateTime();
     $vline = new GanttVLine($todaydate->format("Y-m-d"), "Today");
     $graph->Add($vline);
     if ($startdate == NULL) {
         $myDate = new DateTime();
         $startdate = $myDate->format("Y-m-d");
     }
     if ($enddate == NULL) {
         $my2Date = new DateTime($startdate);
         $my2Date->modify("30days");
         $enddate = $my2Date->format("Y-m-d");
     }
     $graph->SetDateRange($startdate, $enddate);
     $graph->title->Set($title);
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->ShowHeaders(GANTT_HDAY | GANTT_HWEEK | GANTT_HMONTH);
     $graph->scale->week->setStyle(WEEKSTYLE_FIRSTDAY);
     $graph->scale->month->setStyle(MONTHSTYLE_SHORTNAMEYEAR2);
     // Setup a horizontal grid
     $graph->hgrid->Show();
     $graph->hgrid->SetRowFillColor('darkblue@0.93');
     if ($this->shadow) {
         $graph->SetShadow();
     }
     $mapper = array();
     $mydata = array();
     $progress = array();
     $color = array();
     $ii = 0;
     foreach ($this->dataorder as $dorder) {
         if ($datamilestone[$ii] == 0) {
             $mapper[$dataorder[$ii]] = $ii;
             array_push($mydata, array($ii, ACTYPE_NORMAL, $datalabel[$ii], $datastart[$ii], $dataende[$ii], ' '));
             array_push($progress, array($ii, $dataprogress[$ii] / 100));
             array_push($color, array($ii, 'gray'));
         } else {
             $mapper[$dataorder[$ii]] = $ii;
             array_push($mydata, array($ii, ACTYPE_MILESTONE, $datalabel[$ii], $datastart[$ii], $datalabel[$ii]));
         }
         $ii++;
     }
     $myconstrait = array();
     $ii = 0;
     foreach ($constraitkey as $dorder) {
         array_push($myconstrait, array($mapper[$constraitvalue[$ii]], $mapper[$constraitkey[$ii]], $constrait[$ii]));
         $ii++;
     }
     //print_r($myconstrait);
     //print_r($mydata);
     $graph->CreateSimple($mydata, $myconstrait, $progress, $color);
     return $graph;
 }
Exemple #4
0
<?php

// content="text/plain; charset=utf-8"
// Gantt example
require_once "jpgraph/jpgraph.php";
require_once "jpgraph/jpgraph_gantt.php";
//
// The data for the graphs
//
$data = array(array(0, ACTYPE_GROUP, "Phase 1", "2001-10-26", "2001-11-23", ''), array(1, ACTYPE_NORMAL, "  Label 2", "2001-10-26", "2001-11-13", '[KJ]'), array(2, ACTYPE_NORMAL, "  Label 3", "2001-11-20", "2001-11-22", '[EP]'), array(3, ACTYPE_MILESTONE, "  Phase 1 Done", "2001-11-23", 'M2'));
// Create the basic graph
$graph = new GanttGraph();
$graph->title->Set("Gantt Graph using CreateSimple()");
// Setup scale
$graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK);
$graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
// Add the specified activities
$graph->CreateSimple($data);
// .. and stroke the graph
$graph->Stroke();
?>


Exemple #5
0
function gantt_simple_example2($p_metrics, $p_title = "", $p_subtitle = "")
{
    // $data = array(
    //   array(0,ACTYPE_GROUP,    "Phase 1",        "2001-10-26","2001-11-23",""),
    //   array(1,ACTYPE_NORMAL,   "  Label 2",      "2001-10-26","2001-11-13","[KJ]"),
    //   array(2,ACTYPE_NORMAL,   "  Label 3",      "2001-11-20","2001-11-22","[EP]"),
    //   array(3,ACTYPE_MILESTONE,"  Phase 1 Done", "2001-11-23","M2") );
    // Create the basic graph
    $graph = new GanttGraph();
    $graph->title->Set($p_title);
    $graph->subtitle->Set("({$p_subtitle})");
    // Setup scale
    $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK);
    $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
    // Add the specified activities
    $graph->CreateSimple($p_metrics);
    // .. and stroke the graph
    $graph->Stroke();
}