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
actualStart: "2018-01-15",
9
actualEnd: "2018-03-10",
10
children: [
11
{
12
id: "1_1",
13
name: "Analysis",
14
actualStart: "2018-01-15",
15
actualEnd: "2018-01-25"
16
},
17
{
18
id: "1_2",
19
name: "Design",
20
actualStart: "2018-01-20",
21
actualEnd: "2018-02-04"
22
},
23
{
24
id: "1_3",
25
name: "Meeting",
26
actualStart: "2018-02-05",
27
actualEnd: "2018-02-05"
28
},
29
{
30
id: "1_4",
31
name: "Implementation",
32
actualStart: "2018-02-05",
33
actualEnd: "2018-02-24"
34
},
35
{
36
id: "1_5",
37
name: "Testing",
38
actualStart: "2018-02-25",
39
actualEnd: "2018-03-10"
40
}
41
]}
42
];
43
44
// set the input date/time format
45
anychart.format.inputDateTimeFormat("yyyy-MM-dd");
46
47
// create a data tree
48
var treeData = anychart.data.tree(data, "as-tree");
49
50
// create a chart
51
var chart = anychart.ganttProject();
52
53
// set the data
54
chart.data(treeData);
55
56
// access the second data grid column
57
var column_2 = chart.dataGrid().column(1);
58
59
// set the title of the second data grid column
60
column_2.title("Start - End");
61
62
// set the indent for nested labels in the second column
63
column_2.depthPaddingMultiplier(20);
64
65
// set the text of the second data grid column
66
column_2.labels().useHtml(true);
67
column_2.labels().format(function() {
68
var start = anychart.format.dateTime(this.actualStart, "dd MMM");
69
var end = anychart.format.dateTime(this.actualEnd, "dd MMM");
70
return "<span style='color:#64b5f6'>" + start +
71
"</span> - <span style='color:#ffa000'>" + end + "</span>";
72
});
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
});