HTMLcopy
1
<label>Position of Baselines:</label>
2
<button onclick="baselinesAbove(true)">Above Tasks</button>
3
<button onclick="baselinesAbove(false)">Under Tasks</button>
4
<div id="container"></div>
CSScopy
19
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
label {
8
display: inline-block;
9
margin: 10px 0 0 10px;
10
}
11
button {
12
margin: 10px 0 0 10px;
13
}
14
#container {
15
position: absolute;
16
width: 100%;
17
top: 40px;
18
bottom: 0;
19
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
var data = [
5
{
6
id: "1",
7
name: "Development",
8
baselineStart: "2018-01-12",
9
baselineEnd: "2018-03-04",
10
actualStart: "2018-01-15",
11
actualEnd: "2018-03-10",
12
children: [
13
{
14
id: "1_1",
15
name: "Analysis",
16
baselineStart: "2018-01-12",
17
baselineEnd: "2018-01-25",
18
actualStart: "2018-01-15",
19
actualEnd: "2018-01-25"
20
},
21
{
22
id: "1_2",
23
name: "Design",
24
baselineStart: "2018-01-20",
25
baselineEnd: "2018-01-31",
26
actualStart: "2018-01-20",
27
actualEnd: "2018-02-04"
28
},
29
{
30
id: "1_3",
31
name: "Meeting",
32
actualStart: "2018-02-05",
33
actualEnd: "2018-02-05"
34
},
35
{
36
id: "1_4",
37
name: "Implementation",
38
baselineStart: "2018-02-01",
39
baselineEnd: "2018-02-19",
40
actualStart: "2018-02-05",
41
actualEnd: "2018-02-24"
42
},
43
{
44
id: "1_5",
45
name: "Testing",
46
baselineStart: "2018-02-20",
47
baselineEnd: "2018-03-05",
48
actualStart: "2018-02-25",
49
actualEnd: "2018-03-10"
50
}
51
]}
52
];
53
54
// create a data tree
55
var treeData = anychart.data.tree(data, "as-tree");
56
57
// create a chart
58
var chart = anychart.ganttProject();
59
60
// set the data
61
chart.data(treeData);
62
63
// configure baselines
64
baselines = chart.getTimeline().baselines();
65
baselines.normal().fill("#dd2c00 0.3");
66
baselines.normal().stroke(null);
67
baselines.selected().fill("#ef6c00 0.3");
68
baselines.selected().stroke(null);
69
70
// configure the scale
71
chart.getTimeline().scale().maximum("2018-03-15");
72
73
// set the container id
74
chart.container("container");
75
76
// initiate drawing the chart
77
chart.draw();
78
79
// fit elements to the width of the timeline
80
chart.fitAll();
81
});
82
83
// set the position of baselines
84
function baselinesAbove(enabled) {
85
baselines.above(enabled);
86
}