473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Creating Gantt Chart in PHP

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.php");

// 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->SetVMarginFactor(1.5);

// Setup some nonstandard colors
$graph->SetMarginColor('l*********@0.8');
$graph->SetBox(true,'yellow:0.6',2);
$graph->SetFrame(true,'darkgreen',4);
$graph->scale->divider->SetColor('yellow:0.6');
$graph->scale->dividerh->SetColor('yellow:0.6');

// Display month and year scale with the gridlines
$graph->ShowHeaders(GANTT_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','Task','Duration','Start','Finish'),a rray(30,100));
$graph->scale->actinfo->SetBackgroundColor('green:0.*@0.5');
$graph->scale->actinfo->SetFont(FF_ARIAL,FS_NORMAL,10);
$graph->scale->actinfo->vgrid->SetStyle('solid');
$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_projects";

$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName ";
$Result = mysql_db_query($DBName, $Query);

$j=0;
while ($Row=mysql_fetch_array($Result)) {

$duration=$Row["Project_End"]-$Row["Project_Start"];
$data[] =
array(array($j,array($erricon,$Row["ProjectName"],$duration,$Row["Project_Start"],$Row["Project_End"])
,
$Row["Project_Start"],$Row["Project_End"],FF_ARIAL,FS_NORMAL,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($data[$i][4],$data[$i][5],$data[$i][6]);
$bar->SetPattern(BAND_RDIAG,"yellow");
$bar->SetFillColor("gray");
$bar->progress->Set(0.5);
$bar->progress->SetPattern(GANTT_SOLID,"darkgreen");

//$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();

?>

Nov 7 '06 #1
5 10407
Kuna schreef:
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.
What errors are you getting?
JW
Nov 7 '06 #2
Kuna wrote:
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.php");

// 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->SetVMarginFactor(1.5);

// Setup some nonstandard colors
$graph->SetMarginColor('l*********@0.8');
$graph->SetBox(true,'yellow:0.6',2);
$graph->SetFrame(true,'darkgreen',4);
$graph->scale->divider->SetColor('yellow:0.6');
$graph->scale->dividerh->SetColor('yellow:0.6');

// Display month and year scale with the gridlines
$graph->ShowHeaders(GANTT_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','Task','Duration','Start','Finish'),a rray(30,100));
$graph->scale->actinfo->SetBackgroundColor('green:0.*@0.5');
$graph->scale->actinfo->SetFont(FF_ARIAL,FS_NORMAL,10);
$graph->scale->actinfo->vgrid->SetStyle('solid');
$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_projects";

$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName ";
$Result = mysql_db_query($DBName, $Query);

$j=0;
while ($Row=mysql_fetch_array($Result)) {

$duration=$Row["Project_End"]-$Row["Project_Start"];
$data[] =
array(array($j,array($erricon,$Row["ProjectName"],$duration,$Row["Project_Start"],$Row["Project_End"])
,
$Row["Project_Start"],$Row["Project_End"],FF_ARIAL,FS_NORMAL,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($data[$i][4],$data[$i][5],$data[$i][6]);
$bar->SetPattern(BAND_RDIAG,"yellow");
$bar->SetFillColor("gray");
$bar->progress->Set(0.5);
$bar->progress->SetPattern(GANTT_SOLID,"darkgreen");

//$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();

?>
You forgot three important parts here:

1. What do you expect to get?
2. What do you get? (No output because of the errors?)
3. Exactly what errors are you getting?

Also, have you checked the data you got from the database to ensure it
is right (reasonable values, correct type, etc.)?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 7 '06 #3
You forgot three important parts here:

1. What do you expect to get?
2. What do you get? (No output because of the errors?)
3. Exactly what errors are you getting?

Also, have you checked the data you got from the database to ensure it
is right (reasonable values, correct type, etc.)?
Thanks for replying me and I am really sorry I forgot to post the error
message. But now I am able to get into some solutions but the problem
is that still I am getting an error. I have populated the database with
all fields. I am again posting the new code and this is the erro
message I am getting. So please help me its urgent and important for
me. I will be grateful to you.

<?php
// Gantt dyaminc from MySQL example
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.php");
include ("C:/Program
Files/xampp/htdocs/Graph/jpgraph-1.20.5/src/jpgraph_date.php");

$host="localhost";
$user="root";
$password="";
$db="zend";

mysql_connect($host,$user,$password) or die("Could not connect: " .
mysql_error());
mysql_select_db($db) or die("Could not select database: " .
mysql_error());

$tasks = mysql_query("SELECT
task_position,
task_type_value,
task_name,
start_date,
end_date,
DATE_FORMAT(start_date, '%e/%m') as fstart_date,
DATE_FORMAT(end_date, '%e/%m') as fend_date,
CONCAT((end_date - start_date), ' ','days') as duration
FROM tasks, task_type
WHERE tasks.task_type_id=task_type.task_type_id");

if ($row = mysql_fetch_array($tasks)) {
do {
$position[] = $row["task_position"];
$type[] = $row["task_type_value"];
$name[] = $row["task_name"];
$start_date[] = $row["start_date"];
$end_date[] = $row["end_date"];
$fstart_date[] = $row["fstart_date"];
$fend_date[] = $row["fend_date"];
$duration[] = $row["duration"];
}while($row = mysql_fetch_array($tasks));
}
$lines = mysql_num_rows($tasks);
error_reporting(E_ALL);
$graph = new GanttGraph(800,640);
$graph->SetFrame(true,'white',.1);
$graph->SetMarginColor('white:1.7');
//$graph->SetShadow();
$graph->SetColor('white');
//$graph->SetBackgroundGradient('darkblue','white',GRAD_HOR ,BGRAD_MARGIN);

//$graph->title->SetColor('white');
$graph->title->Set("SimpleGantt");
$graph->title->SetFont(FF_ARIAL,FS_BOLD,16);

$graph->ShowHeaders(GANTT_HDAY | GANTT_HWEEK | GANTT_HMONTH);
$graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
$graph->scale->week->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->scale->month->SetStyle(MONTHSTYLE_SHORTNAMEYEAR2);
$graph->scale->month->SetFont(FF_ARIAL, FS_BOLD, 8);

$graph->scale->actinfo->SetColTitles (array('ID','Tasks',
'Duration','Start','End'),array(0,0));
$graph->scale->actinfo->SetFont(FF_ARIAL, FS_ITALIC, 8);

for($i=0; $i< $lines; ++$i) {
$activity = new GanttBar ($position[$i], array($position[$i],
$name[$i], $duration[$i],$fstart_date[$i],$fend_date[$i]),
$start_date[$i], $end_date[$i]);
// $activity = array($position[$i], $type[$i], $name[$i],
$start_date[$i], $end_date[$i]);
$activity ->SetPattern(BAND_RDIAG,"yellow");
$activity ->SetFillColor("red");
$activity->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->Add($activity);
// $graph->CreateSimple($activity);
}
$graph->Stroke();
?>

Here is the Error Message :-
"Cannot autoscale Gantt chart. No dated activities exist.
[GetBarMinMax() start >= n]"

I will be waiting for your reply :)

Thanks and Regards,
Kuna

Nov 7 '06 #4
Kuna wrote:
>>You forgot three important parts here:

1. What do you expect to get?
2. What do you get? (No output because of the errors?)
3. Exactly what errors are you getting?

Also, have you checked the data you got from the database to ensure it
is right (reasonable values, correct type, etc.)?


Thanks for replying me and I am really sorry I forgot to post the error
message. But now I am able to get into some solutions but the problem
is that still I am getting an error. I have populated the database with
all fields. I am again posting the new code and this is the erro
message I am getting. So please help me its urgent and important for
me. I will be grateful to you.

<?php
// Gantt dyaminc from MySQL example
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.php");
include ("C:/Program
Files/xampp/htdocs/Graph/jpgraph-1.20.5/src/jpgraph_date.php");

$host="localhost";
$user="root";
$password="";
$db="zend";

mysql_connect($host,$user,$password) or die("Could not connect: " .
mysql_error());
mysql_select_db($db) or die("Could not select database: " .
mysql_error());

$tasks = mysql_query("SELECT
task_position,
task_type_value,
task_name,
start_date,
end_date,
DATE_FORMAT(start_date, '%e/%m') as fstart_date,
DATE_FORMAT(end_date, '%e/%m') as fend_date,
CONCAT((end_date - start_date), ' ','days') as duration
FROM tasks, task_type
WHERE tasks.task_type_id=task_type.task_type_id");

if ($row = mysql_fetch_array($tasks)) {
do {
$position[] = $row["task_position"];
$type[] = $row["task_type_value"];
$name[] = $row["task_name"];
$start_date[] = $row["start_date"];
$end_date[] = $row["end_date"];
$fstart_date[] = $row["fstart_date"];
$fend_date[] = $row["fend_date"];
$duration[] = $row["duration"];
}while($row = mysql_fetch_array($tasks));
}
$lines = mysql_num_rows($tasks);
error_reporting(E_ALL);
$graph = new GanttGraph(800,640);
$graph->SetFrame(true,'white',.1);
$graph->SetMarginColor('white:1.7');
//$graph->SetShadow();
$graph->SetColor('white');
//$graph->SetBackgroundGradient('darkblue','white',GRAD_HOR ,BGRAD_MARGIN);

//$graph->title->SetColor('white');
$graph->title->Set("SimpleGantt");
$graph->title->SetFont(FF_ARIAL,FS_BOLD,16);

$graph->ShowHeaders(GANTT_HDAY | GANTT_HWEEK | GANTT_HMONTH);
$graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAY);
$graph->scale->week->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->scale->month->SetStyle(MONTHSTYLE_SHORTNAMEYEAR2);
$graph->scale->month->SetFont(FF_ARIAL, FS_BOLD, 8);

$graph->scale->actinfo->SetColTitles (array('ID','Tasks',
'Duration','Start','End'),array(0,0));
$graph->scale->actinfo->SetFont(FF_ARIAL, FS_ITALIC, 8);

for($i=0; $i< $lines; ++$i) {
$activity = new GanttBar ($position[$i], array($position[$i],
$name[$i], $duration[$i],$fstart_date[$i],$fend_date[$i]),
$start_date[$i], $end_date[$i]);
// $activity = array($position[$i], $type[$i], $name[$i],
$start_date[$i], $end_date[$i]);
$activity ->SetPattern(BAND_RDIAG,"yellow");
$activity ->SetFillColor("red");
$activity->title->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->Add($activity);
// $graph->CreateSimple($activity);
}
$graph->Stroke();
?>

Here is the Error Message :-
"Cannot autoscale Gantt chart. No dated activities exist.
[GetBarMinMax() start >= n]"

I will be waiting for your reply :)

Thanks and Regards,
Kuna
OK, I'm not familiar with this specific package, but I looked at the
documentation.

The first thing which comes to mind is are your start and end dates in
the correct format? Have you tried echoing them to the screen to see
what's in them? According to the doc, they should be in the format
'2006-11-07' as a string. That's the default date format for MySQL in
my system, but yours may be different.

Also, I don't like your line:

$activity = new GanttBar ($position[$i], array($position[$i],
$name[$i], $duration[$i],$fstart_date[$i],$fend_date[$i]),
$start_date[$i], $end_date[$i]);

The second parameter according to the doc should be a text label; you're
passing it an array. That may be causing problems. But since you are
getting a chart with hardcoded data, it should be OK.

I'd recommend echoing all of your parameters to the screen to see if
they are really what you expect.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 7 '06 #5
Thanks Jerry,

Thanks a lot for helping I am able to solve it. Actually the problem is
that I have not inserted data in database I thought that first of all
it will show me the blank graph and after entering data it will show
the gantt charts accordingly but I was wrong I need to insert data in
the database so finally I am able to solve it. Thanks again for
cooperating me a lot.

Kuna. :)

Nov 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: musicloverlch | last post by:
OK, I just got a weird question. Can MS Access make a Gantt chart? Has anyone ever done that? How did you do that? Thanks in advance, Laura
1
by: Johnny Fugazzi | last post by:
Does anyone know of a good (and inexpensive) control to display schedule data in a Gantt/Resource Chart?
1
by: news.microsoft.com | last post by:
Hello Does anyone know of any control that allows you to have different view of a calendar including gantt chart style views ? I know the calender control which comes with asp.net 2.0 is not...
0
by: jerry.ranch | last post by:
I was woiondering if there are any add-ins for Access that are Gannt Chart objects? I have a database that records observed and expected dates for many different project and project tasks, and I...
0
by: Gilberto Avila | last post by:
I'm currently developing a web application with ASP .NET 1.1. I'm using the bundled Crystal Reports in Visual Studio 2003 to create reports for this application. The system specification requires...
9
menayah
by: menayah | last post by:
Dear all, How to make a gantt chart from datagrid (datatable) in VB .net web forms ? What are the softwear the I can use for that? Thanks...
0
menayah
by: menayah | last post by:
Dear all, I'm trying to do this gantt chart. but i all get is only the left hand pane. I want the full chart. there is a demo project to run and it runs, but i cant do the same chart. Pls can...
1
by: jj Vorster | last post by:
Hi I am in need of a Gantt Chart in Access that I can use in the development of a rental Company. I should be able to see: Vehicle booking Vehicle out ( Different colour than booking) Vehicle...
9
by: Mel | last post by:
I have some Asp.net 2.0/vb.net code that creates a gantt chart with some dependencies as a new MS Project (.mpp) file. How would I show this resulting .mpp file on an Asp.net webpage? I want to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.