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: "Development",
8
baselineStart: "2018-01-12",
9
baselineEnd: "2018-03-04",
10
actualStart: "2018-01-15",
11
actualEnd: "2018-03-10",
12
children: [
13
{
14
id: "1_1",
15
name: "Analysis",
16
baselineStart: "2018-01-12",
17
baselineEnd: "2018-01-25",
18
actualStart: "2018-01-15",
19
actualEnd: "2018-01-25"
20
},
21
{
22
id: "1_2",
23
name: "Design",
24
baselineStart: "2018-01-20",
25
baselineEnd: "2018-01-31",
26
actualStart: "2018-01-20",
27
actualEnd: "2018-02-04"
28
},
29
{
30
id: "1_3",
31
name: "Meeting",
32
actualStart: "2018-02-05",
33
actualEnd: "2018-02-05"
34
},
35
{
36
id: "1_4",
37
name: "Implementation",
38
baselineStart: "2018-02-01",
39
baselineEnd: "2018-02-19",
40
actualStart: "2018-02-05",
41
actualEnd: "2018-02-24"
42
},
43
{
44
id: "1_5",
45
name: "Testing",
46
baselineStart: "2018-02-20",
47
baselineEnd: "2018-03-05",
48
actualStart: "2018-02-25",
49
actualEnd: "2018-03-10"
50
}
51
]}
52
];
53
54
// create a data tree
55
var treeData = anychart.data.tree(data, "as-tree");
56
57
// create a chart
58
var chart = anychart.ganttProject();
59
60
// set the data
61
chart.data(treeData);
62
63
// set the row and header height
64
chart.defaultRowHeight(35);
65
chart.headerHeight(105);
66
67
// set the height of timeline elements
68
chart.getTimeline().elements().height(20);
69
70
// a function for drawing custom elements
71
var drawingFunction = function () {
72
73
// get the shapes of the element
74
var shapes = this["shapes"];
75
// get the shape to be modified
76
var path = shapes["path"];
77
// get the bounds of the element
78
var bounds = this["predictedBounds"];
79
80
var h = bounds.height;
81
var t = bounds.top;
82
var l = bounds.left;
83
var r = bounds.left + bounds.width;
84
var h1 = bounds.top + bounds.height;
85
var h4 = h / 4;
86
var h2 = h / 2;
87
88
// draw a rounded rectangle
89
path.moveTo(l + h4, h1 - h4)
90
path.arcTo(h4, h4, -270, 180)
91
path.lineTo(r - h4, t + h4)
92
path.arcTo(h4, h4, -90, 180)
93
path.lineTo(l + h2, h1 - h4)
94
path.close();
95
96
}
97
98
// access tasks and baselines
99
var tasks = chart.getTimeline().tasks();
100
var baselines = chart.getTimeline().baselines();
101
102
// draw custom tasks and baselines
103
tasks.rendering().drawer(drawingFunction);
104
baselines.rendering().drawer(drawingFunction);
105
106
// configure the scale
107
chart.getTimeline().scale().maximum("2018-03-15");
108
109
// set the container id
110
chart.container("container");
111
112
// initiate drawing the chart
113
chart.draw();
114
115
// fit elements to the width of the timeline
116
chart.fitAll();
117
});