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
// set locales
3
anychart.format.inputLocale('ja-jp');
4
anychart.format.inputDateTimeFormat('yyyy.MM.dd'); //Like '2015.03.12'
5
anychart.format.outputLocale('ja-jp');
6
anychart.format.outputDateTimeFormat('dd MMM yyyy'); //Like '12 Mar 2015'
7
8
// create data
9
var treeData = anychart.data.tree(getData(), anychart.enums.TreeFillingMethod.AS_TABLE);
10
11
// create gantt-project chart
12
var chart = anychart.ganttProject();
13
14
// set container id
15
chart.container('container');
16
17
// set data
18
chart.data(treeData);
19
20
// datagrid settings
21
var dataGrid = chart.dataGrid();
22
dataGrid.column(0).title().text('#');
23
dataGrid.column(1).width(250).title('title');
24
dataGrid.column(2).textFormatter(function () {
25
var start = this['actualStart'] || this['autoStart'];
26
return anychart.format.dateTime(start);
27
}).title('start');
28
29
dataGrid.column(3).textFormatter(function () {
30
var end = this['actualEnd'] || this['autoEnd'];
31
return (end === void 0) ? '' : anychart.format.dateTime(end); //can be milestone
32
}).title('end');
33
34
// tooltip settings
35
dataGrid.tooltip().textFormatter(tooltipFormatter);
36
chart.getTimeline().tooltip().textFormatter(tooltipFormatter);
37
38
// initiate chart drawing
39
chart.draw();
40
});
41
42
// formatter for timeline and datagrid tooltips
43
function tooltipFormatter() {
44
var startDate = this['actualStart'] || this['autoStart'];
45
var endDate = this['actualEnd'] || this['autoEnd'];
46
var progress = this['progressValue'];
47
48
if (progress === void 0) {
49
var auto = this['autoProgress'] * 100;
50
progress = (Math.round(auto * 100) / 100 || 0) + '%';
51
}
52
53
return (startDate ? 'start date: ' + anychart.format.dateTime(startDate) : '') +
54
(endDate ? '\nend date: ' + anychart.format.dateTime(endDate) : '') +
55
(progress ? '\nprogress: ' + progress : '');
56
}
57
58
// simple data
59
function getData() {
60
return [
61
{'id': '1', name: 'Phase 1 - Strategic Plan'},
62
{'id': '2', 'name': 'Self assessment', 'parent': '1'},
63
{
64
'id': '3',
65
'name': 'It defines the business vision',
66
'parent': '2',
67
'actualStart': Date.UTC(2015, 2, 13),//'2015.03.13',
68
'actualEnd': '2015.03.24'
69
},
70
{
71
'id': '4',
72
'name': 'To identify the available skills, information and support',
73
'parent': '2',
74
'actualStart': '2015.03.25',
75
'actualEnd': '2015.04.06'
76
},
77
{
78
'id': '5',
79
'name': 'Decide whether you want to continue',
80
'parent': '2',
81
'actualStart': '2015.04.07',
82
'actualEnd': '2015.04.15',
83
'baselineStart': '2015.04.06',
84
'baselineEnd': '2015.04.18'
85
}
86
87
];
88
}