Skip to content

Latest commit

 

History

History
590 lines (477 loc) · 32.2 KB

Documentation.md

File metadata and controls

590 lines (477 loc) · 32.2 KB

Usage

Creating a basic Gantt Chart

Include JSGantt CSS and Javascript

<link href="jsgantt.css" rel="stylesheet" type="text/css"/>
<script src="jsgantt.js" type="text/javascript"></script>

Create a div element to hold the gantt chart

<div style="position:relative" class="gantt" id="GanttChartDIV"></div>

Start a <script> block

<script type="text/javascript">

Instantiate JSGantt using GanttChart()

var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'day');

Method definition: GanttChart(pDiv, pFormat)

Parameter Description
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

Customize the look and feel using configuration methods

see Configuration Options below

Add Tasks

a) Using Method()

Using g.AddTaskItemObject method we have to pass all data in "key":"value" format, as shown below. Any numerica data, like pID below should be passed without quotes while text/character data like pName and any dates must be enclosed in quotes. Also, in this way we can pass any custom variables like "category" and "section" shown below. Adding such custom variables will NOT add corresponding columns in the data table on left side of gantt chart. Such custom variables can be then accessed inside jsgantt.js file by using task.getDataObject().yourCustomAttr.

If you want to have custom variables data to be shown in the task table, you should set additional headers for these variables. See Additional Headers below.

// passing object
g.AddTaskItemObject({
  pID: 1,
  pName: "Define Chart <strong>API</strong>",
  pStart: "2017-02-25",
  pEnd: "2017-03-17",
  pPlanStart: "2017-04-01",
  pPlanEnd: "2017-04-15 12:00",
  pClass: "ggroupblack",
  pLink: "",
  pMile: 0,
  pRes: "Brian",
  pComp: 0,
  pGroup: 0,
  pParent: 0,
  pOpen: 1,
  pDepend: "",
  pCaption: "",
  pCost: 1000,
  pNotes: "Some Notes text",
  pBarText: "ex. bar text",
  category: "My Category",
  sector: "Finance"
});

// or passing parameters
g.AddTaskItem(new JSGantt.TaskItem(1, 'Define Chart API','',          '',          'ggroupblack','', 0, 'Brian', 0,  1,0,1,'','','Some Notes text',g));

Method definition: TaskItem(pID, pName, pStart, pEnd, pClass, pLink, pMile, pRes, pComp, pGroup, pParent, pOpen, pDepend, pCaption, pNotes, pGantt, pCost = null, pPlanStart = null, pPlanEnd = null, pDuration = null, pBarText = null, pDataObject = null, pPlanClass = null)

This method takes only the variables defined above and explained below. You can NOT pass custom variables this way.

Parameter Description
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 (e.g. 2013-02-20 09:00) for additional precision or half days
pEnd: (required) the task end date, can enter empty date ('') for groups
pPlanStart: (required) the planed task start date, can enter empty date ('') for groups. You can also enter specific time (e.g. 2013-02-20 09:00) for additional precision or half days
pPlanEnd: (required) the task end date planned, 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
pCost: cost of that task, numeric
pBarText: (optional) Use to include text inside a task bar
pPlanClass: (optional) the css class for planned date of this task

* 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.

b) using parseJSON() with an external JSON file or API

JSGantt.parseJSON('./fixes/data.json', g);

This function returns a promise if you would like to do an event after the json is loaded.

The structure of the JSON file:

{
  "pID": 1,
  "pName": "Define Chart API",
  "pStart": "",
  "pEnd": "",
  "pPlanStart": "",
  "pPlanEnd": "",
  "pClass": "ggroupblack",
  "pLink": "",
  "pMile": 0,
  "pRes": "Brian",
  "pComp": 0,
  "pGroup": 1,
  "pParent": 0,
  "pOpen": 1,
  "pDepend": "",
  "pCaption": "",
  "pCost":  "",
  "pNotes": "Some Notes text",
  "pBarText": "ex. bar text",
  "category": "My Category",
  "sector": "Finance"
}

c) using parseXML() with an external XML file

JSGantt.parseXML("project.xml",g);

Method definition: JSGantt.parseXML(pFile, pGanttObj)

Parameter Description
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:

<project>
<task>
	<pID>25</pID>
	<pName>WCF Changes</pName>
	<pStart></pStart>
	<pEnd></pEnd>
  <pPlanStart></pPlanStart>
	<pPlanEnd></PlanEnd>
	<pClass>gtaskred</pClass>
	<pLink></pLink>
	<pMile>0</pMile>
	<pRes></pRes>
	<pComp>0</pComp>
	<pGroup>1</pGroup>
	<pParent>2</pParent>
	<pOpen>1</pOpen>
  <pCost></pCost>
	<pDepend>2,24</pDepend>
	<pCaption>A caption</pCaption>
	<pNotes>Text - can include limited HTML</pNotes>
  <pPlanClass>gtaskblue</pPlanClass>
