# Gantt charts documentation

- Example
- Properties
- Methods
- Adding events to your Gantt charts
- Adding vertical bars to your Gantt charts

## Example

    <script>
        window.onload = function ()
        {
            // Create the Gantt chart. Note that unlike other OfficeExcel charts the actual data is NOT
            // given as part of the constructor.
            var gantt = new OfficeExcel.Gantt('gantt');

            // Configure the chart to appear as you want.
            gantt.Set('chart.xmax', 365);
            gantt.Set('chart.gutter.left', 75);
            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"]);

            // This is where the events that appear on the Gantt chart are given. You can read about the
            // format below.
            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)']
                                     ]);

            // Now call the .Draw() method to draw the chart.
            gantt.Draw();
        }
    </script>

The example file is here.

## Properties

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

- Chart configuration
- Background
- Margins
- Labels and text
- Titles
- Interactive features
- Zoom
- Events
- Miscellaneous

### Chart configuration

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.xmin
This option can sometimes make using a Gantt chart spread over several pages easier.
Default: 0

### Background

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.background.grid.autofit
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
chart.background.grid.autofit.numhlines
When using autofit this allows you to specify how many horizontal grid lines you want.
Default: 7
chart.background.grid.autofit.numvlines
When using autofit this allows you to specify how many vertical grid lines you want.
Default: 20

### Margins

chart.gutter.left
The left gutter of the chart, (the gutter is where the labels and title are)).
Default: 75
chart.gutter.right
The right gutter of the chart, (the gutter is where the labels and title are).
Default: 25
chart.gutter.top
The top gutter of the chart, (the gutter is where the labels and title are).
Default: 25
chart.gutter.bottom
The bottom gutter of the chart, (the gutter is where the labels and title are).
Default: 25

### Labels and text

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.labels
An array of the labels which are applied to the chart.
Default: [] (An empty array)
chart.labels.align
This determines whether the horizontal labels are drawn at the top (underneath the title) or at the bottom (in the bottom gutter).
Default: top

### Titles

chart.title
The title of the chart.
Default: not set
chart.title.font
The font that the title is rendered in. If not specified the chart.text.font setting is used (usually Verdana)
Default: null
chart.title.size
The size of the title. If not specified the size is usually 2pt bigger than the chart.text.size setting.
Default: null
chart.title.bold
Whather the title is bold or not.
Default: true
chart.title.background
The background color (if any) for the title.
Default: null
chart.title.color
The color of the title.
Default: black
chart.title.hpos
This allows you to completely override the horizontal positioning of the title. It should be a number between 0 and 1, and is multiplied with the whole width of the canvas and then used as the horizontal position.
Default: null
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

### Interactive features

chart.tooltips
An array of tooltips that are shown when the bars are clicked. They can contain HTML.
Default: [] (An empty array)
chart.tooltips.event
This is the event that triggers the tooltips. It can be either onclick or onmousemove.
Default: onclick
chart.tooltips.effect
The animated effect used for showing tooltips. Can be either fade or expand.
Default: fade
chart.tooltips.css.class
This is the name of the CSS class the chart uses.
Default: OfficeExcel_tooltip
chart.tooltips.override
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
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.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
chart.resize.handle.background
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

### Zoom

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 chart 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
chart.zoom.thumbnail.fixed
When the zoom is in thumbnail mode, you can use this property to fix the zoom in the top left corner instead of it following the cursor around.
Default: false
chart.zoom.background
Defaulting to true, this determines whether the zoom has a dark, semi-opaque background that covers the entire web page.
Default: true

### Events

chart.events.click
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
chart.events.mousemove
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

### Miscellaneous

chart.highlight.stroke
If you use tooltips, this controls the colour of the highlight stroke.
Default: black
chart.highlight.fill
If you use tooltips, this controls the colour of the highlight fill.
Default: rgba(255,255,255,0.5)
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)

## Methods

obj.getBar(event)

This method returns the details of a focused bar (ie clicked or mouseover'ed. It returns:

- The chart object
- The X coordinate
- The Y coordinate
- The width of the bar
- The height of the bar
- The index of the bar (starting from 0)

obj.getShape(event)

This method is an alternate name for the above method but has a generic name that is the same acoss the various libraries.

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

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