Adding GANTT chart to PHPRunner/ASPRunnerPro app

A special thank you to Fred Blau who provided the original jsgantt integration sample.

A Gantt chart is a type of bar chart that illustrates a project schedule. Gantt charts illustrate the start and finish dates of the tasks that belong to this project. Some Gantt charts also show the dependency relationships between activities (tasks). Gantt charts can be used to show current schedule status using percent-complete shadings and a vertical "TODAY" line.

Sample GANTT chart in PHPRunner

I'll show you how to add to GANTT chart to your PHPRunner or ASPRunnerPro project. We are going to use free Javascript jsgantt component for this purpose. You can download PHP and ASP version of all required files at the end of this article.

Jsgantt provides an API to add tasks. It can also load tasks from external XML file which we plan to use in our project.

Sample XML file:

  1.  
  2. <project>
  3. <task>
  4. <pID>10</pID>
  5. <pName>WCF Changes</pName>
  6. <pStart></pStart>
  7. <pEnd></pEnd>
  8. <pColor>0000ff</pColor>
  9. <pLink></pLink>
  10. <pMile>0</pMile>
  11. <pRes></pRes>
  12. <pComp>0</pComp>
  13. <pGroup>1</pGroup>
  14. <pParent>0</pParent>
  15. <pOpen>1</pOpen>
  16. <pDepend />
  17. </task>
  18. <task>
  19. <pID>20</pID>
  20. <pName>Move to WCF from remoting</pName>
  21. <pStart>8/11/2008</pStart>
  22. <pEnd>8/15/2008</pEnd>
  23. <pColor>0000ff</pColor>
  24. <pLink></pLink>
  25. <pMile>0</pMile>
  26. <pRes>Rich</pRes>
  27. <pComp>10</pComp>
  28. <pGroup>0</pGroup>
  29. <pParent>10</pParent>
  30. <pOpen>1</pOpen>
  31. <pDepend></pDepend>
  32. </task>
  33. <task>
  34. <pID>30</pID>
  35. <pName>add Auditing</pName>
  36. <pStart>8/19/2008</pStart>
  37. <pEnd>8/21/2008</pEnd>
  38. <pColor>0000ff</pColor>
  39. <pLink></pLink>
  40. <pMile>0</pMile>
  41. <pRes>Mal</pRes>
  42. <pComp>50</pComp>
  43. <pGroup>0</pGroup>
  44. <pParent>10</pParent>
  45. <pOpen>1</pOpen>
  46. <pDepend>20</pDepend>
  47. </task>
  48. </project>

1. We are going to need two tables: tblProjects and tblTasks.

