Gantt chart API reference

Documentation about the Gantt chart including information about all of the options that are available to you. The Gantt chart is commonly used to show scheduling information regarding timetables for people or events. There's a demo that shows an interactive Gantt chart.

Example

<script>
    new RGraph.Gantt({
        id: 'cvs',
        data: [
            {start: 31,  duration: 28, complete: null, label: 'Richard', background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 31,  duration: 28, complete: null, label: 'Fred',    background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 59,  duration: 14, complete: null, label: 'Barney',  background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 59,  duration: 21, complete: null, label: 'Gloria',  background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 59,  duration: 31, complete: null, label: 'Paul',    background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 80,  duration: 21, complete: null, label: 'Harry',   background: null, color: null  border: 'rgba(0,0,0,0)'],
            {start: 94,  duration: 7,  complete: null, label: 'Shane',   background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 120, duration: 14, complete: null, label: 'Barry',   background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 130, duration: 14, complete: null, label: 'Cynthia', background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 211, duration: 61, complete: null, label: 'Graham',  background: null, color: null, border: 'rgba(0,0,0,0)'],
            {start: 334, duration: 31, complete: null, label: 'Paul',    background: null, color: null, border: 'rgba(0,0,0,0)']
        ],
        options: {
            xaxisScaleMax: 365,
            marginLeft: 75,
            xaxisLabels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            title: 'Holiday schedule for Xyz Ltd',
            colorsDefault: 'rgba(255,0,0,1)',
            tooltips: [
                "<b>Richard</b><br />Richard is going on holiday.<br />He'll be away for 28 days.",
                "<b>Fred</b><br />Fred is also going away for 28 days",
                "<b>Barney</b><br />Barney is off work for two weeks",
                "<b>Gloria</b><br />Gloria is off work for 3 weeks",
                "<b>Paul</b><br /> Away for 31 days",
                "<b>Harry</b><br />Away for three weeks",
                "<b>Shane</b><br />Away for one week",
                "<b>Barry</b><br />Away for two weeks",
                "<b>Cynthia</b><br />Away for two weeks",
                "<b>Graham</b><br />Away for August and September",
                "<b>Paul</b><br />Away for 31 days"
            ],
            backgroundVbars: [
                [0, 31, 'rgba(192,255,192,0.5)'],
                [59, 31, 'rgba(192,255,192,0.5)'],
                [120, 31, 'rgba(192,255,192,0.5)'],
                [181, 31, 'rgba(192,255,192,0.5)'],
                [243, 30, 'rgba(192,255,192,0.5)'],
                [304, 30, 'rgba(192,255,192,0.5)']
            ]
        }
    }).draw();
</script>

Properties

You can use these properties to control how the chart appears. You can set them by including them in the options section of the configuration as above.

Background properties

PropertyDescriptionDefault
backgroundBarsCountThe number of background bars.5
backgroundBarsColor1Color of the background bars.white
backgroundBarsColor2Color of the background bars.white
backgroundGridWhether a grid is shown as part of the background.true
backgroundGridColorThe color of the background grid.#eee
backgroundGridLinewidthThe line width of the background grid.1
backgroundGridVlinesCountWhen using autofit this allows you to specify how many vertical grid lines you want.20
backgroundGridDottedIf you want to have your background grid dashed then set this to true.false
backgroundGridDashedIf you want to have your background grid dotted then set this to true. This takes precedence over dashed lines.false
backgroundVbarsVertical bars used for decorative purposes, or for marking something on the chart (an event for example). See below for further information.[] (An empty array)
backgroundHbarsHorizontal bars used for decorative purposes, or for marking something on the chart (an event for example). See below for further information.[] (An empty array)
backgroundColorIf you want to have a single background color for your chart you can use this. It doesn't cover the margins. If you want that then you can simply apply a CSS background color to the canvas tag.null

X axis properties

