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
// create a data tree
44
var treeData = anychart.data.tree(data, "as-tree");
45
46
// create a chart
47
var chart = anychart.ganttProject();
48
49
// set the data
50
chart.data(treeData);
51
52
// create two range markers
53
var marker_1 = chart.getTimeline().rangeMarker(0);
54
var marker_2 = chart.getTimeline().rangeMarker(1);
55
56
// set the range of the first marker
57
marker_1.from("2018-01-20");
58
marker_1.to("2018-01-25");
59
60
// set the range of the second marker
61
marker_2.from("2018-03-01");
62
marker_2.to("end");
63
64
// set the fill of markers
65
marker_1.fill("#455a64 0.2");
66
marker_2.fill("#dd2c00 0.2");
67
68
// configure the scale
69
chart.getTimeline().scale().maximum("2018-03-15");
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
});