</task>
</project>

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.

c) using parseXMLString() with XML held in a javascript string object

JSGantt.parseXMLString("<project><task>...</task></project>",g);

Method definition: JSGantt.parseXML(pStr, pGanttObj)

Parameter Description
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 parseXML above

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)

Parameter Description
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().

Call Draw()

g.Draw();

Updating an existing Gantt Chart

It is also possible to delete tasks using RemoveTaskItem() method.

g.RemoveTaskItem(11);

Method definition: RemoveTaskItem(pID)

Parameter Description
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.

ClearTasks()

This method will clear al the tasks from the list and after that you have to call "g.Draw()".

Drawing custom elements on the chart

If you want to draw something custom in addition to task bars you may find following useful:

  1. Put your drawing call in afterDraw callback. It's called in the end of each Draw call so view will mostly stay in sync. There you can get task row elements with g.getList()[...].getChildRow() and add HTML you need.
  2. Use g.chartRowDateToX(date) to get X coordinate for a date.
  3. If custom drawings go beyond min/max task dates - extend chart range with vMinDate/vMaxDate chart options.
  4. See example in demo with Custom elements flag.

Options

You can set Options as an object, following the example:

g.setOptions({
  vCaptionType: 'Complete',       
  vQuarterColWidth: 36
});

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

Method Description
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)
setShowPlanStartDate(): Controls whether the Plan Task Start Date column is displayed in the task list, defaults to 1 (show column)
setShowPlanEndDate(): Controls whether the Task Plan End Date column is displayed in the task list, defaults to 1 (show column)
setShowCost(): Controls whether the Cost column is displayed in the task list, defaults to 1 (show column)
setAdditionalHeaders(): Set the object with additional headers to be displayed in the data table. ex : { category: { title: 'Category' } }
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)
setShowTaskInfoLink(): 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)
setShowWeekends(): Controls whether shows the weekend days in the Day view Format, defaults to 1 (show weekends)
setShowDeps(): Controls display of dependancy lines, defaults to 1 (show dependencies)
setEvents(): Controls events when a task is click in table data. You have to pass an object with the column and function. If the user click in the header, the event willbe triggered btu instead of the task will be a object about the header. ex.: vEvents: { taskname: console.log, res: console.log }
setEventClickRow(): Controls events when a task row is clicked. Pass a function to execute ex.: vEventClickRow: function(e){console.log(e)}
setEventClickCollapse():_ Controls events when a group task is collapsed (open or close events). Pass a function to execute ex.: vEventClickCollapse: function(e){console.log(e)}
setEventsChange(): Controls events when a task row is cliked. Pass a function to execute ex.: vEventsChange: { taskname: function(task, event, cell, column){ console.log(task, event, cell, column); } }
setAdditionalHeaders: Set object with headers values for additional columns . ex : { category: { title: 'Category' } }
setColumnOrder: Set order of the columns that will be displayed, the default value is : [ 'vShowRes','vShowDur','vShowComp','vShowStartDate','vShowEndDate','vShowPlanStartDate','vShowPlanEndDate','vShowCost','vAdditionalHeaders','vShowAddEntries'] }
setResources(): Set the list of possible resources, must be an array of objects, ex: [{ id: 1, name: 'Mario' } , { id: 2, name: 'Henrique' }]
setCustomLang(): Set custom language vars, ex: {'january': 'My January text'}
setTotalHeight(): Set component height as CSS height (e.g. "300px"). If set - the header is fixed and content is scrollable if needed. Otherwise component height is defined by content
setMinDate(): Set minimum date further than minimum task date. It doesn't trim any task if it starts before this minimum date, but can extend the chart to the left. This may be useful if you want to draw some custom elements on the chart or want to fix the time range regardless of the content
setMaxDate(): Similar to setMinDate()
setTooltipTemplate(): Set template for the tooltip. Can be
  • string - just a static template
  • function(task): string - function returning template for a given task
  • function(task): Promise<string> - function returning promise resolving to string. Until promise is resolved tooltip shows tooltipLoading from lang section
In each case variables inside string are substituted (see example). If function is given and it returns undefined or null - default template is used (like if argument was not passed at all). Function argument is evaluated when tooltip needs to be shown.
setEditable(): Set with true if you want to edit values in the data table, will show inputs instead of texts
setDebug(): Set with true if you want to see debug in console

Key Values

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

Method Description
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() or in a JS Date format. 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. Numeric, 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.

Method Description
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)

Component Description
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.

The available date display methods are

Method Description
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'.
setWeekMinorDateDisplayFormat(): 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:

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

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 language identifier before calling Draw().

