RGraph: HTML5 canvas graph library - Gantt chart documentation

The Gantt chart can be used to easily represent schedules, making visualising this information far more straightfoward.

Example

The example file is here.

<script>
    window.onload = function ()
    {
        var gantt = new RGraph.Gantt('gantt');
        gantt.Set('chart.xmax', 365);
        gantt.Set('chart.gutter', 35);
        gantt.Set('chart.labels', ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
        gantt.Set('chart.title', 'Holiday schedule for Xyz Ltd');
        gantt.Set('chart.defaultcolor', 'rgba(255,0,0,1)');
        gantt.Set('chart.tooltips', ["<b>Richard</b><br />Richard is going on holiday to Malta.<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"]);
        gantt.Set('chart.events'[
                                 [31, 28, null, 'Richard'],
                                 [31, 28, null, 'Fred'],
                                 [59, 14, null, 'Barney'],
                                 [59, 21, null, 'Gloria'],
                                 [59, 31, null, 'Paul'],
                                 [80, 21, null, 'Harry'],
                                 [94, 7, null, 'Shane'],
                                 [120, 14, null, 'Barry'],
                                 [130, 14, null, 'Cynthia'],
                                 [211, 61, null, 'Graham'],
                                 [334, 31, null, 'Paul'],
                                ]);
        gantt.Set('chart.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)'],
                                 ]);
    
        gantt.Draw();
    }
</script>

Available properties

You can use these properties to control how the bar graph apears.

chart.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
chart.background.barcolor1 Color of the background bars
Default: white
chart.background.barcolor2 Color of the background bars
Default: white
chart.background.grid Whether a grid is shown as part of the background
Default: true
chart.background.grid.color The color of the background grid.
Default: #eee
chart.background.grid.hsize The size of the horizontal grid.
Default: 20
chart.background.grid.vsize The size of the vertical grid.
Default: 20
chart.background.grid.width The line width of the background grid.
Default: 1
chart.gutter How big the gutter is. This is the top, bottom and right gutters. The left gutter is three times the gutter wide, to accomodate the labels.
Default: 25
chart.text.size The size of the text (in points).
Default: 10
chart.text.font The font used to render the text.
Default: Verdana
chart.text.color The color of the labels.
Default: black
chart.title The title of the chart.
Default: not set
chart.title.color The color of the title.
Default: black
chart.title.vpos This allows you to completely override the vertical positioning of the title. It should be a number between 0 and 1, and is multiplied with the gutter and then used as the vertical position. It can be useful if you need to have a large gutter.
Default: null
chart.labels An array of the labels which are applied to the chart.
Default: [] (An empty array)
chart.tooltips An array of tooltips that are shown when the bars are clicked. They can contain HTML.
Default: [] (An empty array)
chart.tooltip.effect The animated effect used for showing tooltips. Can be either fade or expand.
Default: fade
chart.borders Whether a border is shown on the event bars
Default: true
chart.defaultcolor The default color of bars. If you don't specify a color for the event, this will be used.
Default: white
chart.events An array of event information that is displayed on the gantt. See below for further information.
Default: [] (An empty array)
chart.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)
chart.contextmenu An array of context menu items. Cannot be used in conjunction with tooltips.
Default: [] (An empty array)
chart.annotatable Whether annotations are enabled for the chart (ie you can draw on the chart interactively.
Default: false
chart.annotate.color If you do not allow the use of the palette, then this will be the only colour allowed for annotations.
Default: black
chart.zoom.mode Can be used to control whether the zoom is in thumbnail or canvas mode. Possible values are: thumbnail and canvas.
Default: canvas
chart.zoom.factor This is the factor that the graph will be zoomed by (bigger values means more zoom)
Default: 1.5
chart.zoom.fade.in 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
chart.zoom.fade.out 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
chart.zoom.hdir The horizontal direction of the zoom. Possible values are: left, center, right
Default: right
chart.zoom.vdir The vertical direction of the zoom. Possible values are: up, center, down
Default: down
chart.zoom.delay The delay (in milliseconds) between frames.
Default: 50
chart.zoom.frames The number of frames in the zoom animation.
Default: 10
chart.zoom.shadow Whether or not the zoomed canvas has a shadow or not.
Default: true
chart.zoom.thumbnail.width When the zoom is in thumbnail mode, this is the width (in pixels) of the thumbnail.
Default: 75
chart.zoom.thumbnail.height When the zoom is in thumbnail mode, this is the height (in pixels) of the thumbnail.
Default: 75


Adding events to your Gantt chart

To add events, you specify them using the chart.events property. You could use the following to set some events on your gantt chart:

gantt.Set('chart.events', [
                       [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']
                      ]);

The first value is the (zero indexed) start number relative to your chart.xmax. So if you have set your chart.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.

And the last optional 6th value is the foreground color of the bar. Defaulting to #0c0.

Adding vertical bars to your Gantt chart

You can add decorative vertical bars like so:

gantt.Set('chart.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)'],
                   ]);

You can use these for decorative purposes, or to mark events/limits. 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.