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