Example Options

The configuration options used in the example index file provided are:

g.setOptions({
  vCaptionType: 'Complete',  // Set to Show Caption : None,Caption,Resource,Duration,Complete,     
  vQuarterColWidth: 36,
  vDateTaskDisplayFormat: 'day dd month yyyy', // Shown in tool tip box
  vDayMajorDateDisplayFormat: 'mon yyyy - Week ww',// Set format to display dates in the "Major" header of the "Day" view
  vWeekMinorDateDisplayFormat: 'dd mon', // Set format to display dates in the "Minor" header of the "Week" view
  vLang: lang,
  vShowTaskInfoLink: 1, // Show link in tool tip (0/1)
  vShowEndWeekDate: 0,  // Show/Hide the date for the last day of the week in header for daily view (1/0)
  vUseSingleCell: 10000, // Set the threshold at which we will only use one cell per table row (0 disables).  Helps with rendering performance for large charts.
  vFormatArr: ['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 included in the example index file provided is as follows:

<link href="jsgantt.css" rel="stylesheet" type="text/css"/>
<script src="jsgantt.js" type="text/javascript"></script>

<div style="position:relative" class="gantt" id="GanttChartDIV"></div>

<script>

var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'day');

g.setOptions({
  vCaptionType: 'Complete',  // Set to Show Caption : None,Caption,Resource,Duration,Complete,     
  vQuarterColWidth: 36,
  vDateTaskDisplayFormat: 'day dd month yyyy', // Shown in tool tip box
  vDayMajorDateDisplayFormat: 'mon yyyy - Week ww',// Set format to display dates in the "Major" header of the "Day" view
  vWeekMinorDateDisplayFormat: 'dd mon', // Set format to display dates in the "Minor" header of the "Week" view
  vLang: lang,
  vAdditionalHeaders: { // Add data columns to your table
    category: {
      title: 'Category'
    },
    sector: {
      title: 'Sector'
    }
  },
  vShowTaskInfoLink: 1, // Show link in tool tip (0/1)
  vShowEndWeekDate: 0,  // Show/Hide the date for the last day of the week in header for daily view (1/0)
  vUseSingleCell: 10000, // Set the threshold at which we will only use one cell per table row (0 disables).  Helps with rendering performance for large charts.
  vFormatArr: ['Day', 'Week', 'Month', 'Quarter'], // Even with setUseSingleCell using Hour format on such a large chart can cause issues in some browsers
  vScrollTo: new Date(),

  // EVENTS

  // OnChangee
  vEventsChange: {
    taskname: console.log,
    res: console.log,
  },
  // EventsClickCell
  vEvents: {
    taskname: console.log,
    res: console.log,
    dur: console.log,
    comp: console.log,
    start: console.log,
    end: console.log,
    planstart: console.log,
    planend: console.log,
    cost: console.log,
    additional_category: console.log, // for additional fields
    beforeDraw: ()=>console.log('before draw listener'),
    afterDraw: ()=>console.log('before after listener')
  },
  vEventClickRow: console.log,
  vEventClickCollapse: console.log
});

// Load from a Json url
JSGantt.parseJSON('./fixes/data.json', g);

// Or Adding  Manually
g.AddTaskItemObject({
  pID: 1,
  pName: "Define Chart <strong>API</strong>",
  pStart: "2017-02-25",
  pEnd: "2017-03-17",
  pPlanStart: "2017-04-01",
  pPlanEnd: "2017-04-15 12:00",
  pClass: "ggroupblack",
  pLink: "",
  pMile: 0,
  pRes: "Brian",
  pComp: 0,
  pGroup: 1,
  pParent: 0,
  pOpen: 1,
  pDepend: "",
  pCaption: "",
  pCost: 1000,
  pNotes: "Some Notes text",
  pBarText: "ex. bar text",
  category: "My Category",
  sector: "Finance"
});

g.Draw();

</script>

Printing

g.printChart(width, height); will set the page size (via an injected css) and trigger the browser's print. The default injected style can be changed by passing a different style as the 3rd parameter to printChart.

The default style is:

 @page {
    size: ${width}mm ${height}mm;
  }
  .gchartcontainer {
    width: ${width}mm;
  }

Troubleshooting

  • My grid has a few/lot of columns and i want to resize the space for the chart and data

You can change the CSS and choose the size:

.gmainright{
	width: 75%;
}
.gmainleft{
	width: 25%;
}

Reference: #157

  • Table headers are missing when vTotalHeight is set

There's a piece of code to calculate scrollbar size, which creates a temporary div in body.

Some styles may mess with this div and cause incorrect calculation.

This temp div has class gscrollbar-calculation-container, so if you have top level styles you can't controll - you may add styles to this class to fix scrollbar calculation.