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
var newData = getNewData();
3
4
//create data tree on our data
5
var treeData = anychart.data.tree(newData, anychart.enums.TreeFillingMethod.AS_TABLE);
6
7
//create project gantt chart
8
var chart = anychart.ganttProject();
9
chart.title('Click on the row and change the title');
10
11
//set container id for the chart
12
chart.container('container');
13
14
//set data for the chart
15
chart.data(treeData);
16
17
//set start splitter position settings
18
chart.splitterPosition(200);
19
20
//get chart data grid link to set column settings
21
var dataGrid = chart.dataGrid();
22
23
//set first column settings
24
var firstColumn = dataGrid.column(1);
25
firstColumn.title('System Engineering');
26
firstColumn.width(140);
27
firstColumn.cellTextSettings().hAlign('left');
28
firstColumn.format(function(item) {
29
return item.get('name');
30
});
31
firstColumn.cellTextSettingsOverrider(labelTextSettingsOverrider);
32
33
34
//initiate chart drawing
35
chart.draw();
36
37
chart.zoomTo(Date.UTC(2008, 0, 31, 1, 36), Date.UTC(2008, 1, 15, 10, 3));
38
39
//--------------------------------------------------
40
// External events
41
//--------------------------------------------------
42
chart.listen(anychart.enums.EventType.ROW_CLICK, function(e) {
43
msg = anychart.enums.EventType.ROW_CLICK + ': ' + e['item'].get('name'); // create a string from the information got by using listeners that will be placed in the Chart Title
44
chart.title(msg);
45
});
46
47
});
48
49
50
51
function labelTextSettingsOverrider(label, item) {
52
switch (item.get('type')) {
53
case 'main':
54
label.fontColor('red').fontWeight('bold');
55
break;
56
case 'first':
57
label.fontColor('green').fontWeight('bold');
58
break;
59
case 'second':
60
label.fontColor('orange').fontWeight('bold');
61
break;
62
}
63
}
64
65
66
function getNewData() {
67
return [
68
{
69
'id': '1',
70
'name': 'Project Management',
71
'rowHeight': 22,
72
'collapsed': false,
73
'type': 'main'
74
},
75
{
76
'id': '2',
77
'name': 'Design and engineer',
78
'parent': '1',
79
'type': 'first',
80
'rowHeight': 30,
81
'progressValue': '80%',
82
'actualStart': Date.UTC(2008, 0, 30, 16, 0),
83
'actualEnd': Date.UTC(2008, 1, 4, 14, 18),
84
'connectTo': '3',
85
'connectorType': 'FinishStart'
86
},
87
{
88
'id': '3',
89
'name': 'Obtain permits',
90
'parent': '1',
91
'type': 'second',
92
'rowHeight': 30,
93
'progressValue': '20%',
94
'actualStart': Date.UTC(2008, 0, 31, 0, 47),
95
'actualEnd': Date.UTC(2008, 1, 5, 14, 18),
96
'connectTo': '5',
97
'connectorType': 'FinishStart'
98
},
99
{
100
'id': '4',
101
'name': 'Structural installation',
102
'rowHeight': 22,
103
'progressValue': '50%',
104
'collapsed': true,
105
'type': 'main'
106
},
107
{
108
'id': '5',
109
'name': 'Install roof attachments',
110
'parent': '4',
111
'type': 'first',
112
'rowHeight': 30,
113
'progressValue': '30%',
114
'actualStart': Date.UTC(2008, 1, 5, 14, 18),
115
'actualEnd': Date.UTC(2008, 1, 7, 14, 18),
116
'connectTo': '6',
117
'connectorType': 'FinishStart'
118
},
119
{
120
'id': '6',
121
'name': 'Assemble racking',
122
'parent': '4',
123
'type': 'second',
124
'rowHeight': 30,
125
'progressValue': '10%',
126
'actualStart': Date.UTC(2008, 1, 6, 0, 47),
127
'actualEnd': Date.UTC(2008, 1, 10, 14, 18)
128
}
129
130
];
131
}