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
child_items: [
9
{
10
id: "1",
11
name: "Server 1",
12
intervals: [
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
intervals: [
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
child_items: [
29
{
30
id: "3",
31
name: "Server 3",
32
intervals: [
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", null, {children: "child_items"});
40
41
// map the data
42
var mapping = treeData.mapAs({periods: "intervals"});
43
44
// create a chart
45
var chart = anychart.ganttResource();
46
47
// set the data
48
chart.data(mapping);
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
});