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
// create data
4
var data = [
5
{
6
id: "A",
7
name: "Location A",
8
children: [
9
{
10
id: "1",
11
name: "Server 1",
12
periods: [
13
{id: "1_1", start: "2018-01-05", end: "2018-01-25"},
14
{id: "1_2", start: "2018-01-28", end: "2018-02-22"},
15
{id: "1_3", start: "2018-03-03", end: "2018-03-25"}
16
],
17
disc_space: "5 TB"
18
},
19
{
20
id: "2",
21
name: "Server 2",
22
periods: [
23
{id: "2_1", start: "2018-01-07", end: "2018-02-15"},
24
{id: "2_2", start: "2018-02-26", end: "2018-03-20"}
25
],
26
disc_space: "7 TB"
27
}
28
]},
29
{
30
id: "B",
31
name: "Location B",
32
children: [
33
{
34
id: "3",
35
name: "Server 3",
36
periods: [
37
{id: "3_1", start: "2018-01-04", end: "2018-03-25"}
38
],
39
disc_space: "9 TB"
40
}
41
]}
42
];
43
44
// create a data tree
45
var treeData = anychart.data.tree(data, "as-tree");
46
47
// create a chart
48
var chart = anychart.ganttResource();
49
50
// set the data
51
chart.data(treeData);
52
53
// configure tooltips of the timeline
54
55
chart.getTimeline().tooltip().useHtml(true);
56
57
chart.getTimeline().tooltip().format(function() {
58
59
var numChildren = this.item.numChildren();
60
var duration = (this.end - this.start) / 1000 / 3600 / 24;
61
var startDate = anychart.format.dateTime(this.start, "dd MMM");
62
var endDate = anychart.format.dateTime(this.end, "dd MMM");
63
var discSpace = this.getData("disc_space");
64
65
var parentText = "Number of Servers: " + numChildren;
66
67
var childText = "<span style='font-weight:600;font-size:12pt'>" +
68
startDate + " - " + endDate + "</span><br><br>" +
69
"Duration: " + duration + " days<br>" +
70
"Disc Space: " + discSpace;
71
72
// identify the resource type and display the corresponding text
73
if (numChildren > 0) {
74
return parentText;
75
} else {
76
return childText;
77
}
78
79
});
80
81
// set the container id
82
chart.container("container");
83
84
// initiate drawing the chart
85
chart.draw();
86
87
// fit elements to the width of the timeline
88
chart.fitAll();
89
});