HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
anychart.data.loadJsonFile(
3
// The data used in this sample can be obtained from the CDN
4
'https://cdn.anychart.com/samples/gantt-general-features/milestones-on-resource-chart/data1.json',
5
function (data) {
6
// create data tree
7
var treeData = anychart.data.tree(data, 'as-table');
8
9
// create resource gantt chart
10
var chart = anychart.ganttResource();
11
12
// set data for the chart
13
chart.data(treeData);
14
15
// set the spliter position
16
chart.splitterPosition(220);
17
18
// set data grid settings
19
var dataGrid = chart.dataGrid();
20
21
var firstColumn = dataGrid.column(0);
22
23
firstColumn
24
.width(80)
25
.labels()
26
.format(function () {
27
return this.item.get('project_number');
28
})
29
.textShadow({
30
color: 'lightgrey',
31
offsetX: '3px',
32
offsetY: '3px',
33
blurRadius: '2px'
34
});
35
firstColumn
36
.title()
37
.text('Project\nNumber')
38
.fontSize(14)
39
.textShadow({
40
color: 'lightgrey',
41
offsetX: '4px',
42
offsetY: '4px',
43
blurRadius: '2px'
44
});
45
46
var secondColumn = dataGrid.column(1);
47
secondColumn.width(140).labels().textOverflow('...').textShadow({
48
color: 'lightgrey',
49
offsetX: '3px',
50
offsetY: '3px',
51
blurRadius: '2px'
52
});
53
54
secondColumn
55
.title()
56
.text('Project\nTitle')
57
.fontSize(14)
58
.textShadow({
59
color: 'lightgrey',
60
offsetX: '4px',
61
offsetY: '4px',
62
blurRadius: '2px'
63
});
64
65
// get timeline
66
var timeline = chart.getTimeline();
67
68
timeline.zoomOnMouseWheel(true);
69
70
// disable periods tooltip
71
timeline.periods().tooltip(false);
72
73
// set weekends fill color
74
timeline.weekendsFill('red 0.2');
75
76
// set holidays fill color
77
timeline.holidaysFill('green 0.2');
78
79
// get timeline calendar
80
var calendar = timeline.scale().calendar();
81
82
// set working hours
83
calendar.schedule([
84
null,
85
{ from: 10, to: 18 },
86
{ from: 10, to: 18 },
87
{ from: 10, to: 18 },
88
{ from: 10, to: 18 },
89
{ from: 10, to: 18 },
90
null
91
]);
92
93
// set container id for the chart
94
chart.container('container');
95
96
// initiate chart drawing
97
chart.draw();
98
99
// set chart's initial zoom
100
chart.zoomTo(Date.UTC(2008, 6, 20, 0), Date.UTC(2008, 7, 7, 0));
101
}
102
);
103
});