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
// data tree settings
4
var treeData = anychart.data.tree(getData(), anychart.enums.TreeFillingMethod.AS_TREE);
5
6
// chart type
7
var chart = anychart.ganttProject();
8
9
// chart container
10
chart.container("container");
11
12
// chart position
13
chart.bounds(0, 0, "100%", "100%");
14
15
// chart data
16
chart.data(treeData);
17
18
// data tree width
19
chart.splitterPosition(190);
20
21
var dataGrid = chart.dataGrid();
22
23
// settings for first column
24
dataGrid.column(0).width(30).title().text("#");
25
26
// settings for the second column
27
dataGrid.column(1).width(140).format(function(item) {
28
return item.get("name");
29
}).title().text("Plan");
30
31
// initiate drawing
32
chart.draw();
33
34
// area to display by default
35
chart.zoomTo(Date.UTC(2007, 0, 1), Date.UTC(2007, 2, 29));
36
37
var expandAllButton = document.createElement("div");
38
var collapseAllButton = document.createElement("div");
39
var expandLast = document.createElement("div");
40
var collapseLast = document.createElement("div");
41
42
expandAllButton.className = "custombutton";
43
collapseAllButton.className = "custombutton";
44
expandLast.className = "custombutton";
45
collapseLast.className = "custombutton";
46
47
expandAllButton.innerHTML = "expand all";
48
collapseAllButton.innerHTML = "collapse all";
49
expandLast.innerHTML = "expand 5";
50
collapseLast.innerHTML = "collapse 5";
51
52
expandAllButton.onclick = function() {
53
chart.expandAll();
54
};
55
collapseAllButton.onclick = function() {
56
chart.collapseAll();
57
};
58
expandLast.onclick = function() {
59
chart.expandTask("5");
60
};
61
collapseLast.onclick = function() {
62
chart.collapseTask("5");
63
};
64
65
// append button to container
66
container.appendChild(collapseLast);
67
container.appendChild(expandLast);
68
container.appendChild(collapseAllButton);
69
container.appendChild(expandAllButton);
70
71
var custombuttons = document.getElementsByClassName("custombutton");
72
73
// set style for all buttons
74
for (var i = 0; i<custombuttons.length; i++){
75
// set button style
76
custombuttons[i].style.top = "210px";
77
custombuttons[i].style.left = 170*i + "px";
78
custombuttons[i].style.width = "165px";
79
custombuttons[i].style.height = "auto";
80
custombuttons[i].style.backgroundColor = "white";
81
custombuttons[i].style.color = "black";
82
custombuttons[i].style.fontFamily = chart.title().fontFamily();
83
custombuttons[i].style.position = "absolute";
84
custombuttons[i].style.zIndex = 2;
85
custombuttons[i].style.transition = "0.5s";
86
custombuttons[i].style.textAlign = "center";
87
custombuttons[i].style.border = "2px solid #444444";
88
custombuttons[i].style.borderRadius = "7px 7px 7px 7px";
89
custombuttons[i].style.fontSize = "18px";
90
custombuttons[i].style.cursor = "pointer";
91
}
92
93
});
94
95
// data
96
function getData() {
97
return [
98
{
99
"name": "Activities",
100
"actualStart": Date.UTC(2007, 0, 25),
101
"actualEnd": Date.UTC(2007, 2, 14),
102
"children": [
103
{
104
"name": "Draft plan",
105
"actualStart": Date.UTC(2007, 0, 25),
106
"actualEnd": Date.UTC(2007, 1, 3)
107
},
108
{
109
"name": "Board meeting",
110
"actualStart": Date.UTC(2007, 1, 4),
111
"actualEnd": Date.UTC(2007, 1, 4)
112
},
113
{
114
"name": "Research option",
115
"actualStart": Date.UTC(2007, 1, 4),
116
"actualEnd": Date.UTC(2007, 1, 24)
117
},
118
{
119
"id": "5",
120
"name": "Innovation activities",
121
"actualStart": Date.UTC(2007, 1, 24),
122
"actualEnd": Date.UTC(2007, 2, 14),
123
"children": [
124
{
125
"name": "Improvement research",
126
"actualStart": Date.UTC(2007, 1, 24),
127
"actualEnd": Date.UTC(2007, 2, 14)
128
}
129
]
130
},
131
]
132
}
133
];
134
}