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
// set the row and header height
38
chart.defaultRowHeight(35);
39
chart.headerHeight(105);
40
41
// access periods
42
var periods = chart.getTimeline().periods();
43
44
// set the height of periods
45
periods.height(40);
46
47
// a function for drawing custom elements
48
var drawingFunction = function () {
49
50
// get the shapes of the element
51
var shapes = this["shapes"];
52
// get the shape to be modified
53
var path = shapes["path"];
54
// get the bounds of the element
55
var bounds = this["predictedBounds"];
56
57
var h = bounds.height;
58
var t = bounds.top;
59
var l = bounds.left;
60
var r = bounds.left + bounds.width;
61
var h1 = bounds.top + bounds.height;
62
var h4 = h / 4;
63
var h2 = h / 2;
64
65
// draw a rounded rectangle
66
path.moveTo(l + h4, h1 - h4)
67
path.arcTo(h4, h4, -270, 180)
68
path.lineTo(r - h4, t + h4)
69
path.arcTo(h4, h4, -90, 180)
70
path.lineTo(l + h2, h1 - h4)
71
path.close();
72
73
}
74
75
// draw custom periods
76
periods.rendering().drawer(drawingFunction);
77
78
// set the container id
79
chart.container("container");
80
81
// initiate drawing the chart
82
chart.draw();
83
84
// fit elements to the width of the timeline
85
chart.fitAll();
86
});