Gantt charts documentation

Share RGraph:   Share or Like RGraph on Facebook!

 

Example

<script>
    // Create the Gantt chart. Note the (October 2012) change in how the events data is specified.
    // You now give the data as an argument to the constructor.
    var gantt = new RGraph.Gantt({
        id: 'cvs',
        data: [
            [31, 28, null, 'Richard', null, null, 'rgba(0,0,0,0)'],
            [31, 28, null, 'Fred', null, null, 'rgba(0,0,0,0)'],
            [59, 14, null, 'Barney', null, null, 'rgba(0,0,0,0)'],
            [59, 21, null, 'Gloria', null, null, 'rgba(0,0,0,0)'],
            [59, 31, null, 'Paul', null, null, 'rgba(0,0,0,0)'],
            [80, 21, null, 'Harry', null, null, 'rgba(0,0,0,0)'],
            [94, 7, null, 'Shane', null, null, 'rgba(0,0,0,0)'],
            [120, 14, null, 'Barry', null, null, 'rgba(0,0,0,0)'],
            [130, 14, null, 'Cynthia', null, null, 'rgba(0,0,0,0)'],
            [211, 61, null, 'Graham', null, null, 'rgba(0,0,0,0)'],
            [334, 31, null, 'Paul', null, null, 'rgba(0,0,0,0)']
        ],
        options: {
            xmax: 365,
            gutterleft: 75,
            labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            title: 'Holiday schedule for Xyz Ltd',
            defaultcolor: '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 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"
            ],
            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)']
            ]
        }
    }).draw();
</script>

The example file is here.

 

Properties

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

Layout style:     
  

Chart configuration

PropertyDescriptionDefault
xmaxRequired. 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
xminThis option can sometimes make using a Gantt chart spread over several pages easier.0

Background

PropertyDescriptionDefault
backgroundBarcolor1Color of the background barswhite
backgroundBarcolor2Color of the background barswhite
backgroundGridWhether a grid is shown as part of the backgroundtrue
backgroundGridColorThe color of the background grid.#eee
backgroundGridHsizeThe size of the horizontal grid.20
backgroundGridVsizeThe size of the vertical grid.20
backgroundGridWidthThe line width of the background grid.1
backgroundGridAutofitInstead of specifying a pixel width/height for the background grid, you can use autofit and specify how many horizontal and vertical lines you want.true
backgroundGridAutofitNumhlinesWhen using autofit this allows you to specify how many horizontal grid lines you want.7
backgroundGridAutofitNumvlinesWhen 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
backgroundColorIf you want to have a single background color for your chart you can use this. It doesn't cover the gutters. If you want that then you can simply apply a CSS background color to the canvas tag.null

Margins

PropertyDescriptionDefault
gutterLeftThe left gutter of the chart, (the gutter is where the labels and title are)).25
gutterRightThe right gutter of the chart, (the gutter is where the labels and title are).25
gutterTopThe top gutter of the chart, (the gutter is where the labels and title are).25
gutterBottomThe bottom gutter of the chart, (the gutter 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

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 gutters 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).true
textSizeThe size of the text (in points).10
textFontThe font used to render the text.Arial
textColorThe color of the labels.black
labelsAn array of the labels which are applied to the chart.[] (An empty array)
labelsColorThe color of the labelsnull (same as textColor)
labelsPercentThis allows you to turn off the percent indicator if you want to.true
labelsAlignThis determines whether the horizontal labels are drawn at the top (underneath the title) or at the bottom (in the bottom gutter).top
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.black
labelsInbarFontThe font used to draw the labels.Arial
labelsInbarSizeThe size of the text labels.10
labelsInbarAboveIf you prefer, the labels can be drawn "above" the bars (actually to the right but for API compatibility it's called "above").false

Titles

PropertyDescriptionDefault
titleThe title of the chart.not set
titleFontThe font that the title is rendered in. If not specified the text.font setting is used (usually Arial)null
titleSizeThe size of the title. If not specified the size is usually 2pt bigger than the text.size setting.null
titleBoldWhether the title is bold or not.true
titleItalicWhether the title is italic or not.false
titleBackgroundThe background color (if any) for the title.null
titleColorThe color of the title.black
titleXTo give the exact X coordinate for the title - use thisnull
titleYTo give the exact Y coordinate for the title - use thisnull
titleXaxisXBy giving this you can specifically set the X position of the X axis titlenull
titleXaxisYBy giving this you can specifically set the Y position of the X axis titlenull
titleXaxisColorThis controls the color of the X axis title.black
titleYaxisXBy giving this you can specifically set the X position of the Y axis titlenull
titleYaxisYBy giving this you can specifically set the Y position of the Y axis titlenull

Interactive features

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 pagenull
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 tooltip 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
annotateColorIf you do not allow the use of the palette, then this will be the only colour allowed for annotations.black
annotateLinewidthThis 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
resizeHandleBackgroundWith 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 its not.null

Zoom

PropertyDescriptionDefault
zoomFactorThis is the factor that the chart will be zoomed by (bigger values means more zoom)1.5
zoomFadeInWhether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomFadeOutWhether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.true
zoomHdirThe horizontal direction of the zoom. Possible values are: left, center, rightright
zoomVdirThe vertical direction of the zoom. Possible values are: up, center, downdown
zoomDelayThe delay (in milliseconds) between frames.50
zoomFramesThe number of frames in the zoom animation.10
zoomShadowWhether or not the zoomed canvas has a shadow or not.true

Events

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

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 barstrue
defaultcolorThe default color of bars. If you don't specify a color for the event, this will be used.white
vbarsVertical bars used for decorative purposes, or for marking something on the chart (an event for example). See below for further information.[] (An empty array)
hbarsHorizontal bars used for decorative purposes, or for marking something on the chart (an event for example). See below for further information.[] (An empty array)
cleartoThis is used in animations and effects as the default color to use when the canvas.null


 

Methods

 

obj.get(name)

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

 

obj.set(name, value)

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

 

obj.getShape(event)

This method returns the details of a focused bar (ie clicked or mouseover'ed. 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, func)

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 - NOT the events property.

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

The first value is the (zero indexed) start number relative to your xmax. So if you have set your xmax 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 second value is the duration. So using the previous example, if you set this to 7, you would have an event lasting a week.

The third 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 fourth value is the label that is used on the left hand side.

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

The optional sixth value is the foreground color of the bar. Defaulting to #0c0.

The optional seventh value is the border color, defaulting to black

And the optional eigth value is the numerical linewidth of the border. The default 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, as above. The second value is the unit length, again as above. The third value is the color of the vertical bar.

And for the horizontal bars you just specify the color of the bar - they automatically extend across the entire gant chart area. If you don't specify a color (as 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: [[0,30],[30,60],[60,90]],
        options: {
            gutterLeft: 35,
            max: 90
        }
    }).grow({frames: 60}, myCallback)
</script>