HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function(){
2
3
// chart data
4
var rawData = [{id: 1, name: 'Foundation', actualStart: '2107-02-06', actualEnd: '2107-02-15', connectTo: 2, connectorType: 'FinishStart'},
5
{id: 2, name: 'Walls', actualStart: '2107-02-16', actualEnd: '2107-02-20', connectTo: 3, connectorType: 'StartStart'},
6
{id: 3, name: 'Roof', actualStart: '2107-02-28', actualEnd: '2107-03-10', connectTo: 4, connectorType: 'FinishFinish'},
7
{id: 4, name: 'Plumbing', actualStart: '2107-03-15', actualEnd: '2107-03-25', connectTo: 5, connectorType: 'StartFinish'},
8
{id: 5, name: 'Wallpapers', actualStart: '2107-02-28', actualEnd: '2107-03-10'}];
9
10
// create a data tree
11
var treeData = anychart.data.tree(rawData, anychart.enums.TreeFillingMethod.AS_TABLE);
12
13
// create project gantt chart
14
var chart = anychart.ganttProject();
15
16
// set data for the chart
17
chart.data(treeData);
18
19
// set the original chart title
20
chart.title('Click on the connectors to get the information');
21
22
// enable Gantt editing
23
chart.editing(true);
24
25
// listen to the connectorclick event and change the title
26
chart.listen('connectorclick', function(e){
27
chart.title(e.fromItem.get('name') + ' to ' + e.toItem.get('name') + ': ' + e.connType);
28
});
29
30
// make connectors thicker
31
chart.getTimeline().connectorStroke('#455A64', 3);
32
33
// set row height
34
chart.defaultRowHeight(45);
35
36
// set width for the datagrid
37
dataGrid = chart.dataGrid();
38
dataGrid.column(0).width(10);
39
dataGrid.column(1).width(140);
40
41
// set pixel position of the main splitter
42
chart.splitterPosition(150);
43
44
// disable labels and tooltips
45
chart.getTimeline().labels().enabled(false);
46
chart.getTimeline().tooltip().enabled(false);
47
dataGrid.tooltip().enabled(false);
48
49
// set container id for the chart
50
chart.container('container');
51
// initiate chart drawing
52
chart.draw();
53
54
// zoom chart to to all elements
55
chart.fitAll();
56
});