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
3
4
// create data
5
var data = [
6
{
7
"name": "Renewal",
8
"children": [
9
{
10
"name": "adamtestclient.com.au",
11
"subType": "Domain Registration",
12
"upfrontCost": 120,
13
"ongoingCost": 0,
14
"actualStart": "2021-09-07",
15
"actualEnd": "2021-09-07"
16
},
17
{
18
"name": "Dynamics GP",
19
"subType": "Application",
20
"upfrontCost": 30000,
21
"ongoingCost": 0,
22
"actualStart": "2021-10-28",
23
"actualEnd": "2021-10-28"
24
},
25
{
26
"name": "VMware Essentials Plus",
27
"subType": "Licensing, Warranties and Renewals",
28
"upfrontCost": 0,
29
"ongoingCost": 0,
30
"actualStart": "2021-10-28",
31
"actualEnd": "2021-10-28"
32
},
33
{
34
"name": "Test License #1",
35
"subType": "Licensing, Warranties and Renewals",
36
"upfrontCost": 2500,
37
"ongoingCost": 0,
38
"actualStart": "2021-12-21",
39
"actualEnd": "2021-12-21"
40
},
41
{
42
"name": "visitsdemodomain.net.au",
43
"subType": "Domain Registration",
44
"upfrontCost": 0,
45
"ongoingCost": 0,
46
"actualStart": "2022-02-07",
47
"actualEnd": "2022-02-07"
48
}
49
]
50
},
51
{
52
"name": "Strategy",
53
"children": [
54
{
55
"name": "Replacement of phone system with Teams Phone",
56
"subType": "Modern Workplace",
57
"upfrontCost": 5000,
58
"ongoingCost": 5000,
59
"actualStart": "2021-08-31",
60
"actualEnd": "2021-08-31"
61
},
62
{
63
"name": "Replace aging UPS",
64
"subType": "Platforms",
65
"upfrontCost": 0,
66
"ongoingCost": 0,
67
"actualStart": "2021-09-21",
68
"actualEnd": "2021-09-21"
69
},
70
{
71
"name": "Decommission legacy file services (on-premise and Datto Workplace)",
72
"subType": "Business Solutions",
73
"upfrontCost": 0,
74
"ongoingCost": 0,
75
"actualStart": "2021-10-11",
76
"actualEnd": "2021-10-11"
77
},
78
{
79
"name": "Upgrade Mebourne internet service",
80
"subType": "Networks",
81
"upfrontCost": 0,
82
"ongoingCost": 0,
83
"actualStart": "2021-12-09",
84
"actualEnd": "2022-01-15"
85
},
86
{
87
"name": "Implement new CRM",
88
"subType": "Business Solutions",
89
"upfrontCost": 0,
90
"ongoingCost": 0,
91
"actualStart": "2022-01-06",
92
"actualEnd": "2022-01-06"
93
},
94
{
95
"name": "Melbourne Office Relocation",
96
"type": "Strategy",
97
"subType": "Other",
98
"upfrontCost": 0,
99
"ongoingCost": 0,
100
"actualStart": "2022-03-14",
101
"actualEnd": "2022-03-14"
102
}
103
]
104
}
105
];
106
107
108
109
// create a data tree
110
var treeData = anychart.data.tree(data, "as-tree");
111
// create a chart
112
var chart = anychart.ganttProject();
113
114
115
// access the timeline
116
var timeline = chart.getTimeline();
117
// configure labels of tasks
118
timeline.milestones().labels().useHtml(true);
119
//timeline.milestones().labels().format(
120
//"<span style='color:#295496;font-size:14px;font-family:Roboto'><b>{%name}</b></span><BR><span style='font-family:Roboto'><b>Upfront cost:</b> {%upfrontCost}<BR><b>Monthly cost:</b> {%ongoingCost}</span>"
121
//);
122
123
124
timeline.milestones().labels().format(
125
function() {
126
127
var customfieldName = this.getData("name");
128
var customfieldType = this.getData("type");
129
var customfieldSubType = this.getData("subType");
130
var customfieldUpfrontCost = this.getData("upfrontCost");
131
var customfieldOngoingCost = this.getData("ongoingCost");
132
133
if (customfieldType == "Strategy") {
134
return "<span style='color:#295496;font-size:12px;font-family:Roboto'>" + customfieldName + "</span><BR><span style='font-family:Roboto'><b>Upfront cost:</b> " + customfieldUpfrontCost + "<BR><b>Monthly cost:</b> " + customfieldOngoingCost + "</span>";
135
} else {
136
return "<span style='color:#962954;font-size:12px;font-family:Roboto'>" + customfieldName + "</span><BR><span style='font-family:Roboto'><b>Renewal cost:</b> " + customfieldUpfrontCost + "</span>";
137
}
138
139
}
140
141
);
142
143
144
timeline.milestones().fill("#a9bad5");
145
timeline.milestones().stroke("#fcfcfc");
146
147
timeline.milestones().markerType("circle");
148
149
150
chart.getTimeline().groupingTasks().enabled(false);
151
152
chart.getTimeline().scale().maximumGap(".5");
153
chart.getTimeline().scale().minimumGap(".1");
154
155
156
chart.dataGrid().column(0).enabled(false);
157
158
var column1 = chart.dataGrid().column(1);
159
160
column1.title().fontFamily("Roboto");
161
column1.width(350);
162
column1.labels().useHtml(true);
163
column1.depthPaddingMultiplier(30);
164
165
166
//column1.labels().format("<span style='font-size:16px;font-family:Roboto'>{%name}</span><br><span style='font-family:Roboto'><b>{%subType}</b><br>{%detailedDescription}</span>");
167
column1.labels().format(function() {
168
169
var numChildren = this.item.numChildren();
170
var duration = (this.actualEnd - this.actualStart) / 1000 / 3600 / 24;
171
var progress = this.progress * 100 + "%";
172
var customField = "";
173
if (this.getData("custom_field")) {
174
customField = "<span style='font-weight:bold'>" +
175
this.getData("custom_field") + " </span>";
176
}
177
var customfieldType = this.getData("type");
178
var customfieldSubType = this.getData("subType");
179
var parentText = "<span style='font-size:16px;font-family:Roboto;font-weight:600;'>" + this.name + "</span>";
180
181
if (customfieldType == "Strategy") {
182
var milestoneText = "<span style='font-size:14px;font-family:Roboto'>" + this.name + "</span>";
183
var taskText = "<span style='font-size:14px;font-family:Roboto'>" + this.name + "</span>";
184
} else {
185
186
var milestoneText = "<span style='font-size:14px;font-family:Roboto'>" + this.name + "</span><br><span style='font-family:Roboto'><b>" + customfieldSubType + "</b></span";
187
var taskText = "<span style='font-size:14px;font-family:Roboto'>" + this.name + "</span><br><span style='font-family:Roboto'><b>" + customfieldSubType + "</b></span";
188
189
190
}
191
192
193
194
// identify the task type and display the corresponding text
195
if (numChildren > 0) {
196
return parentText;
197
} else {
198
if (duration == 0) {
199
return milestoneText;
200
} else {
201
return taskText;
202
}
203
}
204
205
});
206
207
208
// create two range markers
209
var marker_1 = chart.getTimeline().rangeMarker(0);
210
211
// set the range of the first marker
212
marker_1.from("2021-12-01");
213
marker_1.to("2022-01-05");
214
215
216
// set the fill of markers
217
//marker_1.fill("#dd2c00 0.1");
218
//marker_1.useHtml(true);
219
//marker_1.text("marker <span style='font-size:26'>1</span>");
220
//marker_1.offsetX(-10);
221
222
223
224
225
var header = chart.getTimeline().header();
226
227
header.level(0).fill("#64b5f6 0.2");
228
header.level(0).height(35);
229
230
231
header.level(1).height(35);
232
header.level(2).height(35);
233
234
chart.rowHoverFill("#f3f3f3");
235
chart.rowSelectedFill("#f3f3f3");
236
237
chart.getTimeline().scale().fiscalYearStartMonth(7);
238
239
anychart.format.outputDateTimeFormat("dd/MM/yyyy");
240
241
242
chart.defaultRowHeight(50);
243
// set the data
244
chart.data(treeData);
245
// set the container id
246
chart.container("container");
247
// initiate drawing the chart
248
chart.draw();
249
// fit elements to the width of the timeline
250
chart.fitAll();
251
//chart.fitToTask();
252
//chart.zoomTo(Date.UTC(2021, 10, 3), Date.UTC(2022, 01, 6));
253
});