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
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/samples/sparkline-charts/win-loss/data.js
4
// prepare the data for charts
5
var t1 = getData()[0]; // eslint-disable-line no-undef
6
var t2 = getData()[1]; // eslint-disable-line no-undef
7
var t3 = getData()[2]; // eslint-disable-line no-undef
8
var t4 = getData()[3]; // eslint-disable-line no-undef
9
var t5 = getData()[4]; // eslint-disable-line no-undef
10
var t6 = getData()[5]; // eslint-disable-line no-undef
11
var t7 = getData()[6]; // eslint-disable-line no-undef
12
var t8 = getData()[7]; // eslint-disable-line no-undef
13
var t9 = getData()[8]; // eslint-disable-line no-undef
14
var t10 = getData()[9]; // eslint-disable-line no-undef
15
var t11 = getData()[10]; // eslint-disable-line no-undef
16
var t12 = getData()[11]; // eslint-disable-line no-undef
17
var t13 = getData()[12]; // eslint-disable-line no-undef
18
var t14 = getData()[13]; // eslint-disable-line no-undef
19
var t15 = getData()[14]; // eslint-disable-line no-undef
20
var t16 = getData()[15]; // eslint-disable-line no-undef
21
var t17 = getData()[16]; // eslint-disable-line no-undef
22
var t18 = getData()[17]; // eslint-disable-line no-undef
23
var t19 = getData()[18]; // eslint-disable-line no-undef
24
var t20 = getData()[19]; // eslint-disable-line no-undef
25
26
// create table, this table provides layout for the sparkline charts
27
var table = anychart.standalones.table();
28
29
// set table size settings
30
table.bounds('5%', '20px', '90%', '90%');
31
32
// set table contents (sparkline charts and text)
33
table.contents([
34
['Team', null, 'W', 'L', 'History', 'Percent'],
35
[
36
'1.',
37
'Liverpool',
38
getWins(t1),
39
getLoses(t1),
40
createWinLoss(t1),
41
getPercent(t1)
42
],
43
[
44
'2.',
45
'Fulham',
46
getWins(t2),
47
getLoses(t2),
48
createWinLoss(t2),
49
getPercent(t2)
50
],
51
[
52
'3.',
53
'Chelsea',
54
getWins(t3),
55
getLoses(t3),
56
createWinLoss(t3),
57
getPercent(t3)
58
],
59
[
60
'4.',
61
'Man United',
62
getWins(t4),
63
getLoses(t4),
64
createWinLoss(t4),
65
getPercent(t4)
66
],
67
[
68
'5.',
69
'Bolton',
70
getWins(t5),
71
getLoses(t5),
72
createWinLoss(t5),
73
getPercent(t5)
74
],
75
[
76
'6.',
77
'Blackburn',
78
getWins(t6),
79
getLoses(t6),
80
createWinLoss(t6),
81
getPercent(t6)
82
],
83
[
84
'7.',
85
'Wigan Athletic',
86
getWins(t7),
87
getLoses(t7),
88
createWinLoss(t7),
89
getPercent(t7)
90
],
91
[
92
'8.',
93
'West Ham United',
94
getWins(t8),
95
getLoses(t8),
96
createWinLoss(t8),
97
getPercent(t8)
98
],
99
[
100
'9.',
101
'Charlton',
102
getWins(t9),
103
getLoses(t9),
104
createWinLoss(t9),
105
getPercent(t9)
106
],
107
[
108
'10.',
109
'Arsenal',
110
getWins(t10),
111
getLoses(t10),
112
createWinLoss(t10),
113
getPercent(t10)
114
],
115
[
116
'11.',
117
'Sunderland',
118
getWins(t11),
119
getLoses(t11),
120
createWinLoss(t11),
121
getPercent(t11)
122
],
123
[
124
'12.',
125
'Aston Villa',
126
getWins(t12),
127
getLoses(t12),
128
createWinLoss(t12),
129
getPercent(t12)
130
],
131
[
132
'13.',
133
'Tottenham',
134
getWins(t13),
135
getLoses(t13),
136
createWinLoss(t13),
137
getPercent(t13)
138
],
139
[
140
'14.',
141
'Everton',
142
getWins(t14),
143
getLoses(t14),
144
createWinLoss(t14),
145
getPercent(t14)
146
],
147
[
148
'15.',
149
'West Bromwich',
150
getWins(t15),
151
getLoses(t15),
152
createWinLoss(t15),
153
getPercent(t15)
154
],
155
[
156
'16.',
157
'Portsmouth',
158
getWins(t16),
159
getLoses(t16),
160
createWinLoss(t16),
161
getPercent(t16)
162
],
163
[
164
'17.',
165
'Middlesbrough',
166
getWins(t17),
167
getLoses(t17),
168
createWinLoss(t17),
169
getPercent(t17)
170
],
171
[
172
'18.',
173
'Newcastle',
174
getWins(t18),
175
getLoses(t18),
176
createWinLoss(t18),
177
getPercent(t18)
178
],
179
[
180
'19.',
181
'Birmingham City',
182
getWins(t19),
183
getLoses(t19),
184
createWinLoss(t19),
185
getPercent(t19)
186
],
187
[
188
'20.',
189
'Manchester City',
190
getWins(t20),
191
getLoses(t20),
192
createWinLoss(t20),
193
getPercent(t20)
194
]
195
]);
196
197
// set [0,0] cell settings
198
table.getCell(0, 0).colSpan(2);
199
table.getCell(0, 0).hAlign('left');
200
table.getCell(0, 0).padding(0, 0, 0, 45);
201
202
// disable borders for all cells in the table
203
table
204
.cellBorder('none')
205
// set table rows odd/even fill
206
.rowEvenFill('#F6F7F8')
207
.rowOddFill('#FFF')
208
// set table text settings
209
.fontFamily('Verdana')
210
.fontColor('#7c868e')
211
.fontSize('12px')
212
.vAlign('middle')
213
.hAlign('center');
214
215
// set fixed width for some of the tables columns
216
table.getCol(0).width(40);
217
table.getCol(1).maxWidth(120).hAlign('left');
218
table.getCol(2).width(40);
219
table.getCol(3).width(40);
220
table.getCol(5).width(60).fontColor('#545f69');
221
222
// set text settings for columns
223
table.getRow(0).cellFill('#e9eaed').fontColor('#545f69');
224
225
// set container id for the table
226
table.container('container');
227
// draw the table and all elements it contains
228
// (you don't need to call the draw method for internal tables and charts)
229
table.draw();
230
});
231
232
/**
233
* Helper function, creates sparkline chart with WinLos type using anychart.sparkline method,
234
* sets passed data and visual preference.
235
* @param {Array} array Sparkline data.
236
* @return {anychart.charts.Sparkline} New sparkline chart with passed data.
237
*/
238
function createWinLoss(array) {
239
var chart = anychart.sparkline(array);
240
chart.background(null);
241
chart.seriesType('win-loss');
242
chart.height('100%');
243
chart.margin().top('5%');
244
chart.margin().bottom('5%');
245
chart.padding(0);
246
return chart;
247
}
248
249
/**
250
* Helper function, returns count of positive values in passed array.
251
* @param {Array} array
252
* @return {number}
253
*/
254
function getWins(array) {
255
var wins = 0;
256
for (var i = 0, count = array.length - 1; i < count; i++) {
257
if (array[i] > 0) wins++;
258
}
259
return wins;
260
}
261
262
/**
263
* Helper function, returns count of negative values in passed array.
264
* @param {Array} array
265
* @return {number}
266
*/
267
function getLoses(array) {
268
var loses = 0;
269
for (var i = 0, count = array.length - 1; i < count; i++) {
270
if (array[i] < 0) loses++;
271
}
272
return loses;
273
}
274
275
/**
276
* Helper function, returns percent ratio of positive to negative value.
277
* @param {Array} array
278
* @return {string}
279
*/
280
function getPercent(array) {
281
var wins = 0;
282
var total = array.length;
283
for (var i = 0, count = array.length - 1; i < count; i++) {
284
if (array[i] > 0) wins++;
285
}
286
return Math.round((wins / total) * 100) + '%';
287
}