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
parent: null
9
},
10
{
11
id: "1",
12
name: "Server 1",
13
parent: "A",
14
periods: [
15
{id: "1_1", start: "2018-01-05", end: "2018-01-25"},
16
{id: "1_2", start: "2018-01-28", end: "2018-02-22"},
17
{id: "1_3", start: "2018-03-03", end: "2018-03-25"}
18
]},
19
{
20
id: "2",
21
name: "Server 2",
22
parent: "A",
23
periods: [
24
{id: "2_1", start: "2018-01-07", end: "2018-02-15"},
25
{id: "2_2", start: "2018-02-26", end: "2018-03-20"}
26
]},
27
{
28
id: "B",
29
name: "Location B",
30
parent: null
31
},
32
{
33
id: "3",
34
name: "Server 3",
35
parent: "B",
36
periods: [
37
{id: "3_1", start: "2018-01-04", end: "2018-03-25"}
38
]}
39
];
40
41
// create a data tree
42
var treeData = anychart.data.tree(data, "as-table");
43
44
// create a chart
45
var chart = anychart.ganttResource();
46
47
// set the data
48
chart.data(treeData);
49
50
// set the container id
51
chart.container("container");
52
53
// initiate drawing the chart
54
chart.draw();
55
56
// fit elements to the width of the timeline
57
chart.fitAll();
58
});