Hi All,
I am trying to create a gantt chart in php by getting data from
database. I am using WindowsXp OS and having php-4 and my-sql DB. I
have installed the JPGRAPH package to my system and including the
jpgraph modules accordingly. I am able to create a gantt chart by
hardcoding the datas but when I am trying to get the data from database
then I am not able to get the chart it is showing errors. I think thre
might be some problem in my code . So please rectify my code I have
posted here.
Thanks,
Kuna
<?php
include ("C:/Program
Files/xampp/htdocs/Graph/jpgraph-1.20.5/src/jpgraph.php");
include ("C:/Program
Files/xampp/htdocs/Graph/jpgraph-1.20.5/src/jpgraph_gantt.p hp");
// Basic Gantt graph
$graph = new GanttGraph();
$graph->title->Set("Project StartDate and EndDate");
// Explicitely set the date range
// (Autoscaling will of course also work)
$graph->SetDateRange(' 2006-01-01','2007-12-31');
// 1.5 line spacing to make more room
$graph->SetVMarginFact or(1.5);
// Setup some nonstandard colors
$graph->SetMarginColor ('lightgreen@0. 8');
$graph->SetBox(true,'y ellow:0.6',2);
$graph->SetFrame(true, 'darkgreen',4);
$graph->scale->divider->SetColor('yell ow:0.6');
$graph->scale->dividerh->SetColor('yell ow:0.6');
// Display month and year scale with the gridlines
$graph->ShowHeaders(GA NTT_HMONTH | GANTT_HYEAR);
$graph->scale->month->grid->SetColor('gray ');
$graph->scale->month->grid->Show(true);
$graph->scale->year->grid->SetColor('gray ');
$graph->scale->year->grid->Show(true);
// For the titles we also add a minimum width of 100 pixels for the
Task name column
$graph->scale->actinfo->SetColTitles (
array('Note','T ask','Duration' ,'Start','Finis h'),array(30,10 0));
$graph->scale->actinfo->SetBackgroundC olor('green:0.5 @0.5');
$graph->scale->actinfo->SetFont(FF_ARI AL,FS_NORMAL,10 );
$graph->scale->actinfo->vgrid->SetStyle('soli d');
$graph->scale->actinfo->vgrid->SetColor('gray ');
// Uncomment this to keep the columns but show no headers
//$graph->scale->actinfo->Show(false);
// Setup the icons we want to use
$erricon = new IconImage(GICON _FOLDER,0.8);
$startconicon = new IconImage(GICON _FOLDEROPEN,0.6 );
$endconicon = new IconImage(GICON _TEXTIMPORTANT, 0.5);
// Set the variables for the database access:
$Host = "localhost" ;
$User = "root";
$Password = "";
$DBName = "zend";
$TableName = "tbl_projec ts";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName ";
$Result = mysql_db_query( $DBName, $Query);
$j=0;
while ($Row=mysql_fet ch_array($Resul t)) {
$duration=$Row["Project_En d"]-$Row["Project_St art"];
$data[] =
array(array($j, array($erricon, $Row["ProjectNam e"],$duration,$Row["Project_St art"],$Row["Project_En d"])
,
$Row["Project_St art"],$Row["Project_En d"],FF_ARIAL,FS_NO RMAL,8));
++$j;
print $j;
}
// Create the bars and add them to the gantt chart
for($i=0; $i<count($data) ; ++$i) {
$bar = new
GanttBar($data[$i][0],$data[$i][1],$data[$i][2],$data[$i][3]);
//if( count($data[$i])>4 )
//$bar->title->SetFont($dat a[$i][4],$data[$i][5],$data[$i][6]);
$bar->SetPattern(BAN D_RDIAG,"yellow ");
$bar->SetFillColor(" gray");
$bar->progress->Set(0.5);
$bar->progress->SetPattern(GAN TT_SOLID,"darkg reen");
//$bar->title->SetCSIMTarget( array('#1'.$i,' #2'.$i,'#3'.$i, '#4'.$i,'#5'.$i ),array('11'.$i ,'22'.$i,'33'.$ i));
$graph->Add($bar);
}
// Output the chart
$graph->Stroke();
?>
I am trying to create a gantt chart in php by getting data from
database. I am using WindowsXp OS and having php-4 and my-sql DB. I
have installed the JPGRAPH package to my system and including the
jpgraph modules accordingly. I am able to create a gantt chart by
hardcoding the datas but when I am trying to get the data from database
then I am not able to get the chart it is showing errors. I think thre
might be some problem in my code . So please rectify my code I have
posted here.
Thanks,
Kuna
<?php
include ("C:/Program
Files/xampp/htdocs/Graph/jpgraph-1.20.5/src/jpgraph.php");
include ("C:/Program
Files/xampp/htdocs/Graph/jpgraph-1.20.5/src/jpgraph_gantt.p hp");
// Basic Gantt graph
$graph = new GanttGraph();
$graph->title->Set("Project StartDate and EndDate");
// Explicitely set the date range
// (Autoscaling will of course also work)
$graph->SetDateRange(' 2006-01-01','2007-12-31');
// 1.5 line spacing to make more room
$graph->SetVMarginFact or(1.5);
// Setup some nonstandard colors
$graph->SetMarginColor ('lightgreen@0. 8');
$graph->SetBox(true,'y ellow:0.6',2);
$graph->SetFrame(true, 'darkgreen',4);
$graph->scale->divider->SetColor('yell ow:0.6');
$graph->scale->dividerh->SetColor('yell ow:0.6');
// Display month and year scale with the gridlines
$graph->ShowHeaders(GA NTT_HMONTH | GANTT_HYEAR);
$graph->scale->month->grid->SetColor('gray ');
$graph->scale->month->grid->Show(true);
$graph->scale->year->grid->SetColor('gray ');
$graph->scale->year->grid->Show(true);
// For the titles we also add a minimum width of 100 pixels for the
Task name column
$graph->scale->actinfo->SetColTitles (
array('Note','T ask','Duration' ,'Start','Finis h'),array(30,10 0));
$graph->scale->actinfo->SetBackgroundC olor('green:0.5 @0.5');
$graph->scale->actinfo->SetFont(FF_ARI AL,FS_NORMAL,10 );
$graph->scale->actinfo->vgrid->SetStyle('soli d');
$graph->scale->actinfo->vgrid->SetColor('gray ');
// Uncomment this to keep the columns but show no headers
//$graph->scale->actinfo->Show(false);
// Setup the icons we want to use
$erricon = new IconImage(GICON _FOLDER,0.8);
$startconicon = new IconImage(GICON _FOLDEROPEN,0.6 );
$endconicon = new IconImage(GICON _TEXTIMPORTANT, 0.5);
// Set the variables for the database access:
$Host = "localhost" ;
$User = "root";
$Password = "";
$DBName = "zend";
$TableName = "tbl_projec ts";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName ";
$Result = mysql_db_query( $DBName, $Query);
$j=0;
while ($Row=mysql_fet ch_array($Resul t)) {
$duration=$Row["Project_En d"]-$Row["Project_St art"];
$data[] =
array(array($j, array($erricon, $Row["ProjectNam e"],$duration,$Row["Project_St art"],$Row["Project_En d"])
,
$Row["Project_St art"],$Row["Project_En d"],FF_ARIAL,FS_NO RMAL,8));
++$j;
print $j;
}
// Create the bars and add them to the gantt chart
for($i=0; $i<count($data) ; ++$i) {
$bar = new
GanttBar($data[$i][0],$data[$i][1],$data[$i][2],$data[$i][3]);
//if( count($data[$i])>4 )
//$bar->title->SetFont($dat a[$i][4],$data[$i][5],$data[$i][6]);
$bar->SetPattern(BAN D_RDIAG,"yellow ");
$bar->SetFillColor(" gray");
$bar->progress->Set(0.5);
$bar->progress->SetPattern(GAN TT_SOLID,"darkg reen");
//$bar->title->SetCSIMTarget( array('#1'.$i,' #2'.$i,'#3'.$i, '#4'.$i,'#5'.$i ),array('11'.$i ,'22'.$i,'33'.$ i));
$graph->Add($bar);
}
// Output the chart
$graph->Stroke();
?>
Comment