Gantt charts documentation

Share RGraph:   

 

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.

 

Chart configuration

xmax
Required. 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.
Default: none

xmin
This option can sometimes make using a Gantt chart spread over several pages easier.
Default: 0

 

Background

backgroundBarcolor1
Color of the background bars
Default: white

backgroundBarcolor2
Color of the background bars
Default: white

backgroundGrid
Whether a grid is shown as part of the background
Default: true

backgroundGridColor
The color of the background grid.
Default: #eee

backgroundGridHsize
The size of the horizontal grid.
Default: 20

backgroundGridVsize
The size of the vertical grid.
Default: 20

backgroundGridWidth
The line width of the background grid.
Default: 1

backgroundGridAutofit
Instead of specifying a pixel width/height for the background grid, you can use autofit and specify how many horizontal and vertical lines you want.
Default: true

backgroundGridAutofitNumhlines
When using autofit this allows you to specify how many horizontal grid lines you want.
Default: 7

backgroundGridAutofitNumvlines
When using autofit this allows you to specify how many vertical grid lines you want.
Default: 20

backgroundGridDotted
If you want to have your background grid dashed then set this to true.
Default: false

backgroundGridDashed
If you want to have your background grid dotted then set this to true. This takes precedence over dashed lines.
Default: false

backgroundColor
If 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.
Default: null

 

Margins

gutterLeft
The left gutter of the chart, (the gutter is where the labels and title are)).
Default: 25

gutterRight
The right gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterTop
The top gutter of the chart, (the gutter is where the labels and title are).
Default: 25

gutterBottom
The bottom gutter of the chart, (the gutter is where the labels and title are).
Default: 25

vmargin
Acts much like the hmargin setting for the bar chart. By using this setting you can give yourself thin bars.
Default: 2

 

Labels and text

textAccessible
A 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>

Default: true

textAccessibleOverflow
This 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.
Default: visible

textAccessiblePointerevents
This controls whether the DOM text responds to mouse based events or not (it sets the pointer-events CSS property to none).
Default: true

textSize
The size of the text (in points).
Default: 10

textFont
The font used to render the text.
Default: Arial

textColor
The color of the labels.
Default: black

labels
An array of the labels which are applied to the chart.
Default: [] (An empty array)

labelsColor
The color of the labels
Default: null (same as textColor)

labelsPercent
This allows you to turn off the percent indicator if you want to.
Default: true

labelsAlign
This determines whether the horizontal labels are drawn at the top (underneath the title) or at the bottom (in the bottom gutter).
Default: top

labelsInbar
An array of labels that are drawn inside the Gantt chart bars. These labels can also be drawn on the right of these bars.
Default: null

labelsInbarAlign
This controls whether the labels are aligned left, center or right when the labels are drawn inside the bars.
Default: left

labelsInbarBgcolor
The background color for the text. By default there's no background to the text.
Default: null

labelsInbarColor
The color of the labels.
Default: black

labelsInbarFont
The font used to draw the labels.
Default: Arial

labelsInbarSize
The size of the text labels.
Default: 10

labelsInbarAbove
If you prefer, the labels can be drawn "above" the bars (actually to the right but for API compatibility it's called "above").
Default: false

 

Titles

title
The title of the chart.
Default: not set

titleFont
The font that the title is rendered in. If not specified the text.font setting is used (usually Arial)
Default: null

titleSize
The size of the title. If not specified the size is usually 2pt bigger than the text.size setting.
Default: null

titleBold
Whether the title is bold or not.
Default: true

titleItalic
Whether the title is italic or not.
Default: false

titleBackground
The background color (if any) for the title.
Default: null

titleColor
The color of the title.
Default: black

titleX
To give the exact X coordinate for the title - use this
Default: null

titleY
To give the exact Y coordinate for the title - use this
Default: null

titleXaxisX
By giving this you can specifically set the X position of the X axis title
Default: null

titleXaxisY
By giving this you can specifically set the Y position of the X axis title
Default: null

titleYaxisX
By giving this you can specifically set the X position of the Y axis title
Default: null

titleYaxisY
By giving this you can specifically set the Y position of the Y axis title
Default: null

 

Interactive features

tooltips
An array of tooltips that are shown when the bars are clicked. They can contain HTML.
Default: (An empty array)

tooltipsEvent
This is the event that triggers the tooltips. It can be either onclick or onmousemove.
Default: onclick

tooltipsEffect
The effect used for showing tooltips. Can be either fade or none.
Default: fade

tooltipsCssClass
This is the name of the CSS class the chart uses.
Default: RGraph_tooltip

tooltipsOverride
If 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
Default: null

tooltipsCoordsPage
If set to true the tooltips will be positioned using the .pageX and .pageY coordinates. If you use canvas tags that are offset from the .pageX and .pageY coordinates - this can help with tooltip positioning.
Default: false

tooltipsNohideonclear
Not 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.
Default: false

contextmenu
An array of context menu items. Cannot be used in conjunction with tooltips.
Default: (An empty array)

annotatable
Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false

annotateColor
If you do not allow the use of the palette, then this will be the only colour allowed for annotations.
Default: black

annotateLinewidth
This is the line width of the annotations.
Default: 1

resizable
Defaulting 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).
Default: false

resizeHandleBackground
With 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.
Default: null

resizableMaxwidth
This allows you to set a maximum width that the chart can be resized to.
Default: null

resizableMaxheight
This allows you to set a maximum height that the chart can be resized to.
Default: null

 

Zoom

zoomFactor
This is the factor that the chart will be zoomed by (bigger values means more zoom)
Default: 1.5

zoomFadeIn
Whether the zoomed canvas fades in or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomFadeOut
Whether the zoomed canvas fades out or not. This also can be used to control the fade in for the zoom in thumbnail mode.
Default: true

zoomHdir
The horizontal direction of the zoom. Possible values are: left, center, right
Default: right

zoomVdir
The vertical direction of the zoom. Possible values are: up, center, down
Default: down

zoomDelay
The delay (in milliseconds) between frames.
Default: 50

zoomFrames
The number of frames in the zoom animation.
Default: 10

zoomShadow
Whether or not the zoomed canvas has a shadow or not.
Default: true

 

Events

eventsClick
If you want to add your own onclick function you can do so by assigning it to this property. See here for details.
Default: null

eventsMousemove
If you want to add your own onmousemove function you can do so by assigning it to this property. See here for details.
Default: null

eventsMouseover
If you want to add your own onmouseover function you can do so by assigning it to this property. See here for details.
Default: null

 

miscellaneous

highlightStyle
By 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.
Default: null

highlightStroke
If you use tooltips, this controls the colour of the highlight stroke.
Default: black

highlightFill
If you use tooltips, this controls the colour of the highlight fill.
Default: rgba(255,255,255,0.5)

borders
Whether a border is shown on the event bars
Default: true

defaultcolor
The default color of bars. If you don't specify a color for the event, this will be used.
Default: white

vbars
Vertical bars used for decorative purposes, or for marking something on the chart (an event for example). See below for further information.
Default: [] (An empty array)

hbars
Horizontal bars used for decorative purposes, or for marking something on the chart (an event for example). See below for further information.
Default: [] (An empty array)

clearto
This is used in animations and effects as the default color to use when the canvas.
Default: 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>

Comments

Add a new comment...