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
manager: "J. Doe",
11
children: [
12
{
13
id: "1_1",
14
name: "Analysis",
15
actualStart: "2018-01-15",
16
actualEnd: "2018-01-25",
17
progressValue: "75%"
18
},
19
{
20
id: "1_2",
21
name: "Design",
22
actualStart: "2018-01-20",
23
actualEnd: "2018-02-04",
24
progressValue: "100%",
25
custom_field: "!"
26
},
27
{
28
id: "1_3",
29
name: "Meeting",
30
actualStart: "2018-02-05",
31
actualEnd: "2018-02-05",
32
custom_field: "!"
33
},
34
{
35
id: "1_4",
36
name: "Implementation",
37
actualStart: "2018-02-05",
38
actualEnd: "2018-02-24",
39
progressValue: "60%"
40
},
41
{
42
id: "1_5",
43
name: "Testing",
44
actualStart: "2018-02-25",
45
actualEnd: "2018-03-10",
46
custom_field: "?"
47
}
48
]}
49
];
50
51
// create a data tree
52
var treeData = anychart.data.tree(data, "as-tree");
53
54
// create a chart
55
var chart = anychart.ganttProject();
56
57
// set the data
58
chart.data(treeData);
59
60
// set the text of the first data grid column
61
var column_1 = chart.dataGrid().column(0);
62
column_1.labels().fontColor("#64b5f6");
63
column_1.labels().fontWeight(600);
64
column_1.labels().format("{%linearIndex}.");
65
66
// set the text of the second data grid column
67
var column_2 = chart.dataGrid().column(1);
68
column_2.labels().useHtml(true);
69
column_2.labels().format(
70
"<span style='color:#dd2c00;font-weight:bold'>{%custom_field} </span>" +
71
"{%name}: <span style='color:#64b5f6'>{%progress}</span>"
72
);
73
74
// configure the scale
75
chart.getTimeline().scale().maximum("2018-03-20");
76
77
// set the container id
78
chart.container("container");
79
80
// initiate drawing the chart
81
chart.draw();
82
83
// fit elements to the width of the timeline
84
chart.fitAll();
85
});