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 data grid
54
chart.dataGrid().tooltip().useHtml(true);
55
chart.dataGrid().tooltip().format(
56
"<span style='font-weight:600;font-size:12pt'>" +
57
"{%start}{dateTimeFormat:dd MMM} - " +
58
"{%end}{dateTimeFormat:dd MMM}</span><br><br>" +
59
"Disc Space: {%disc_space}"
60
);
61
62
// set the container id
63
chart.container("container");
64
65
// initiate drawing the chart
66
chart.draw();
67
68
// fit elements to the width of the timeline
69
chart.fitAll();
70
});