jsGanttImproved - 1.7.5.2

  100% Free Javascript / CSS/ HTML Gantt chart control. Completely buzzword compliant including AJAX !

Basic Features

Advanced Features

Bugs/Issues


Current Issues:

  1. If the browser is viewing the page at anything other than 100% zoom then bars may not be sized or positioned correctly.

Changes/fixes in jsGanttImproved:

v1.7.5.2:

v1.7.5:

v1.7:

v1.6:

v1.5:

v1.4:

v1.3:

Please see the differences for the CSS file in commit ea9890e for details of CSS structural changes.

v1.2:

Both these updates required changes to existing element IDs and style classes. Custom stylesheets will most likely need to be updated.

All chart element ids are now prefixed with the id of the master DIV containing the chart. As a result the default stylesheet has been updated to no longer use any element ids to apply styles.

Please see the notes for commit b4bf8ea for details of CSS structural changes.

v1.1:

v1.0:

Download

Click here to download the current version of jsGantt Improved
You can download the latest bleeding edge version, request features and report issues at https://github.com/jsGanttImproved/jsgantt-improved/

License

JSGanttImproved is released under BSD license.
If you plan to use it in a commercial product please consider donating the first sale to charity.

Usage

Creating a basic Gantt Chart

  1. Include JSGantt CSS and Javascript
    <link rel="stylesheet" type="text/css" href="jsgantt.css" />
    <script language="javascript" src="jsgantt.js"></script>
    
  2. Create a div element to hold the gantt chart
    <div style="position:relative" class="gantt" id="GanttChartDIV"></div>
  3. Start a <script> block
    <script type="text/javascript">
  4. Instantiate JSGantt using GanttChart()
    var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'day');
    

    Method definition: GanttChart(pDiv, pFormat)

    pDiv
    (required) this is a DIV object created in HTML
    pFormat
    (required) - used to indicate whether chart should be drawn in "hour", "day", "week", "month", or "quarter" format
  5. Customize the look and feel using configuration methods (see Configuration Options)

  6. Add Tasks
    1. using AddTaskItem()
      g.AddTaskItem(new JSGantt.TaskItem(1, 'Define Chart API','',          '',          'ggroupblack','', 0, 'Brian', 0,  1,0,1,'','','Some Notes text',g));
      g.AddTaskItem(new JSGantt.TaskItem(11,'Chart Object',    '2016-02-20','2016-02-20','gmilestone', '', 1, 'Shlomy',100,0,1,1,'','','',g));
      

      Method definition: TaskItem(pID, pName, pStart, pEnd, pColor, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption, pNotes, pGantt)

      pID
      (required) a unique numeric ID used to identify each row
      pName
      (required) the task Label
      pStart
      (required) the task start date, can enter empty date ('') for groups. You can also enter specific time (2016-02-20 12:00) for additional precision.
      pEnd
      (required) the task end date, can enter empty date ('') for groups
      pClass
      (required) the css class for this task
      pLink
      (optional) any http link to be displayed in tool tip as the "More information" link.
      pMile
      (optional) indicates whether this is a milestone task - Numeric; 1 = milestone, 0 = not milestone
      pRes
      (optional) resource name
      pComp
      (required) completion percent, numeric
      pGroup
      (optional) indicates whether this is a group task (parent) - Numeric; 0 = normal task, 1 = standard group task, 2 = combined group task*
      pParent
      (required) identifies a parent pID, this causes this task to be a child of identified task. Numeric, top level tasks should have pParent set to 0
      pOpen
      (required) indicates whether a standard group task is open when chart is first drawn. Value must be set for all items but is only used by standard group tasks. Numeric, 1 = open, 0 = closed
      pDepend
      (optional) comma separated list of id's this task is dependent on. A line will be drawn from each listed task to this item
      Each id can optionally be followed by a dependency type suffix. Valid values are:
      'FS' - Finish to Start (default if suffix is omitted)
      'SF' - Start to Finish
      'SS' - Start to Start
      'FF' - Finish to Finish
      If present the suffix must be added directly to the id e.g. '123SS'
      pCaption
      (optional) caption that will be added after task bar if CaptionType set to "Caption"
      pNotes
      (optional) Detailed task information that will be displayed in tool tip for this task
      pGantt
      (required) javascript JSGantt.GanttChart object from which to take settings. Defaults to "g" for backwards compatibility

      * Combined group tasks show all sub-tasks on one row. The information displayed in the task list and row caption are taken from the parent task. Tool tips are generated individually for each sub-task from its own information. Milestones are not valid as sub-tasks of a combined group task and will not be displayed. No bounds checking of start and end dates of sub-tasks is performed therefore it is possible for these task bars to overlap. Dependencies can be set to and from sub-tasks only.

    2. using parseXML() with an external XML file
      JSGantt.parseXML("project.xml",g);
      

      Method definition: JSGantt.parseXML(pFile, pGanttObj)

      pFile
      (required) this is the filename of the XML
      pGanttObj
      (required) a GanttChart object returned by a call to JSGantt.GanttChart()

      The structure of the native XML file:

      Field definitions are as described for the parameters to TaskItem above. The pClass element is optional in XML files and will default to "ggroupblack" for group tasks, "gtaskblue" for normal tasks and "gmilestone" for milestones. The pGantt element is not required for XML import.

      JSGannt Improved will also test the provided XML file to see if it appears to be in Microsoft Project XML format. If so an attempt will be made to load up the project. This feature is experimental, the import is best effort and not guaranteed. Once loaded the project as interpreted by JSGantt Improved can be extracted using the XML Export methods provided.

    3. using parseXMLString() with XML held in a javascript string object
      JSGantt.parseXMLString("<project><task>...</task></project>",g);
      

      Method definition: JSGantt.parseXMLString(pStr, pGanttObj)

      pStr
      (required) this is a javascript String containing XML
      pGanttObj
      (required) a GanttChart object returned by a call to JSGantt.GanttChart()

      The XML provided will be parsed in exactly the same way as the contents of an external XML file and hence must match the format as described for JSGantt.parseXML() above

  7. Call Draw()

    g.Draw();
  8. Close the <script> block

    </script>

