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
anychart.data.loadJsonFile('https://gist.githubusercontent.com/shacheeswadia/21da3da501982400b8ca35690b17ea5a/raw/d17e3774c6db1502b5d95677a5656ecc43f24526/resourceChartData.json', function (data) {
3
4
// set the japanese locale
5
anychart.format.outputLocale('ja-jp');
6
7
// create a data tree
8
var treeData = anychart.data.tree(data, 'as-tree');
9
10
// create a resource gantt chart
11
var chart = anychart.ganttResource();
12
13
// set the data
14
chart.data(treeData);
15
16
// fit elements to the width of the timeline
17
chart.fitAll();
18
19
// set the position of the splitter to match the first column
20
chart.dataGrid().fixedColumns(true);
21
22
// enable and configure the chart title
23
var title = chart.title();
24
title.enabled(true);
25
title
26
.text('Tokyo 2020 Paralympic Schedule - Venues and Sports')
27
.fontSize(18)
28
.fontWeight(600)
29
.fontColor('#b32e3c')
30
.padding(10);
31
32
// customize the color of the bars
33
var elements = chart.getTimeline().elements();
34
elements.normal().fill('#e96a7b 0.75');
35
elements.normal().stroke('#db4e50');
36
37
// enable labels
38
elements.labels().enabled(true);
39
elements.labels().fontColor('White');
40
41
// set the row height
42
chart.defaultRowHeight(25);
43
44
// set the header height
45
chart.headerHeight(95);
46
47
// enable html for the data grid tooltip
48
chart.dataGrid().tooltip().useHtml(true);
49
50
// configure the tooltips of the timeline
51
chart.getTimeline().tooltip().useHtml(true);
52
53
chart.getTimeline().tooltip().title(false);
54
chart.getTimeline().tooltip().separator(false);
55
56
chart.getTimeline().tooltip().format(function(e) {
57
var depth = e.item.meta('depth');
58
var tooltipText;
59
60
// when hovering a venue row
61
// show the number of sports in the venue
62
if (depth === 0) {
63
tooltipText = e.item.numChildren() + ' Sports in the venue.';
64
} else {
65
if (typeof e.period === 'undefined') {
66
// when hovering an event row
67
// show the sport and the number of events
68
var events = e.item.get('periods').length;
69
tooltipText = '<span style=\'font-weight:600;font-size:12px\'>' +
70
events + ' ' +
71
e.name + ' event(s).</span>';
72
} else {
73
// when hovering an event bar
74
// show the start and end of the event
75
var start = anychart.format.dateTime(e.start, 'dd MMM');
76
var end = anychart.format.dateTime(e.end, 'dd MMM');
77
78
tooltipText = '<span style="font-weight:600;font-size:12px">' +
79
start + '-' + end + ' </span>';
80
}
81
}
82
83
return tooltipText;
84
});
85
86
chart.dataGrid().tooltip().format(function(e)
87
{
88
// different tooltips for venues and sports
89
// in the data grid
90
91
var depth = e.item.meta('depth');
92
var tooltipText;
93
94
// the number of sports for venues
95
if (depth === 0) {
96
tooltipText = e.item.numChildren() + ' Sports in the venue.';
97
} else {
98
// the number of events for sports
99
tooltipText = '<span style="font-weight:600;font-size:12px">' +
100
e.name + ': ' +
101
e.item.get('periods').length + ' event(s) in the venue. </span>';
102
}
103
104
return tooltipText;
105
}
106
);
107
108
// disable the first data grid column
109
chart.dataGrid().column(0).enabled(false);
110
111
// set the width of the labels column
112
chart.dataGrid().column(1).width(285);
113
114
// set the text of the first data grid column
115
var column_1 = chart.dataGrid().column(1);
116
column_1.labels()
117
.useHtml(true);
118
119
// format labels depending on whether it is a venue or a sport
120
column_1.labels().format(function(e) {
121
// decision based on a depth in hierarchy
122
var depth = e.item.meta('depth');
123
var style = (depth === 0) ? 'bold' : '400';
124
return '<span style="font-size:12px;font-weight:' + style + '">' + e.name + ' </span>';
125
});
126
127
// set the container id
128
chart.container('container');
129
130
// draw the chart
131
chart.draw();
132
133
});
134
});