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
// create data tree on our data
3
var treeData = anychart.data.tree(getData(), anychart.enums.TreeFillingMethod.AS_TABLE);
4
5
// create resource gantt chart
6
var chart = anychart.ganttResource();
7
8
// set container id for the chart
9
chart.container('container');
10
11
// set data for the chart
12
chart.data(treeData);
13
14
//set DataGrid and TimeLine visual settings
15
chart.dataGrid().rowOddFill('#fff');
16
chart.dataGrid().rowEvenFill('#fff');
17
chart.getTimeline().rowOddFill('#fff');
18
chart.getTimeline().rowEvenFill('#fff');
19
20
// set start splitter position settings
21
chart.splitterPosition(150);
22
23
// get chart data grid link to set column settings
24
var dataGrid = chart.dataGrid();
25
chart.getTimeline().tooltip().useHtml(true);
26
chart.getTimeline().tooltip().format(function (e) {
27
var item = e['item'];
28
return item.get('name') + '<br>' + 'Start time: ' + anychart.utils.defaultDateFormatter(item.meta('minPeriodDate')) + '<br>'
29
+ 'End time: ' + anychart.utils.defaultDateFormatter(item.meta('maxPeriodDate'));
30
});
31
32
// set first column settings
33
var firstColumn = dataGrid.column(0);
34
firstColumn.title('#');
35
firstColumn.width(30);
36
firstColumn.cellTextSettings().hAlign('center');
37
38
// set second column settings
39
var secondColumn = dataGrid.column(1);
40
secondColumn.title('Person');
41
secondColumn.width(120);
42
secondColumn.cellTextSettings().hAlign('left');
43
secondColumn.format(function (item) {
44
return item.get('name');
45
});
46
47
// initiate chart drawing
48
chart.draw();
49
50
// zoom chart to specified date
51
chart.zoomTo(1171036800000, 1176908400000);
52
});
53
54
55
function getData() {
56
// colors
57
var moccasin_border = '#B8AA96';
58
var moccasin_bottom = '#CFC0A9';
59
var moccasin_middle = '#E6D5BC';
60
var moccasin_top = '#E8D9C3';
61
62
var rosybrown_border = '#9B9292';
63
var rosybrown_bottom = '#AFA4A4';
64
var rosybrown_middle = '#C2B6B6';
65
var rosybrown_top = '#C8BDBD';
66
67
var brown_border = '#6B5D5D';
68
var brown_bottom = '#796868';
69
var brown_middle = '#867474';
70
var brown_top = '#928282';
71
72
return [
73
{
74
"id": "1",
75
"name": "Alex Exler",
76
"periods": [
77
{"id": "1_1", "start": 1171468800000, "end": 1171987200000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, { "color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}},
78
{"id": "1_2", "start": 1174921200000, "end": 1175612400000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, { "color": moccasin_middle, "position": 0.38 }, {"color": moccasin_top, "position": 1}]}}]
79
},
80
{
81
"id": "2",
82
"name": "Philip Kineyko",
83
"periods": [
84
{"id": "2_1", "start": 1173024000000, "end": 1173715200000, "stroke": rosybrown_border,"fill": {"angle": 90, "keys": [{"color": rosybrown_bottom, "position": 0}, {"color": rosybrown_middle, "position": 0.38 }, {"color": rosybrown_top, "position": 1}]}},
85
{"id": "2_2", "start": 1173888000000, "end": 1174406400000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, {"color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}}]
86
},
87
{
88
"id": "3",
89
"name": "Luke Liakos",
90
"periods": [
91
{"id": "3_1", "start": 1169740800000, "end": 1170172800000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, {"color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}},
92
{"id": "3_2", "start": 1171987200000, "end": 1172505600000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, { "color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}}]
93
},
94
{
95
"id": "4",
96
"name": "Judy Penfold",
97
"periods": [
98
{"id": "4_1", "start": 1171814400000, "end": 1172419200000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, {"color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}},
99
{"id": "4_2", "start": 1173628800000, "end": 1174320000000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, {"color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}}]
100
},
101
{
102
"id": "5",
103
"name": "Patricia Darmon",
104
"periods": [
105
{"id": "5_1", "start": 1171296000000, "end": 1171382400000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, {"color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}},
106
{"id": "5_2", "start": 1174233600000, "end": 1174579200000, "stroke": moccasin_border, "fill": {"angle": 90, "keys": [{"color": moccasin_bottom, "position": 0}, {"color": moccasin_middle, "position": 0.38}, {"color": moccasin_top, "position": 1}]}}]
107
}
108
];
109
110
111
}