It is possible to add items to the chart in realtime via javascript using either direct method calls or additional XML files. It is also possible to delete tasks using RemoveTaskItem() method.

g.RemoveTaskItem(11);

Method definition: RemoveTaskItem(pID)

pID
(required) the unique numeric ID of the item to be removed

If the task removed is a group item, all child tasks will also be removed.

After adding or removing tasks a call to "g.Draw()" must be made to redraw the chart.

Configuration Options

Switches

Many of the features of jsGanttImproved can be customised through the use of setter methods available on the GanttChart object returned by a call to JSGantt.GanttChart()

The following options take a single numeric parameter; a value of 1 will enable the describe functionality, 0 will disable it

setUseToolTip()
Controls the display of tool tip boxes, defaults to 1 (enabled)
setUseFade()
Controls use of the fade effect when showing/hiding tool tips, defaults to 1 (enabled)
setUseMove()
Controls use of the sliding effect when changing between different task tool tips, defaults to 1 (enabled)
setUseRowHlt()
Controls the use of row mouseover highlighting, defaults to 1 (enabled)
setUseSort()
Controls whether the task list is sorted into parent task / start time order or is simply displayed in the order created, defaults to 1 (sort enabled)
setShowRes()
Controls whether the Resource column is displayed in the task list, defaults to 1 (show column)
setShowDur()
Controls whether the Task Duration column is displayed in the task list, defaults to 1 (show column)
setShowComp()
Controls whether the Percentage Complete column is displayed in the task list, defaults to 1 (show column)
setShowStartDate()
Controls whether the Task Start Date column is displayed in the task list, defaults to 1 (show column)
setShowEndDate()
Controls whether the Task End Date column is displayed in the task list, defaults to 1 (show column)
setShowTaskInfoRes()
Controls whether the Resource information is displayed in the task tool tip, defaults to 1 (show information)
setShowTaskInfoDur()
Controls whether the Task Duration information is displayed in the task tool tip, defaults to 1 (show information)
setShowTaskInfoComp()
Controls whether the Percentage Complete information is displayed in the task tool tip, defaults to 1 (show information)
setShowTaskInfoStartDate()
Controls whether the Task Start Date information is displayed in the task tool tip, defaults to 1 (show information)
setShowTaskInfoEndDate()
Controls whether the Task End Date information is displayed in the task tool tip, defaults to 1 (show information)
Controls whether the More Information link is displayed in the task tool tip, defaults to 0 (do NOT show link)
setShowTaskInfoNotes()
Controls whether the Additional Notes data is displayed in the task tool tip, defaults to 1 (show notes)
setShowEndWeekDate()
Controls whether the major heading in "Day" view displays the week end-date in the appropriate format (see below), defaults to 1 (show date)
setShowDeps()
Controls display of dependancy lines, defaults to 1 (show dependencies)

Key Values

The following options enable functionality using a set of specific key values

