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
// data
3
var data = getData();
4
5
// set filling method for tree
6
var treeData = anychart.data.tree(data, 'as-table');
7
8
// create PERT chart
9
var chart = anychart.pert();
10
// set spacing between milestones
11
chart
12
.data(treeData)
13
.horizontalSpacing('18.7%')
14
// set padding for chart
15
.padding([25, 50, 0, 50]);
16
17
// get duration project
18
var duration = chart.getStat('pertChartProjectDuration');
19
20
// set title text
21
chart
22
.title()
23
.enabled(true)
24
.useHtml(true)
25
.padding([0, 0, 35, 0])
26
.text(
27
'Airplane Design Process with PERT Chart' +
28
'<br>Project duration: ' +
29
duration +
30
' days'
31
);
32
33
// set settings for tasks
34
var tasks = chart.tasks();
35
// format upper label task
36
tasks.upperLabels().format(function () {
37
return this.item.get('fullName');
38
});
39
40
// format lower label task
41
tasks.lowerLabels().format('{%duration} days');
42
43
// create tasks tooltip
44
var taskTooltip = tasks.tooltip();
45
// tooltip settings
46
taskTooltip.separator(true).titleFormat(function () {
47
// return fullName from data
48
return this.item.get('fullName');
49
});
50
taskTooltip.title().useHtml(true);
51
52
// set settings for milestones
53
var milestones = chart.milestones();
54
// set milestones color
55
milestones
56
.color('#2C81D5')
57
// set milestones item size
58
.size('6.5%');
59
milestones.hovered().fill(function () {
60
return anychart.color.lighten(this.sourceColor, 0.25);
61
});
62
milestones.tooltip().format(defuaultMilesoneTooltipTextFormatter);
63
64
// set settings for critical milestones
65
var critMilestones = chart.criticalPath().milestones();
66
// format label
67
critMilestones.labels().format(function () {
68
if (this.creator) {
69
return this.creator.get('name');
70
}
71
return this.isStart ? 'Start' : 'Finish';
72
});
73
// set color
74
critMilestones
75
.color('#E24B26')
76
// fill color for critMilestones item
77
.fill(function () {
78
if (this.creator) {
79
return this.sourceColor;
80
}
81
return this.isStart ? '#60727B' : '#60727B';
82
});
83
84
// hover fill/stroke color for critMilestones item
85
critMilestones
86
.hovered()
87
.fill(function () {
88
if (this.creator) {
89
return anychart.color.lighten(this.sourceColor, 0.25);
90
}
91
return this.isStart ? '#60727b' : '#60727b';
92
})
93
.stroke(function () {
94
return this.creator ? '1.5 #a94e3d' : null;
95
});
96
97
// set container id for the chart
98
chart.container('container');
99
// initiate chart drawing
100
chart.draw();
101
});
102
103
function defuaultMilesoneTooltipTextFormatter() {
104
var result = '';
105
var i = 0;
106
if (this.successors && this.successors.length) {
107
result += 'Successors:';
108
for (i = 0; i < this.successors.length; i++) {
109
result += '\n - ' + this.successors[i].get('fullName');
110
}
111
if (this.predecessors && this.predecessors.length) result += '\n\n';
112
}
113
if (this.predecessors && this.predecessors.length) {
114
result += 'Predecessors:';
115
for (i = 0; i < this.predecessors.length; i++) {
116
result += '\n - ' + this.predecessors[i].get('fullName');
117
}
118
}
119
return result;
120
}
121
122
function getData() {
123
return [
124
{
125
id: '1',
126
duration: 30,
127
name: '1',
128
fullName: 'Aerodynamics'
129
},
130
{
131
id: '2',
132
duration: 50,
133
name: '2',
134
fullName: 'Build & Test Model'
135
},
136
{
137
id: '3',
138
duration: 35,
139
name: '3',
140
fullName: 'Structure'
141
},
142
{
143
id: '4',
144
duration: 50,
145
name: '4',
146
dependsOn: ['1'],
147
fullName: 'Propulsion'
148
},
149
{
150
id: '5',
151
duration: 60,
152
name: '5',
153
dependsOn: ['2'],
154
fullName: 'Build Prototype'
155
},
156
{
157
id: '6',
158
duration: 40,
159
name: '6',
160
dependsOn: ['3'],
161
fullName: 'Control & Stability'
162
},
163
{
164
id: '7',
165
duration: 20,
166
name: '7',
167
dependsOn: ['4'],
168
fullName: 'Wind Tunnel'
169
},
170
{
171
id: '8',
172
duration: 20,
173
name: '8',
174
dependsOn: ['6'],
175
fullName: 'Computation'
176
},
177
{
178
id: '9',
179
duration: 45,
180
name: '9',
181
dependsOn: ['7'],
182
fullName: 'Review'
183
},
184
{
185
id: '10',
186
duration: 30,
187
name: '10',
188
dependsOn: ['8'],
189
fullName: 'Flight Simulation'
190
},
191
{
192
id: '11',
193
duration: 50,
194
name: '11',
195
dependsOn: ['9'],
196
fullName: 'Research flights'
197
},
198
{
199
id: '12',
200
duration: 45,
201
name: '12',
202
dependsOn: ['10'],
203
fullName: 'Revise & Review'
204
},
205
{
206
id: '13',
207
duration: 25,
208
name: '13',
209
dependsOn: ['5'],
210
fullName: 'Finalize'
211
}
212
];
213
}