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
var data = getData();
3
var chart = anychart.ganttProject();
4
chart.defaultRowHeight(40);
5
chart.data(data, 'as-tree');
6
var timeline = chart.getTimeline();
7
chart.xScale().minimumGap(0.2).maximumGap(0.2);
8
9
//Getting the previews.
10
var previews = timeline.milestones().preview();
11
previews.enabled(true);
12
previews.labels(true);
13
14
//Styling previews.
15
timeline.milestones().preview({
16
fill: 'lightgreen',
17
stroke: 'purple'
18
});
19
20
chart.title('Labels crop is set to ' + timeline.cropLabels());
21
chart.container('container');
22
chart.draw();
23
chart.fitAll();
24
});
25
26
function getData() {
27
return [
28
{
29
id: 1,
30
name: 'Collapsed grouping task',
31
collapsed: true,
32
children: [
33
{
34
id: 2,
35
name: 'Milestone 1',
36
shortName: 'M1',
37
actualStart: Date.UTC(2019, 3, 1)
38
},
39
{
40
id: 3,
41
name: 'Milestone 2',
42
shortName: 'M2',
43
actualStart: Date.UTC(2019, 3, 10)
44
},
45
{
46
id: 3,
47
name: 'Milestone 3',
48
shortName: 'M3',
49
actualStart: Date.UTC(2019, 3, 14)
50
},
51
{
52
id: 4,
53
name: 'Milestone 4',
54
shortName: 'M4',
55
actualStart: Date.UTC(2019, 3, 20)
56
}
57
]
58
},
59
{
60
id: 5,
61
name: 'Expanded grouping task',
62
children: [
63
{
64
id: 6,
65
name: 'Milestone 5',
66
shortName: 'M5',
67
actualStart: Date.UTC(2019, 3, 17)
68
},
69
{
70
id: 7,
71
name: 'Milestone 6',
72
shortName: 'M6',
73
actualStart: Date.UTC(2019, 4, 1)
74
},
75
{
76
id: 8,
77
name: 'Milestone 7',
78
shortName: 'M7',
79
actualStart: Date.UTC(2019, 4, 12)
80
}
81
]
82
}
83
];
84
}