setShowSelector()
Controls where the format selector is displayed, accepts multiple parameters.
Valid parameter values are "Top", "Bottom".
Defaults to "Top".
setFormatArr()
Controls which format options are shown in the format selector, accepts multiple parameters.
Valid parameter values are "Hour", "Day", "Week", "Month", "Quarter".
Defaults to all valid values.
setCaptionType()
Controls which task field to use as a caption on the Gantt Chart task bar, accepts a single parameter.
Valid parameter values are "None", "Caption", "Resource", "Duration", "Complete".
Defaults to "None"
setDateInputFormat()
Defines the input format used for dates in task creation, accepts a single parameter.
Valid parameter values are "yyyy-mm-dd", "dd/mm/yyyy", "mm/dd/yyyy".
Defaults to "yyyy-mm-dd"
setScrollTo()
Sets the date the Gantt Chart will be scrolled to, specified in the date input format set by setDateInputFormat() above. Also accepts the special value "today"
Defaults to minimum display date
setUseSingleCell()
Sets the threshold total number of cells at which the task list will use a single table cell for each row rather than one cell per period. Useful to improve performance on large charts. A value of 0 disables this functionality (always use multiple cells), defaults to 25000
setLang()
Sets translation to use when drawing the chart. Defaults to "en" as this is the only language provided in the base installation (see Internationalisation below for details on how to add more translations.)

Layout

Most of the look and feel of the Gantt Chart can be controlled using CSS however, as the length of a task bar is determined by column width, the following methods take a single numeric parameter that defines the appropriate column width in pixels.

Note that the task bar sizing code assumes the use of collapsed table borders 1px wide.

setHourColWidth()
Width of Gantt Chart columns in pixels when drawn in "Hour" format. Defaults to 18.
setDayColWidth()
Width of Gantt Chart columns in pixels when drawn in "Day" format. Defaults to 18.
setWeekColWidth()
Width of Gantt Chart columns in pixels when drawn in "Week" format. Defaults to 36.
setMonthColWidth()
Width of Gantt Chart columns in pixels when drawn in "Month" format. Defaults to 36.
setQuarterColWidth()
Width of Gantt Chart columns in pixels when drawn in "Quarter" format, although not mandatory it is recommended that this be set to a value divisible by 3. Defaults to 18.
setRowHeight()
Height of Gantt Chart rows in pixels. Used to route dependency lines near end points. Defaults to 20.
setMinGpLen()
Group tasks have their task bars embellished with end points, this value specifies the width of one of these end points in pixels. A short task bar's length will be rounded up to display either a single or both endpoints correctly. Defaults to 8.

Display Date Formats

Date display formats can be individually controlled. The methods used to set these display formats each take a single format string parameter. The format string can be made up of the following components (case sensitive)

h
Hour (1-12)
hh
Hour (01-12)
pm
am/pm indicator
PM
AM/PM indicator
H
Hour (0-23)
HH
Hour (01-23)
mi
Minutes (1-59)
MI
Minutes (01-59)
d
Day (1-31)
dd
Day (01-31)
day
Abbriviated day of week
DAY
Day of week
m
Month (1-12)
mm
Month (01-12)
mon
Abbriviated month text
month
Full month text
yy
Year, excluding century
yyyy
Year
q
Quarter (1-4)
qq
Quarter (Q1-Q4)
w
ISO Week number (1-53)
ww
ISO Week number (01-53)
week
Full ISO Week date format

separated by one of the following characters: "/\-.,'<space>:

Any text between separators that does not match one of the components above will be checked using a case insensitive match for a valid internationalised string (see Internationalisation below). If the value is still not found the text will be output unchanged.

setDateTaskTableDisplayFormat()
Date format used for start and end dates in the main task list. Defaults to 'dd/mm/yyyy'.
setDateTaskDisplayFormat()
Date format used for start and end dates in task tool tips. Defaults to 'dd month yyyy'.
setHourMajorDateDisplayFormat()
Date format used for Gantt Chart major date headings displayed in "Hour" format. Defaults to 'day dd month yyyy'.
setDayMajorDateDisplayFormat()
Date format used for Gantt Chart major date headings displayed in "Day" format. Defaults to 'dd/mm/yyyy'.
setWeekMajorDateDisplayFormat()
Date format used for Gantt Chart major date headings displayed in "Week" format. Defaults to 'yyyy'.
setMonthMajorDateDisplayFormat()
Date format used for Gantt Chart major date headings displayed in "Month" format. Defaults to 'yyyy'.
setQuarterMajorDateDisplayFormat()
Date format used for Gantt Chart major date headings displayed in "Year" format. Defaults to 'yyyy'.
setHourMinorDateDisplayFormat()
Date format used for Gantt Chart minor date headings displayed in "Hour" format. Defaults to 'HH'.
setDayMinorDateDisplayFormat()
Date format used for Gantt Chart minor date headings displayed in "Day" format. Defaults to 'dd'.
setWeekMinjorDateDisplayFormat()
Date format used for Gantt Chart minor date headings displayed in "Week" format. Defaults to 'dd/mm'.
setMonthMinorDateDisplayFormat()
Date format used for Gantt Chart minor date headings displayed in "Month" format. Defaults to 'mon'.
setQuarterMinorDateDisplayFormat()
Date format used for Gantt Chart minor date headings displayed in "Year" format. Defaults to 'qq'.

