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: "Root",
8
start_date: "2018-01-15",
9
end_date: "2018-03-10",
10
child_items: [
11
{
12
id: "1_2",
13
name: "Child 1",
14
start_date: "2018-01-15",
15
end_date: "2018-01-25"
16
},
17
{
18
id: "1_3",
19
name: "Child 2",
20
start_date: "2018-01-20",
21
end_date: "2018-02-04"
22
},
23
{
24
id: "1_3",
25
name: "Child 3",
26
start_date: "2018-02-05",
27
end_date: "2018-02-05"
28
},
29
{
30
id: "1_4",
31
name: "Child 4",
32
start_date: "2018-02-05",
33
end_date: "2018-02-24"
34
},
35
{
36
id: "1_5",
37
name: "Child 5",
38
start_date: "2018-02-25",
39
end_date: "2018-03-10"
40
}
41
]}
42
];
43
44
// create a data tree
45
var treeData = anychart.data.tree(data, "as-tree", null, {children: "child_items"});
46
47
// map the data
48
var mapping = treeData.mapAs({actualStart: "start_date", actualEnd: "end_date"});
49
50
// create a chart
51
var chart = anychart.ganttProject();
52
53
// set the data
54
chart.data(mapping);
55
56
// configure the scale
57
chart.getTimeline().scale().maximum("2018-03-15");
58
59
// set the chart title
60
chart.title("Tree Data Model: Mapping");
61
chart.title().padding(10);
62
63
// set the container id
64
chart.container("container");
65
66
// initiate drawing the chart
67
chart.draw();
68
69
// fit elements to the width of the timeline
70
chart.fitAll();
71
});