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