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
// load the data
4
anychart.data.loadJsonFile(
5
"https://gist.githubusercontent.com/awanshrestha/07b9144e8f2539cd192ef9a38f3ff8f5/raw/b4cfb7c27b48a0e92670a87b8f4b1607ca230a11/Fifa%2520World%2520Cup%25202022%2520Qatar%2520Stadium%2520Schedule.json",
6
function (data) {
7
8
// create a data tree
9
var treeData = anychart.data.tree(data, "as-table");
10
11
// create a resource gantt chart
12
var chart = anychart.ganttResource();
13
14
// set the data for the chart
15
chart.data(treeData);
16
17
// customize the rows
18
chart
19
.rowSelectedFill("#D4DFE8")
20
.rowHoverFill("#EAEFF3")
21
.splitterPosition(230);
22
23
// set the row height
24
chart.defaultRowHeight(50);
25
26
// customize the column settings:
27
// get the data grid
28
var dataGrid = chart.dataGrid();
29
// set the fixed columns mode
30
dataGrid.fixedColumns(true);
31
// first column
32
dataGrid
33
.column(0)
34
.title("#")
35
.width(30)
36
.labels({ hAlign: "center" });
37
// second column
38
dataGrid
39
.column(1)
40
.title("Stadium")
41
.width(200)
42
.labels()
43
.useHtml(true)
44
.format(function () {
45
return (
46
"<strong>" + this.name.toString() + "</strong> <br>" + this.item.get("city")
47
);
48
});
49
50
// configure the period labels:
51
// get the period labels
52
var periodLabels = chart.getTimeline().periods().labels();
53
// set the period labels
54
periodLabels
55
.enabled(true)
56
.useHtml(true)
57
.format(
58
"<span style='color:#fff; font-size: 12px;'>{%result}</span>"
59
);
60
61
// configure the background of the chart
62
chart.background("#edeae8 0.8");
63
64
// customize the color of the bars:
65
// get the elements
66
var elements = chart.getTimeline().elements();
67
// check if the current item is a tie, and if yes, color it differently
68
elements.normal().fill(function() {
69
var result = this.period.result;
70
var scores = result.split("-").map(Number);
71
if (scores[0] === scores[1]) {
72
return "#11A055 0.8";
73
} else {
74
return "#9a1032 0.8";
75
}
76
});
77
elements.normal().stroke("#212c68");
78
79
// configure the tooltip
80
var tooltip = chart.getTimeline().tooltip();
81
tooltip
82
.useHtml(true)
83
.format(function(e) {
84
var tooltipText;
85
if (typeof e.period === "undefined") {
86
tooltipText = e.item.la.city;
87
} else {
88
var period = e.period;
89
tooltipText = period.result;
90
}
91
return tooltipText;
92
});
93
94
// set the container
95
chart.container("container");
96
97
// draw the chart
98
chart.draw();
99
dataGrid.fixedColumns(true);
100
}
101
);
102
103
});