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-02-25",
16
progressValue: "75%"
17
},
18
{
19
id: "1_2",
20
name: "Design",
21
actualStart: "2018-01-20",
22
actualEnd: "2018-02-04",
23
progressValue: "100%"
24
},
25
{
26
id: "1_3",
27
name: "Meeting",
28
actualStart: "2018-02-05",
29
actualEnd: "2018-02-05",
30
custom_field: "(?)"
31
},
32
{
33
id: "1_4",
34
name: "Implementation",
35
actualStart: "2018-02-05",
36
actualEnd: "2018-02-24",
37
progressValue: "60%"
38
},
39
{
40
id: "1_5",
41
name: "Testing",
42
actualStart: "2018-02-25",
43
actualEnd: "2018-03-10"
44
}
45
]}
46
];
47
48
// create a data tree
49
var treeData = anychart.data.tree(data, "as-tree");
50
51
// create a chart
52
var chart = anychart.ganttProject();
53
54
// set the data
55
chart.data(treeData);
56
57
// access the timeline
58
var timeline = chart.getTimeline();
59
60
// configure labels of elements
61
timeline.elements().labels().fontWeight(600);
62
63
// configure labels of tasks
64
timeline.tasks().labels().useHtml(true);
65
timeline.tasks().labels().format(
66
"- <span style='color:#64b5f6'>{%progress}</span>"
67
);
68
69
// configure labels of parent tasks
70
timeline.groupingTasks().labels().useHtml(true);
71
timeline.groupingTasks().labels().format(
72
"- <span style='color:#dd2c00'>{%progress}</span>"
73
);
74
75
// configure labels of milestones
76
timeline.milestones().labels().useHtml(true);
77
timeline.milestones().labels().format(
78
"<span style='color:#ffa000'> " +
79
"{%actualStart}{dateTimeFormat:dd MMM}</span> {%custom_field}"
80
);
81
82
// configure the scale
83
chart.getTimeline().scale().maximum("2018-03-23");
84
85
// set the container id
86
chart.container("container");
87
88
// initiate drawing the chart
89
chart.draw();
90
91
// fit elements to the width of the timeline
92
chart.fitAll();
93
});