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: "Tasks",
8
actualStart: "2018-02-02",
9
actualEnd: "2018-02-25",
10
children: [
11
{
12
id: "1_1",
13
name: "Task 1",
14
actualStart: "2018-02-02",
15
actualEnd: "2018-02-07",
16
connectTo: "1_2",
17
connectorType: "finish-start"
18
},
19
{
20
id: "1_2",
21
name: "Task 2",
22
actualStart: "2018-02-09",
23
actualEnd: "2018-02-09",
24
connectTo: "1_5",
25
connectorType: "start-start"
26
},
27
{
28
id: "1_3",
29
name: "Task 3",
30
actualStart: "2018-02-11",
31
actualEnd: "2018-02-23",
32
connectTo: "1_4",
33
connectorType: "finish-finish"
34
},
35
{
36
id: "1_4",
37
name: "Task 4",
38
actualStart: "2018-02-18",
39
actualEnd: "2018-02-25",
40
connectTo: "1_5",
41
connectorType: "start-finish"
42
},
43
{
44
id: "1_5",
45
name: "Task 5",
46
actualStart: "2018-02-15",
47
actualEnd: "2018-02-21"
48
}
49
]}
50
];
51
52
// create a data tree
53
var treeData = anychart.data.tree(data, "as-tree");
54
55
// create a chart
56
var chart = anychart.ganttProject();
57
58
// set the data
59
chart.data(treeData);
60
61
// configure the scale
62
chart.getTimeline().scale().maximum("2018-02-27");
63
64
// disable labels of elements
65
chart.getTimeline().elements().labels(false);
66
67
// configure connectors
68
var connectors = chart.getTimeline().connectors();
69
connectors.normal().fill("#ffa000");
70
connectors.selected().fill("#ef6c00");
71
connectors.normal().stroke("2 #ffa000");
72
connectors.selected().stroke("2 #ef6c00");
73
74
// set the container id
75
chart.container("container");
76
77
// initiate drawing the chart
78
chart.draw();
79
80
// fit elements to the width of the timeline
81
chart.fitAll();
82
});