tblProject contains basic project description.

  1. CREATE TABLE `tblProject` (
  2. `ProjectID` int(11) NOT NULL AUTO_INCREMENT,
  3. `ProjectName` varchar(40) DEFAULT NULL,
  4. `StartDate` datetime DEFAULT NULL,
  5. `EndDate` datetime DEFAULT NULL,
  6. PRIMARY KEY (`ProjectID`)
  7. ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

tblTasks contains detailed description of each task. Some fields in this table are optional and not being used in our example.

  1. CREATE TABLE `tblTasks` (
  2. `TaskID` int(11) NOT NULL AUTO_INCREMENT,
  3. `ProjectID` int(11) DEFAULT NULL,
  4. `ParentID` int(11) DEFAULT '0',
  5. `TaskName` varchar(60) DEFAULT NULL,
  6. `TaskNumber` varchar(10) DEFAULT NULL,
  7. `AssignedTo` varchar(30) DEFAULT NULL,
  8. `SchedStart` datetime DEFAULT NULL,
  9. `SchedEnd` datetime DEFAULT NULL,
  10. `ActualStart` datetime DEFAULT NULL,
  11. `ActualEnd` datetime DEFAULT NULL,
  12. `EstHours` float DEFAULT NULL,
  13. `TaskStatus` int(11) DEFAULT NULL,
  14. `PercentComplete` tinyint(4) DEFAULT NULL,
  15. `Notes` longtext,
  16. `IsGroup` tinyint(4) DEFAULT '0',
  17. `BarColorHex` varchar(6) DEFAULT '0000FF',
  18. `DependentOn` varchar(10) DEFAULT NULL,
  19. PRIMARY KEY (`TaskID`)
  20. ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

2. Add both tables to the project and link them as Master-Details using ProjectID as a link field in both tables. Check off 'Display child records on View page' option.

We also choose ProjectID as a key column of tblProjects table.

3. In Visual Editor proceed to the page where you want to display the GANTT chart. In our example we add GANTT chart to the tblProjects view page. Right-click where you want to add the chart and choose 'Insert PHP code snippet'. Paste the following code there:

  1. $value = "Gantt<BR>";
  2.  
  3. $myFile = "gantt.php?ProjectID=".$_REQUEST["editid1"];
  4. //$myFile="gantt.xml";
  5.  
  6. $value = $value."
  7. <link rel='stylesheet' type='text/css' href='jsgantt.css'/>";
  8. $value = $value."<script language='javascript' src='jsgantt.js'></script>";
  9.  
  10. $value = $value."
  11. <div style='position:relative' class='gantt' id='GanttChartDIV'></div>
  12.  
  13. \n";
  14. $value = $value."<script language='javascript'>\n";
  15.  
  16. $value = $value."var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'week');\n";
  17.  
  18. $value = $value."g.setShowRes(1);\n";
  19. $value = $value."g.setShowDur(1);\n";
  20. $value = $value."g.setShowComp(1);\n";
  21. $value = $value."g.setCaptionType('Resource');\n";
  22.  
  23. $value = $value."if( g ) {\n";
  24.  
  25. $value = $value."JSGantt.parseXML('".$myFile."',g);\n";
  26.  
  27. $value = $value."}";
  28. $value = $value."else {";
  29. $value = $value." alert('not defined');";
  30. $value = $value." }";
  31.  
  32. $value = $value."</script>";
  33.  
  34. echo $value;

In this code snippet we include jsgantt.js and jsgantt.css files, create JSGantt object and parse XML file provided by gantt.php file. Note that we pass the current ProjectID as a parameter to gantt.php ("gantt.php?ProjectID=".$_REQUEST["editid1"]);

4. In the output directory create a new file named gantt.php and paste the following code there:

  1. <?php
  2. include("include/dbcommon.php");
  3. $out="
  4. <project>\n";
  5.  
  6. $sql = "select * from tblTasks where ProjectID=".$_REQUEST["ProjectID"]." Order by TaskNumber";
  7.  
  8. $rs = db_query($sql,$conn);
  9.  
  10. while($rdata=db_fetch_array($rs))
  11. {
  12.  
  13. $out.="<task>\n";
  14. $out.="
  15. <pID>".$rdata["TaskNumber"]."</pID>\n";
  16. $out.="
  17. <pName>".$rdata["TaskName"]."</pName>\n";
  18.  
  19. if ($rdata["SchedStart"] == "")
  20. {
  21. $StartDate = "";
  22. }
  23. else
  24. {
  25. $StartDate = date('m/d/Y',strtotime($rdata["SchedStart"]));
  26. }
  27. $out.="
  28. <pStart>".$StartDate."</pStart>\n";
  29.  
  30. if ($rdata["SchedEnd"] == "")
  31. {
  32. $EndDate = "";
  33. }
  34. else
  35. {
  36. $EndDate = date('m/d/Y',strtotime($rdata["SchedEnd"]));
  37. }
  38. $out.="
  39. <pEnd>".$EndDate."</pEnd>\n";
  40. $out.="
  41. <pColor>".$rdata["BarColorHex"]."</pColor>\n";
  42. $out.="
  43. <pLink></pLink>\n";
  44. $out.="
  45. <pMile>0</pMile>\n";
  46. $out.="
  47. <pRes>".$rdata["AssignedTo"]."</pRes>\n";
  48. $out.="
  49. <pComp>".$rdata["PercentComplete"]."</pComp>\n";
  50. $out.="
  51. <pGroup>".$rdata["IsGroup"]."</pGroup>\n";
  52. $out.="
  53. <pParent>".$rdata["ParentID"]."</pParent>\n";
  54. $out.="
  55. <pOpen>1</pOpen>\n";
  56. $out.="
  57. <pDepend>".$rdata["DependentOn"]."</pDepend>\n";
  58. $out.="
  59. <pCaption></pCaption>\n";
  60. $out.="</task>\n";
  61. }
  62. $out.="</project>";
  63.  
  64. echo $out;
  65.  
  66. ?>

Make sure to amend table and field names if your database structure is different.

Now build your project and proceed to tblprojects view page. If you done everything right you going to see a GANTT chart. Here is the live demo page just in case.

Enjoy!

Download files mentioned in this article: PHP version ASP version.

More info on jsgantt:
Documentation
Examples

21 comments to Adding GANTT chart to PHPRunner/ASPRunnerPro app

  • Smith

    Are you planing to include this in the next version pf phprunner/asprunner just the way we create the charts through the software which will take care of most of the steps mentioned above, Then it will be a great advantage.

  • Smith

    Are you planing to include this in the next version pf phprunner/asprunner just the way we create the charts through the software which will take care of most of the steps mentioned above, Then it will be a great advantage. AnyGANTT (http://anychart.com/products/anygantt/) is also a good choice to incorporate in the software like AnyChart.

  • Edgar V

    This is an awsome project and it can extreamly useful. One thought, question.
    Is there a way you can export it to excel?

  • admin

    Edgar,

    I guess you can use standard PHPRunner export function. It will export data only though. The actual chart is Javascript based and works in browser only. Btw, Excel has its own built-in GANTT chart functionality.

  • admin

    Smith,

    we haven’t decided yet what kind of GANTT integration we can offer. The method above should take care of most needs for now.

  • Edgar V

    Thank you for the reply. The reason for my question was because our President liked the project but as I quote “We often get asked by our corporate office to send the gantt charts so they can see the progress of a specific project. I can easily send the excel gantt chart, If I have to send them a user name and password to log in I don’t think they would do that” Hence my question for exporting the gantt and data to excel.

    Thanks!!

  • rlee6087

    I tired this an all I get is the Gantt under the view page. Can you be a bit more specific with the instructions please. I noticed that the project.xml file is supposed tobe called gantt.xml? Please advise as this is a seriously major enhancement to an already great product.

  • This is a great feature. For someone like me it involves more information. If I have a database with all my task in a table, with the same fields as in the example, step by step, what do I need to do to get it to look like your output?

    Also, if this could be built in the the phprunner in a manner that was easy to use I think it would be extremely useful in many industries.

    Thanks for any help
    Don

  • Rlee6087

    I figured it out, works great in IE, however doesnt appear in latest ersion of Firefox, or not for me anyway. Still pretty impressive. I love it.

  • APENSLER

    This is a fantastic tool! I have one question. Does anyone know how to create a milestone. I have not be able to figure that out.

    Thanks

  • I currently have a test site created using phprunner. I want to incorporate the gantt chart into it using the data that is already there. I need someone to help me with that. I would be willing to pay you for your services. I also want to learn how to do it myself. Please contact me if you would be willing to help me with this and we can discuss the details and your price. Thanks donbwalker@gmail.com

  • Mohamed

    Hi Admin,

    As far as I understand, you need to have an XML file in the first place, right? How can I create a gantt chart out of MySQL database without the need of XML file? Can you please let me know how to do it?

    thanks,
    Mohamed

  • Ulrich Lüer

    Hi Admin,

    this function looks as if it could be used to show various planning charts beside a gantt chart.
    I think of sheduling rent periods for a vehicle or device.
    Reservation of facilities etc.
    Is there somebody to draft a solution for this typ of tasks.
    I have a table e.g. vehicles and a table sheduled periods that are linked by the vehicles_ID. At the moment I list this in the standard Master/Slave – relationship form with color codes for planned, actual and old rent data sets.
    To have a calender like layout would be very helpful.

    Thanks
    Ulrich

  • Mohamed

    xlinesoft really needs to implement a gantt chart function in PHPRunner. Any plans for the next version?

    One more thing:

    Is there a way to display a gantt chart for all projects in one page in stead of a gantt per project? Can anybody please help?

    thanks,
    Mohamed

  • admin

    @Rlee6087

    I would suggest to re-download gantt files. The issue with Firefox were fixed a couple of days after article were published.

  • admin

    @Mohamed

    you do not need an XML file, gantt.php creates XML file on the fly based on your database data.

    The approach above will work with any data and you can add it to any page. Its all matter of what data you want to display. Modify gantt.php file if field names in your database are different. Contact support directly if you need more help.

  • admin

    @Ulrich

    just in case – check Calendar template at http://xlinesoft.com/templates/calendar/index.htm. Probably this is what you looking for.

  • Bernd

    What I do wrong if I only see GANT as a discripten

  • David Fleming

    I’ve been been working on this all morning and like Bernd above I can only see Gantt displayed (no chart data). I’ve used the download file (from here) and the ones available from the jsgantt page. Ive used the snippet from this page and the one from the download. For testing I’ve also created the example gantt.xml file and uncommented the reference to in in line 4 (while commenting out the php file reference in line 3). I always see the same result which is just the heading Gantt.

    When the demo files from the jsgantt project download and install them into a subdirectory of the same site I see the demo show up perfectly.

  • David Fleming

    Solution! I think I discovered that the .sql file included incorrectly names the new tables with all lowercase letters while the code looks for tables with tblProject and tblTasks (mixed case). If you follow the guide from the screen using upper/lower case table names then it works!

  • I’ve been been trying to download but it keeps showing me this: 403 – Forbidden: Access is denied.
    Is anyone else having issues with it? Is there another download page?

    Thanks

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>