PropertyDescriptionDefault
xaxisScaleMaxRequired. This determines how many "units" wide the Gantt chart is. For example to represent a year, you would use 365, giving a granularity of one day.none
xaxisScaleMinThis option can sometimes make using a Gantt chart spread over several pages easier.0
xaxisLabelsWith the Gantt chart the labels are given as part of the data array. See the example code above.Not applicable
xaxisLabelsFontThe font used to render the text.null
xaxisLabelsSizeThe size of the text.null
xaxisLabelsColorThe color of the X axis labels.null
xaxisLabelsBoldWhether the X axis labels are bold or not.null
xaxisLabelsItalicWhether the X axis labels are italic or not.null
xaxisLabelsAlignThis determines whether the horizontal labels are drawn at the top (underneath the title) or at the bottom (in the bottom margin).bottom
xaxisTitleThe title used for the X axis title.null
xaxisTitleXBy giving this you can specifically set the X position of the X axis title.null
xaxisTitleYBy giving this you can specifically set the Y position of the X axis title.null
xaxisTitleFontThe font used to render the X axis title.null
xaxisTitleSizeThe size of the X axis title.null
xaxisTitleColorThis controls the color of the X axis title.null
xaxisTitleBoldWhether the X axis title is bold or not.null
xaxisTitleItalicWhether the X axis title is italic or not.null

Y axis properties

PropertyDescriptionDefault
yaxisTitleThe title of the Gantt chart.null
yaxisTitleFontThe font that the Y axis title is rendered in.null
yaxisTitleSizeThe size of the Y axis title.null
yaxisTitleColorThe color of the Y axis title.null
yaxisTitleBoldWhether the Y axis title is bold or not.null
yaxisTitleItalicWhether the Y axis title is italic or not.null
yaxisTitleXBy giving this you can specifically set the X position of the Y axis title.null
yaxisTitleYBy giving this you can specifically set the Y position of the Y axis title.null
yaxisLabelsFontThe font used to render the Y axis labels.null
yaxisLabelsSizeThe size of the Y axis labels.null
yaxisLabelsColorThe color of the Y axis labels.null
yaxisLabelsBoldWhether the Y axis labels are bold or not.null
yaxisLabelsItalicWhether the Y axis labels are italic or not.null

Color properties

PropertyDescriptionDefault
colorsDefaultThe default color of bars. If you don't specify a color for the event, this will be used.white

Margin properties

PropertyDescriptionDefault
marginLeftThe left margin of the chart, (the margin is where the labels and title are)).25
marginRightThe right margin of the chart, (the margin is where the labels and title are).25
marginTopThe top margin of the chart, (the margin is where the labels and title are).25
marginBottomThe bottom margin of the chart, (the margin is where the labels and title are).25
vmarginActs much like the hmargin setting for the bar chart. By using this setting you can give yourself thin bars.2

Labels and text properties

