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
// create a data tree
45
var treeData = anychart.data.tree(data, "as-tree");
46
47
// create a chart
48
var chart = anychart.ganttProject();
49
50
// set the data
51
chart.data(treeData);
52
53
// create two text markers
54
var marker_1 = chart.getTimeline().textMarker(0);
55
var marker_2 = chart.getTimeline().textMarker(1);
56
57
// set values of markers
58
marker_1.value("2018-01-25");
59
marker_2.value("end");
60
61
// set the text of markers
62
marker_1.useHtml(true);
63
marker_1.text("marker <span style='font-size:26'>1</span>");
64
marker_2.text("marker 2");
65
66
// configure the font of markers
67
marker_1.fontColor("#455a64");
68
marker_2.fontColor("#dd2c00");
69
marker_1.fontWeight(600);
70
marker_2.fontWeight(600);
71
72
// configure the background of the first marker
73
marker_1.background().enabled(true);
74
marker_1.background().fill("#e3e8e8");
75
marker_1.background().stroke("2 #455a64");
76
77
// configure the position of markers
78
marker_1.rotation(0);
79
marker_1.padding(5)
80
marker_1.offsetY(31);
81
marker_2.offsetX(-10);
82
83
// configure the scale
84
chart.getTimeline().scale().maximum("2018-03-15");
85
86
// set the container id
87
chart.container("container");
88
89
// initiate drawing the chart
90
chart.draw();
91
92
// fit elements to the width of the timeline
93
chart.fitAll();
94
});