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
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
},
31
{
32
id: "1_4",
33
name: "Implementation",
34
actualStart: "2018-02-05",
35
actualEnd: "2018-02-24",
36
progressValue: "60%"
37
},
38
{
39
id: "1_5",
40
name: "Testing",
41
actualStart: "2018-02-25",
42
actualEnd: "2018-03-10"
43
}
44
]}
45
];
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
// configure progress bars of regular tasks
57
var tasks = chart.getTimeline().tasks();
58
tasks.progress().normal().fill("#dd2c00");
59
tasks.progress().selected().fill("#455a64 0.5");
60
tasks.progress().selected().stroke("#455a64");
61
62
// configure progress bars of parent tasks
63
var parentTasks = chart.getTimeline().groupingTasks();
64
parentTasks.progress().normal().fill(null);
65
parentTasks.progress().selected().fill(null);
66
parentTasks.progress().selected().stroke(null);
67
68
// configure the scale
69
chart.getTimeline().scale().maximum("2018-03-20");
70
71
// set the container id
72
chart.container("container");
73
74
// initiate drawing the chart
75
chart.draw();
76
77
// fit elements to the width of the timeline
78
chart.fitAll();
79
});