PropertyDescriptionDefault
textAccessibleA new feature in 2016 that allows you to use DOM text in place of canvas text. It makes for much higher quality text that you can also select if desired (for copy/paste operations). It won't fit all situations and you can read more about the DOM text feature here. A good way to control borders/margins/padding etc is not to set them on the canvas but to wrap the canvas in a div and set them on that like this:
<div style="margin-left: 50px; display: inline-block">
<canvas id="cvs" width="650" height="250"></canvas>
</div>
true
textAccessibleOverflowThis can be visible or hidden and it controls whether the text is clipped to the edges of the canvas. It defaults to be visible and means you can set small margins if you wish.visible
textAccessiblePointereventsThis controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).false
textSizeThe size of the text (in points).12
textFontThe font used to render the text.Arial, Verdana, sans-serif
textColorThe color of the labels.black
textBoldWhether the text on the chart is bold or not.false
textItalicWhether the text on the chart is italic or not.false
labelsInbarAn array of labels that are drawn inside the Gantt chart bars. These labels can also be drawn on the right of these bars.null
labelsInbarAlignThis controls whether the labels are aligned left, center or right when the labels are drawn inside the bars.left
labelsInbarBgcolorThe background color for the text. By default there's no background to the text.null
labelsInbarColorThe color of the labels.null
labelsInbarFontThe font used to draw the labels.null
labelsInbarSizeThe size of the text labels.null
labelsInbarBoldWhether the inbar labels are bold or not.null
labelsInbarItalicWhether the inbar labels are italic or not.null
labelsInbarAboveIf you prefer, the labels can be drawn "above" the bars (actually to the right but for API compatibility it's called "above").false
labelsCompleteThis allows you to turn off the "percent complete" indicator if you want to.true
labelsCompleteFontThe font used to render the percent-complete number.null
labelsCompleteSizeThe size of the text.null
labelsCompleteColorThe color of the text.null
labelsCompleteBoldWhether the text is bold or not.null
labelsCompleteItalicWhether the text is italic or not.null

Title properties

PropertyDescriptionDefault
titleThe title of the chart.not set
titleFontThe font that the title is rendered in. If not specified the textFont setting is used (usually Arial).null
titleSizeThe size of the title. If not specified the size is usually 2pt bigger than the textSize setting.null
titleBoldWhether the title is bold or not.true
titleItalicWhether the title is italic or not.false
titleColorThe color of the title.black
titleBackgroundThe background color (if any) for the title.null
titleXTo give the exact X coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.null
titleYTo give the exact Y coordinate for the title - use this. This can also be a string like this: "-5" -- in which case it's converted to a number and added to the calculated coordinate - allowing you to adjust the calculated coordinate.null

Interactive features properties

PropertyDescriptionDefault
tooltipsAn array of tooltips that are shown when the bars are clicked. They can contain HTML.(An empty array)
tooltipsEventThis is the event that triggers the tooltips. It can be either onclick or onmousemove.onclick
tooltipsEffectThe effect used for showing tooltips. Can be either fade or none.fade
tooltipsCssClassThis is the name of the CSS class the chart uses.RGraph_tooltip
tooltipsOverrideIf you wish to handle showing tooltips yourself, this should be a function object which does just that. There's more information on the tooltips documentation page.null
tooltipsNohideonclearNot an option that you'll need particularly often if at all. Setting this to true means that when you call the RGraph.clear() API function tooltips DO NOT get hidden.false
contextmenuAn array of context menu items. Cannot be used in conjunction with tooltips.(An empty array)
annotatableWhether annotations are enabled for the chart (ie you can draw on the chart interactively.false
annotatableColorIf you do not allow the use of the palette, then this will be the only colour allowed for annotations.black
annotatableLinewidthThis is the line width of the annotations.1
resizableDefaulting to false, this determines whether your chart will be resizable. Because of the numerous event handlers this has to install code on, This feature is unlikely to work with other dynamic features (the context menu is fine however).false
resizableHandleBackgroundWith this you can specify the background color for the resize handle. If you're adjusting the position of the handle then you may need this to make the handle stand out more.null
resizableMinwidthThis allows you to set a minimum width that the chart can be resized to.null
resizableMinheightThis allows you to set a minimum height that the chart can be resized to.null
resizableMaxwidthThis allows you to set a maximum width that the chart can be resized to.null
resizableMaxheightThis allows you to set a maximum height that the chart can be resized to.null
adjustableDefaulting to false, this determines whether your bar chart will be adjustable.false
adjustableOnlyThis should be an array of values that determine whether a Bar is adjustable or not. A truthy value for when it is, a falsey value for when it's not.null

Event properties

PropertyDescriptionDefault
eventsClickIf you want to add your own onclick function you can do so by assigning it to this property. See here for details.null
eventsMousemoveIf you want to add your own onmousemove function you can do so by assigning it to this property. See here for details.null
eventsMouseoverIf you want to add your own onmouseover function you can do so by assigning it to this property. See here for details.null
eventsMouseoutIf you want to add your own onmouseout function you can do so by assigning it to this property. See here for details.null

Miscellaneous properties

PropertyDescriptionDefault
highlightStyleBy default this is null but you can set it to a function if you wish so that function is called to do the chart highlighting. Its passed the shape object as an argument.null
highlightStrokeIf you use tooltips, this controls the colour of the highlight stroke.black
highlightFillIf you use tooltips, this controls the colour of the highlight fill.rgba(255,255,255,0.5)
bordersWhether a border is shown on the event bars.true
cleartoThis is used in animations and effects as the default color to use when the canvas is cleared.null


Methods

obj.get(name)

An accessor function that you can use to retrieve the values of properties.

obj.set(name, value)

An accessor that you can use to set the values of properties.

obj.getShape(event)

This method returns the details of a focused bar (ie clicked or hovered over). It returns:

The shape also includes textual indexes like this: shape['object'] And they are:

obj.getXCoord(value)

This method can be used to get an appropriate X coordinate for a value when you're doing custom drawing on the chart. It returns null if the value is out of range.

obj.getValue(mixed)

This method can be used to get the value when the chart has been clicked on. The argument is the event object. You can also use this method outside of an event listener by giving the function an array as the argument containing the X/Y coordinates.

obj.canvas.onclick = function (e)
{
    var obj   = e.target.__object__;
    var value = obj.getValue(e);
    
    // ...
}
obj.on(event, function)

This method can be used to set an event listener on an object. It operates in a similar way to the jQuery on() function. The first argument is the event you wish to attach to and the second is the handler function. For example:

.on('draw', function (obj)
{
    // Put event code here
});
The exec option and method

The exec function is documented here.

Adding events (the information represented on the chart) to your Gantt chart

To add events (the information represented on the chart), you now specify them as an argument to the constructor - it's no longer the events property.

myGantt = new RGraph.Gantt({
        id: 'cvs',
        data: [
            {start: 31, duration: 28, complete: 75, label: 'Richard'},
            {start: 12, duration: 28, complete: 67, label: 'Fred'},
            {start: 59, duration: 14, complete: 0,  label: 'Barney'},
            {start: 59, duration: 21, complete: 5,  label: 'Gloria'},
            {start: 46, duration: 31, complete: 94, label: 'Paul'}]
            {start: 80, duration: 21, complete: 46, label: 'Harry'},
            {start: 94, duration: 17, complete: 84, label: 'Shane'},
            {start: 34, duration: 14, complete: 32, label: 'Barry'},
            {start: 64, duration: 14, complete: 28, label: 'Cynthia', background: 'red', color: 'yellow'},
            {start: 13, duration: 61, complete: 74, label: 'Graham'},
            {start: 84, duration: 31, complete: 16, label: 'Paul'}
        ],
        options: {
        }
    );

The start value is the (zero indexed) start number relative to your xaxisScaleMax value. So if you have set your xaxisScaleMax to 62, (to represent two months), and this value is 31, the start will be the start of the second month. In this case you could give two labels - ['July', 'August'].

The duration value is the duration. So using the previous example, if you set this to 7, you would have an event lasting a week.

The complete value is the "percentage complete" indicator. This is shown to the right of the event and is optional - you can specify null if you wish.

The label value is the label that is used on the left hand side.

The optional background value stipulates the background colour that the bar is. The default is white.

The optional color value is the foreground color of the bar. This defaults to #0c0.

The optional border value is the border colour, defaulting to black

And the optional linewidth value is the numerical linewidth of the border. The default for this is 1.

Adding vertical and horizontal bars to your Gantt chart

You can add decorative vertical or horizontal bars like so:

...
vbars: [
    [0,   31, 'rgba(192,255,192,0.5)'],
    [59,  31, 'rgba(192,255,192,0.5)'],
    [120, 31, 'rgba(192,255,192,0.5)'],
    [181, 31, 'rgba(192,255,192,0.5)'],
    [243, 30, 'rgba(192,255,192,0.5)'],
    [304, 30, 'rgba(192,255,192,0.5)'],
],
hbars: [,'red',,,,'green'],
...

You can use these for decorative purposes, or to mark events/limits. For the vertical bars the first value is the start index, the same as above. The second value is the unit length, again, the same as above. The third value is the colour of the vertical bar.

And for the horizontal bars you just specify the colour of the bar - they automatically extend across the entire Gantt chart area. If you don't specify a colour (as is demonstrated above) then there won't be a bar for that entry.

Animation effects

These effects are available and can be used instead of the draw() function. There are also generic effects available which you can see here: Generic effects and transitions
<script>
    /**
    * Optional callback function that's called when the effect is complete
    */
    function myCallback (obj)
    {
        // ...
    }

    var obj = new RGraph.Gantt({
        id: 'cvs',
        data: [
            {start: 0,  duration: 30},
            {start: 30, duration: 60},
            {start: 60, duration: 90}
        ],
        options: {
            marginLeft: 35,
            xaxisScaleMax: 90
        }
    }).grow({frames: 60}, myCallback)
</script>