Internationalisation

jsGanttImproved only provides English text however all hard coded strings can be replaced by calling the addLang() method available on the GanttChart object returned by a call to JSGantt.GanttChart()

The addLang() method takes two parameters. The first is a string identifier for the language, the second is a javascript object containing all the replacement text pairs, the default English settings are:

january
January
february
February
march
March
april
April
maylong
May
june
June
july
July
august
August
september
September
october
October
november
November
december
December
jan
Jan
feb
Feb
mar
Mar
apr
Apr
may
May
jun
Jun
jul
Jul
aug
Aug
sep
Sep
oct
Oct
nov
Nov
dec
Dec
sunday
Sunday
monday
Monday
tuesday
Tuesday
wednesday
Wednesday
thursday
Thursday
friday
Friday
saturday
Saturday
sun
Sun
mon
Mon
tue
Tue
wed
Wed
thu
Thu
fri
Fri
sat
Sat
resource
Resource
duration
Duration
comp
% Comp.
completion
Completion
startdate
Start Date
enddate
End Date
moreinfo
More Information
notes
Notes
format
Format
hour
Hour
day
Day
week
Week
month
Month
quarter
Quarter
hours
Hours
days
Days
weeks
Weeks
months
Months
quarters
Quarters
hr
Hr
dy
Day
wk
Wk
mth
Mth
qtr
Qtr
hrs
Hrs
dys
Days
wks
Wks
mths
Mths
qtrs
Qtrs

When adding a language any translations that are not provided will use the default English language value. This provides a simple way to override default strings e.g.

g.addLang('en2', {'format':'Select', 'comp':'Complete'});

would create a language called 'en2' where the text in the format selector was "Select" rather than "Format" and the header for the Percentage Complete column in the task list is "Complete" rather than "% Comp."

Once a translation has been added a call must be made to setLang() with the appropriate langage identifier before calling Draw().

Example Options

The configuration options used in the example chart above are:

g.setCaptionType('Complete');  // Set to Show Caption (None,Caption,Resource,Duration,Complete)
g.setQuarterColWidth(36);
g.setDateTaskDisplayFormat('day dd month yyyy'); // Shown in tool tip box
g.setDayMajorDateDisplayFormat('mon yyyy - Week ww'); // Set format to display dates in the "Major" header of the "Day" view
g.setWeekMinorDateDisplayFormat('dd mon'); // Set format to display dates in the "Minor" header of the "Week" view
g.setShowTaskInfoLink(1); //Show link in tool tip (0/1)
g.setShowEndWeekDate(0); // Show/Hide the date for the last day of the week in header for daily view (1/0)
g.setUseSingleCell(10000); // Set the threshold at which we will only use one cell per table row (0 disables).  Helps with rendering performance for large charts.
g.setFormatArr('Day', 'Week', 'Month', 'Quarter'); // Even with setUseSingleCell using Hour format on such a large chart can cause issues in some browsers

Putting all this information together the final code to produce the chart above is as follows:

XML Export

The following methods can be used to extract details of tasks in the project in XML format

Method definition: getXMLProject()

Returns a string containing the entire project in JSGantt Improved XML format. Dates will be exported in the currently defined input format as set by setDateInputFormat()

Method definition: getXMLTask(pID, pIdx)

pID
(required) the numeric ID that identifies the task to extract
pIdx
(optional) Boolean - if present and set to "true" the number passed in the pID parameter is treated as an array index for the task list rather than an ID

Returns a string containing the specified task item in JSGantt Improved XML format. Dates will be exported in the currently defined input format as set by setDateInputFormat()

Additional Demos

Credits

Developed by Paul Geldart

Based on jsGantt 1.2 developed by Shlomy Gantz and Brian Twidt
Contributed: Paul Labuschagne, Kevin Badgett, Ilan Admon