HTMLcopy
x
1
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-core.min.js"></script>
2
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-gantt.min.js"></script>
3
4
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-data-adapter.min.js"></script>
5
6
<script src="https://cdn.anychart.com/releases/8.10.0/locales/ja-jp.js"></script>
7
8
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
135
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
start = anychart.format.dateTime(e.start, "dd MMM");
76
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
87
chart.dataGrid().tooltip().format(function(e)
88
{
89
// different tooltips for venues and sports
90
// in the data grid
91
92
var depth = e.item.meta('depth');
93
var tooltipText;
94
95
// the number of sports for venues
96
if (depth==0){
97
tooltipText = e.item.numChildren() + " Sports in the venue.";
98
} else {
99
// the number of events for sports
100
tooltipText = "<span style='font-weight:600;font-size:12px'>" +
101
e.name + ": " +
102
e.item.get("periods").length + " event(s) in the venue. </span>"
103
}
104
105
return tooltipText;
106
}
107
);
108
109
// disable the first data grid column
110
chart.dataGrid().column(0).enabled(false);
111
112
// set the width of the labels column
113
chart.dataGrid().column(1).width(285);
114
115
// set the text of the first data grid column
116
var column_1 = chart.dataGrid().column(1);
117
column_1.labels()
118
.useHtml(true);
119
120
// format labels depending on whether it is a venue or a sport
121
column_1.labels().format(function(e) {
122
// decision based on a depth in hierarchy
123
var depth = e.item.meta('depth');
124
var style = (depth==0)?'bold':'400';
125
return "<span style='font-size:12px;font-weight:" + style + "'>" + e.name + " </span>";
126
});
127
128
// set the container id
129
chart.container("container");
130
131
// draw the chart
132
chart.draw();
133
134
});
135
});