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
// create data tree on our data
3
var treeData = anychart.data.tree(getData(), anychart.enums.TreeFillingMethod.AS_TABLE);
4
5
// create resource gantt chart
6
var chart = anychart.ganttResource();
7
8
// set container id for the chart
9
chart.container("container");
10
11
// set data for the chart
12
chart.data(treeData);
13
14
// set start splitter position settings
15
chart.splitterPosition(160);
16
17
// get chart data grid link to set column settings
18
var dataGrid = chart.dataGrid();
19
20
var expandAllButton = document.createElement("div");
21
var collapseAllButton = document.createElement("div");
22
var expandLast = document.createElement("div");
23
var collapseLast = document.createElement("div");
24
25
expandAllButton.className = "custombutton";
26
collapseAllButton.className = "custombutton";
27
expandLast.className = "custombutton";
28
collapseLast.className = "custombutton";
29
30
expandAllButton.innerHTML = "expand all";
31
collapseAllButton.innerHTML = "collapse all";
32
expandLast.innerHTML = "expand 4";
33
collapseLast.innerHTML = "collapse 4";
34
35
expandAllButton.onclick = function() {
36
chart.expandAll();
37
};
38
collapseAllButton.onclick = function() {
39
chart.collapseAll();
40
};
41
expandLast.onclick = function() {
42
chart.expandTask("409");
43
};
44
collapseLast.onclick = function() {
45
chart.collapseTask("409");
46
};
47
48
// append button to container
49
container.appendChild(collapseLast);
50
container.appendChild(expandLast);
51
container.appendChild(collapseAllButton);
52
container.appendChild(expandAllButton);
53
54
var custombuttons = document.getElementsByClassName("custombutton");
55
56
// set style for all buttons
57
for (var i = 0; i<custombuttons.length; i++){
58
// set button style
59
custombuttons[i].style.top = "177px";
60
custombuttons[i].style.left = 170*i + "px";
61
custombuttons[i].style.width = "165px";
62
custombuttons[i].style.height = "auto";
63
custombuttons[i].style.backgroundColor = "white";
64
custombuttons[i].style.color = "black";
65
custombuttons[i].style.fontFamily = chart.title().fontFamily();
66
custombuttons[i].style.position = "absolute";
67
custombuttons[i].style.zIndex = 2;
68
custombuttons[i].style.transition = "0.5s";
69
custombuttons[i].style.textAlign = "center";
70
custombuttons[i].style.border = "2px solid #444444";
71
custombuttons[i].style.borderRadius = "7px 7px 7px 7px";
72
custombuttons[i].style.fontSize = "18px";
73
custombuttons[i].style.cursor = "pointer";
74
}
75
76
// initiate chart drawing
77
chart.draw();
78
79
// zoom chart to specified date
80
chart.fitAll();
81
});
82
83
function getData() {
84
return [
85
{
86
"id":"404",
87
"name": "office 404"
88
},
89
{
90
"id":"409",
91
"name": "office 409"
92
},
93
{
94
"id": "1",
95
"name": "Server 1",
96
"parent": "404",
97
"periods": [
98
{"id": "1_1", "start": Date.UTC(2013, 1, 20), "end": Date.UTC(2013, 1, 25)},
99
{"id": "1_2", "start": Date.UTC(2013, 2, 2), "end": Date.UTC(2013, 2, 15)},
100
{"id": "1_2", "start": Date.UTC(2013, 2, 20), "end": Date.UTC(2013, 3, 1)}
101
]
102
},
103
{
104
"id": "2",
105
"name": "Server 2",
106
"parent": "404",
107
"periods": [
108
{"id": "2_1", "start": Date.UTC(2013, 1, 20), "end": Date.UTC(2013, 1, 22)},
109
{"id": "2_2", "start": Date.UTC(2013, 1, 25), "end": Date.UTC(2013, 2, 5)}
110
]
111
},
112
{
113
"id": "3",
114
"name": "Server 3",
115
"parent": "409",
116
"periods": [
117
{"id": "3_1", "start": Date.UTC(2013, 2, 10), "end": Date.UTC(2013, 2, 22)},
118
{"id": "3_2", "start": Date.UTC(2013, 2, 25), "end": Date.UTC(2013, 3, 5)}
119
]
120
}
121
];
122
}