HTMLcopy
1
<div id='container'></div>
CSScopy
x
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
8
.anychart-tooltip {
9
padding: 0;
10
background: white;
11
color: #333;
12
box-shadow: 2px 2px 5px #333;
13
border-radius: 0;
14
}
15
16
.anychart-tooltip-title h5 {
17
background: #455a64;
18
padding: 10px 30px;
19
margin: 0;
20
}
21
22
.anychart-tooltip-title h5.default {
23
color: #fff;
24
}
25
26
.anychart-tooltip hr {
27
margin: 0;
28
}
29
30
.anychart-tooltip .tooltip-content {
31
padding: 0 30px;
32
}
JavaScriptcopy
384
1
anychart.onDocumentReady(function () {
2
3
// Create a project gantt chart
4
var chart = anychart.ganttProject();
5
6
// Create a data tree from the dataset created from line 133
7
var treeData = anychart.data.tree(data, 'as-tree');
8
// Load it to the chart
9
chart.data(treeData);
10
11
// Customize the chart's data grid:
12
// get the data grid
13
var dataGrid = chart.dataGrid();
14
// enable html in the data grid's tooltips
15
dataGrid.tooltip().useHtml(true);
16
// set the task name column's width
17
dataGrid.column(1).width(250);
18
19
// Set the line splitting the data grid and the timeline
20
chart.splitterPosition(303);
21
22
// Get the chart's timeline
23
var timeline = chart.getTimeline();
24
25
// Get the chart's milestones
26
var milestones = timeline.milestones();
27
28
// Some milestones are formatted in the data using the 'milestone' property.
29
// Set the milestone format for all other milestones
30
milestones
31
.markerType('square')
32
.fill('#96a6a6')
33
.stroke('#333');
34
35
// Customize the default tooltip:
36
timeline.tooltip()
37
// enable html
38
.useHtml(true)
39
// format the tooltip title
40
.titleFormat(function () {
41
return '<h5 class="title default">' + this.name + '</h5>';
42
})
43
// format the tooltip content
44
.format(function () {
45
return (
46
'<div class="tooltip-content">\n' +
47
'<p><b>Start date</b>: ' +
48
anychart.format.date(this.actualStart) + '</p>\n' +
49
'<p><b>End date</b>: ' +
50
anychart.format.date(this.actualEnd) + '</p>\n' + '</div>'
51
);
52
});
53
54
// Customize the milestone tooltip:
55
milestones.tooltip()
56
// enable html
57
.useHtml(true)
58
// format the tooltip title
59
.titleFormat(function () {
60
var bgcolor = this.getData('milestone')
61
? this.getData('milestone').fill: '#96a6a6';
62
return (
63
'<h5 class="title" style="background: ' + bgcolor + '">' +
64
this.name + '</h5>'
65
);
66
})
67
// format the tooltip content
68
.format(function () {
69
return (
70
'<div class="tooltip-content"><p><b>Date</b>: ' +
71
anychart.format.date(this.actualStart) + '</p></div>'
72
);
73
});
74
75
// Preview milestones on their parent tasks
76
milestones.preview().enabled(true);
77
78
// Highlight holidays:
79
// get the timeline calendar
80
var calendar = timeline.scale().calendar();
81
// set the holidays
82
calendar.holidays([{day: 4, month: 6, label: 'Independence Day'}]);
83
// customize the holiday and weekend fill
84
timeline.holidaysFill('green 0.2').weekendsFill('red 0.2');
85
86
// Set the chart's initial zoom
87
chart.zoomTo(Date.UTC(2024, 6, 1, 0), Date.UTC(2024, 6, 16, 0));
88
89
// Render the chart within a specified container
90
chart.container('container').draw();
91
92
// Collapse all elements except for the first root task
93
chart.collapseAll().expandTask('1');
94
95
// Add a legend:
96
chart.legend()
97
// enable the legend
98
.enabled(true)
99
// set the legend's items
100
.items([
101
{
102
text: 'Meetings',
103
iconFill: '#64b5f6',
104
iconType: 'pentagon'
105
},
106
{
107
text: 'Reviews',
108
iconFill: '#ffd54f',
109
iconType: 'diamond'
110
},
111
{
112
text: 'Publishing',
113
iconFill: '#00bfa5',
114
iconType: 'star5'
115
},
116
{
117
text: 'Other',
118
iconFill: '#96a6a6',
119
iconType: 'square'
120
}
121
]);
122
123
});
124
125
// Create data
126
var data = [
127
{
128
id: '1',
129
name: 'Digital Marketing Campaign',
130
actualStart: '2024-07-01',
131
actualEnd: '2024-08-03',
132
children: [
133
{
134
id: '1.1',
135
name: 'Planning',
136
actualStart: '2024-07-01',
137
actualEnd: '2024-07-06',
138
children: [
139
{
140
id: '1.1.1',
141
name: 'Write campaign brief',
142
actualStart: '2024-07-01',
143
actualEnd: '2024-07-03'
144
},
145
{
146
id: '1.1.2',
147
name: 'Team kickoff',
148
actualStart: '2024-07-05',
149
actualEnd: '2024-07-05',
150
milestone: {
151
enabled: true,
152
markerType: 'pentagon',
153
fill: '#64b5f6',
154
stroke: '#666'
155
}
156
},
157
{
158
id: '1.1.3',
159
name: 'Creative brainstorm',
160
actualStart: '2024-07-06',
161
milestone: {
162
enabled: true,
163
markerType: 'pentagon',
164
fill: '#64b5f6',
165
stroke: '#666'
166
}
167
}
168
]
169
},
170
{
171
id: '1.2',
172
name: 'Content',
173
actualStart: '2024-07-07',
174
actualEnd: '2024-07-11',
175
children: [
176
{
177
id: '1.2.1',
178
name: 'Write content',
179
actualStart: '2024-07-07',
180
actualEnd: '2024-07-10'
181
},
182
{
183
id: '1.2.2',
184
name: 'Review content',
185
actualStart: '2024-07-11',
186
milestone: {
187
enabled: true,
188
markerType: 'diamond',
189
fill: '#ffd54f',
190
stroke: '#666'
191
}
192
}
193
]
194
},
195
{
196
id: '1.3',
197
name: 'Design',
198
actualStart: '2024-07-10',
199
actualEnd: '2024-07-14',
200
children: [
201
{
202
id: '1.3.1',
203
name: 'Design campaign graphics',
204
actualStart: '2024-07-10',
205
actualEnd: '2024-07-13'
206
},
207
{
208
id: '1.3.2',
209
name: 'Review graphics',
210
actualStart: '2024-07-14',
211
milestone: {
212
enabled: true,
213
markerType: 'diamond',
214
fill: '#ffd54f',
215
stroke: '#666'
216
}
217
}
218
]
219
},
220
{
221
id: '1.4',
222
name: 'Marketing Channels',
223
actualStart: '2024-07-10',
224
actualEnd: '2024-07-16',
225
children: [
226
{
227
id: '1.4.1',
228
name: 'Website',
229
actualStart: '2024-07-10',
230
actualEnd: '2024-07-15',
231
children: [
232
{
233
id: '1.4.1.1',
234
name: 'Build landing page',
235
actualStart: '2024-07-10',
236
actualEnd: '2024-07-13'
237
},
238
{
239
id: '1.4.1.2',
240
name: 'Review landing page',
241
actualStart: '2024-07-14',
242
milestone: {
243
enabled: true,
244
markerType: 'diamond',
245
fill: '#ffd54f',
246
stroke: '#666'
247
}
248
},
249
{
250
id: '1.4.1.3',
251
name: 'Launch page',
252
actualStart: '2024-07-15',
253
milestone: {
254
enabled: true,
255
markerType: 'star5',
256
fill: '#00bfa5',
257
stroke: '#666'
258
}
259
}
260
]
261
},
262
{
263
id: '1.4.2',
264
name: 'Email',
265
actualStart: '2024-07-12',
266
actualEnd: '2024-07-16',
267
children: [
268
{
269
id: '1.4.2.1',
270
name: 'Build emails',
271
actualStart: '2024-07-12',
272
actualEnd: '2024-07-14'
273
},
274
{
275
id: '1.4.2.2',
276
name: 'Test emails',
277
actualStart: '2024-07-15T12:00',
278
milestone: {
279
enabled: true,
280
markerType: 'diamond',
281
fill: '#ffd54f',
282
stroke: '#666'
283
}
284
},
285
{
286
id: '1.4.2.3',
287
name: 'Schedule emails',
288
actualStart: '2024-07-16',
289
milestone: {
290
enabled: true,
291
markerType: 'star5',
292
fill: '#00bfa5',
293
stroke: '#666'
294
}
295
}
296
]
297
},
298
{
299
id: '1.4.3',
300
name: 'Social Media',
301
actualStart: '2024-07-12',
302
actualEnd: '2024-07-16',
303
children: [
304
{
305
id: '1.4.3.1',
306
name: 'Create social posts',
307
actualStart: '2024-07-12',
308
actualEnd: '2024-07-15'
309
},
310
{
311
id: '1.4.3.2',
312
name: 'Schedule social posts',
313
actualStart: '2024-07-16',
314
milestone: {
315
enabled: true,
316
markerType: 'star5',
317
fill: '#00bfa5',
318
stroke: '#666'
319
}
320
}
321
]
322
},
323
{
324
id: '1.4.4',
325
name: 'Advertising',
326
actualStart: '2024-07-12',
327
actualEnd: '2024-07-16',
328
children: [
329
{
330
id: '1.4.4.1',
331
name: 'Set up ads',
332
actualStart: '2024-07-12',
333
actualEnd: '2024-07-16'
334
}
335
]
336
}
337
]
338
},
339
{
340
id: '1.5',
341
name: 'Campaign Live Dates',
342
actualStart: '2024-07-17',
343
actualEnd: '2024-07-31',
344
children: [
345
{
346
id: '1.5.1',
347
name: 'Campaign live',
348
actualStart: '2024-07-17'
349
},
350
{
351
id: '1.5.2',
352
name: 'End of campaign',
353
actualStart: '2024-07-31'
354
}
355
]
356
},
357
{
358
id: '1.6',
359
name: 'Reporting',
360
actualStart: '2024-07-17',
361
actualEnd: '2024-08-03',
362
children: [
363
{
364
id: '1.6.1',
365
name: 'Track & analyze campaign results',
366
actualStart: '2024-07-17',
367
actualEnd: '2024-08-02'
368
},
369
{
370
id: '1.6.2',
371
name: 'Retrospective meeting',
372
actualStart: '2024-08-03',
373
milestone: {
374
enabled: true,
375
markerType: 'pentagon',
376
fill: '#64b5f6',
377
stroke: '#666'
378
}
379
}
380
]
381
}
382
]
383
}
384
];