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
custom_field: "(*)"
14
},
15
{
16
id: "2",
17
name: "Server 2",
18
periods: [
19
{id: "2_1", start: "2018-01-07", end: "2018-02-15"},
20
{id: "2_2", start: "2018-02-26", end: "2018-03-20"}
21
],
22
custom_field: "(!)"
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
custom_field: "(?)"
31
}
32
];
33
34
// create a data tree
35
var treeData = anychart.data.tree(data, "as-tree");
36
37
// create a chart
38
var chart = anychart.ganttResource();
39
40
// set the data
41
chart.data(treeData);
42
43
// configure labels of periods
44
var periodLabels = chart.getTimeline().periods().labels();
45
periodLabels.enabled(true);
46
periodLabels.useHtml(true);
47
periodLabels.fontColor("#104d89");
48
periodLabels.fontWeight(600);
49
periodLabels.format(
50
"<span style='color:#991f00'>{%custom_field}</span> " +
51
"start: {%start}{dateTimeFormat:dd MMM}"
52
);
53
54
// set the container id
55
chart.container("container");
56
57
// initiate drawing the chart
58
chart.draw();
59
60
// fit elements to the width of the timeline
61
chart.fitAll();
62
});