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