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
var chart = anychart.column();
3
chart.title('Frog Column');
4
5
chart.background().fill('#fff');
6
7
var series = chart.column([15, 17, 25, 14, 19, 10, 21]);
8
series.hovered().fill('pink');
9
series.selected().fill('#CDE5B2');
10
series
11
.tooltip()
12
.titleFormat(function () {
13
return 'Frog ' + ++this.index;
14
})
15
.format('Value: {%Value}');
16
17
// get shapes
18
var shapes = series.rendering().shapes();
19
20
// add 'rect-transparent' shape to shapes group
21
shapes.push({
22
// shape name
23
name: 'rect-transparent',
24
// shape type ('path', 'circle', 'ellipse' or 'rect')
25
shapeType: 'path',
26
// ZIndex for the balance of shapes relative to each other
27
zIndex: 1
28
});
29
30
// add 'hands' shape to shapes group
31
shapes.push({
32
// shape name
33
name: 'hands',
34
// shape type ('path', 'circle', 'ellipse' or 'rect')
35
shapeType: 'path',
36
// set fill settings
37
fillName: 'fill',
38
// set stroke settings
39
strokeName: 'stroke',
40
// enabled hover/select state
41
canBeHoveredSelected: true,
42
// ZIndex for the balance of shapes relative to each other
43
zIndex: 2
44
});
45
46
// add 'eyes' shape to shapes group
47
shapes.push({
48
// shape name
49
name: 'eyes',
50
// shape type ('path', 'circle', 'ellipse' or 'rect')
51
shapeType: 'path',
52
// set fill settings
53
fillName: 'fill',
54
// set stroke settings
55
strokeName: 'stroke',
56
// enabled hover/select state
57
canBeHoveredSelected: true,
58
// ZIndex for the balance of shapes relative to each other
59
zIndex: 2
60
});
61
62
// add 'pupils' shape to shapes group
63
shapes.push({
64
// shape name
65
name: 'pupils',
66
// shape type ('path', 'circle', 'ellipse' or 'rect')
67
shapeType: 'path',
68
// set fill settings
69
fillName: 'fill',
70
// set stroke settings
71
strokeName: 'stroke',
72
// enabled hover/select state
73
canBeHoveredSelected: true,
74
// ZIndex for the balance of shapes relative to each other
75
zIndex: 2
76
});
77
78
chart.yScale().minimum(0);
79
chart.yScale().ticks().interval(5);
80
81
// set rendering settings
82
series
83
.rendering()
84
// set point function to drawing
85
.point(drawer)
86
// set update point function to drawing, change the point shape when the state changes
87
.updatePoint(drawer)
88
// set shapes
89
.shapes(shapes);
90
91
// set container id for the chart
92
chart.container('container');
93
// initiate chart drawing
94
chart.draw();
95
96
// listen point select
97
chart.listen('pointsselect', function (e) {
98
if (!e.point.selected()) {
99
flag = true;
100
}
101
});
102
});
103
104
var flag = true;
105
var deviationHandsFinal;
106
var deviationPupilsFinal;
107
var intervalFirst = null;
108
var intervalSecond = null;
109
110
function drawer() {
111
// if missing (not correct data), then skipping this point drawing
112
if (this.missing) {
113
return;
114
}
115
116
// get shapes group
117
var shapes = this.shapes || this.getShapesGroup(this.pointState);
118
// calculate the left value of the x-axis
119
var leftX = this.x - this.pointWidth / 2;
120
// calculate the right value of the x-axis
121
var rightX = leftX + this.pointWidth;
122
// calculate the half of point width
123
var rx = this.pointWidth / 2;
124
125
var deviationPupils = 1;
126
var deviationHands = 1;
127
var that = this;
128
// calculate gap
129
var gap = Math.floor(
130
this.pointWidth / this.series.data().getRowsCount()
131
);
132
133
if (gap > 10) {
134
gap = 10;
135
}
136
137
// if pointState > 0, then hover or select point state
138
if (this.pointState > 0) {
139
shapes.path
140
// resets all 'path' operations
141
.clear()
142
// draw column (body)
143
.moveTo(leftX, this.zero)
144
.lineTo(leftX, this.value + rx)
145
.lineTo(rightX, this.value + rx)
146
.lineTo(rightX, this.zero)
147
// close by connecting the last point with the first straight line
148
.close()
149
150
// draw circular arc (head)
151
.moveTo(leftX, this.value)
152
.circularArc(this.x, this.value + rx - gap, rx, rx, 180, 180)
153
// close by connecting the last point with the first straight line
154
.close();
155
156
shapes['rect-transparent']
157
// draw transparent rectangle (mouth)
158
.moveTo(leftX - 5, this.value + rx - 1)
159
.lineTo(leftX - 5, this.value - gap + rx + 1)
160
.lineTo(rightX + 5, this.value - gap + rx + 1)
161
.lineTo(rightX + 5, this.value + rx - 1)
162
.fill('#fff')
163
.stroke('#fff')
164
// close by connecting the last point with the first straight line
165
.close();
166
167
shapes.hands
168
// resets all 'hands' operations
169
.clear()
170
.stroke('1 #546269')
171
// draw path hands
172
.moveTo(leftX - rx / 2, this.value + rx)
173
.lineTo(leftX, this.value + 2 * rx)
174
.circularArc(
175
leftX - rx / 2,
176
this.value + rx,
177
rx / 5,
178
rx / 5,
179
-210,
180
180
181
)
182
.fill('red')
183
// close by connecting the last point with the first straight line
184
.close()
185
186
// draw wrist
187
.moveTo(rightX + rx / 2, this.value + rx)
188
.lineTo(rightX, this.value + 2 * rx)
189
.circularArc(
190
rightX + rx / 2,
191
this.value + rx,
192
rx / 5,
193
rx / 5,
194
210,
195
180
196
)
197
// close by connecting the last point with the first straight line
198
.close();
199
200
shapes.eyes
201
// resets all 'eyes' operations
202
.clear()
203
// draw eyes
204
.moveTo(leftX, this.value + rx)
205
.circularArc(
206
this.x - rx / 2,
207
this.value + rx / 4 - gap,
208
rx / 4,
209
rx / 3,
210
360,
211
360
212
)
213
.moveTo(rightX, this.value + rx)
214
.circularArc(
215
this.x + rx / 2,
216
this.value + rx / 4 - gap,
217
rx / 4,
218
rx / 3,
219
360,
220
360
221
)
222
.stroke('#546269')
223
.fill('#fff');
224
225
// select point state
226
if (this.pointState === 2) {
227
if (!flag) {
228
shapes.pupils
229
// resets all 'pupils' operations
230
.clear()
231
// draw pupils
232
.moveTo(leftX, this.value + rx)
233
.circularArc(
234
this.x - rx / 2,
235
this.value + rx / 4 - deviationPupilsFinal - gap / 2,
236
rx / 6,
237
rx / 6,
238
360,
239
360
240
)
241
.moveTo(rightX, that.value + rx)
242
.circularArc(
243
this.x + rx / 2,
244
this.value + rx / 4 - deviationPupilsFinal - gap / 2,
245
rx / 6,
246
rx / 6,
247
360,
248
360
249
)
250
.fill('#DD3F2A')
251
.stroke('1 #546269');
252
shapes.hands
253
// resets all 'hands' operations
254
.clear()
255
// draw hands
256
.moveTo(
257
leftX - rx / 2 + deviationHandsFinal,
258
this.value + rx - deviationHandsFinal
259
)
260
.lineTo(leftX, this.value + 2 * rx)
261
.circularArc(
262
leftX - rx / 2 + deviationHandsFinal,
263
this.value + rx - deviationHandsFinal,
264
rx / 5,
265
rx / 5,
266
-210 + deviationHandsFinal,
267
180
268
)
269
// close by connecting the last point with the first straight line
270
.close()
271
272
// draw wrist
273
.moveTo(
274
rightX + rx / 2 - deviationHandsFinal,
275
this.value + rx - deviationHandsFinal
276
)
277
.lineTo(rightX, this.value + 2 * rx)
278
.circularArc(
279
rightX + rx / 2 - deviationHandsFinal,
280
this.value + rx - deviationHandsFinal,
281
rx / 5,
282
rx / 5,
283
210 - deviationHandsFinal,
284
180
285
)
286
// close by connecting the last point with the first straight line
287
.close();
288
return;
289
}
290
291
if (intervalFirst === null) {
292
intervalFirst = setInterval(function () {
293
deviationPupils += 1;
294
shapes.pupils
295
// resets all 'pupils' operations
296
.clear()
297
// draw pupils
298
.moveTo(leftX, that.value + rx)
299
.circularArc(
300
that.x - rx / 2,
301
that.value + rx / 4 - deviationPupils - gap / 2,
302
rx / 6,
303
rx / 6,
304
360,
305
360
306
)
307
.moveTo(rightX, that.value + rx)
308
.circularArc(
309
that.x + rx / 2,
310
that.value + rx / 4 - deviationPupils - gap / 2,
311
rx / 6,
312
rx / 6,
313
360,
314
360
315
)
316
.fill('#DD3F2A')
317
.stroke('1 #546269');
318
319
if (deviationPupils >= rx / 5) {
320
clearInterval(intervalFirst);
321
intervalFirst = null;
322
deviationPupilsFinal = deviationPupils;
323
flag = false;
324
}
325
}, 10);
326
}
327
328
if (intervalSecond === null) {
329
intervalSecond = setInterval(function () {
330
deviationHands += 1;
331
shapes.hands
332
// resets all 'hands' operations
333
.clear()
334
// draw hands
335
.moveTo(
336
leftX - rx / 2 + deviationHands,
337
that.value + rx - deviationHands
338
)
339
.lineTo(leftX, that.value + 2 * rx)
340
.circularArc(
341
leftX - rx / 2 + deviationHands,
342
that.value + rx - deviationHands,
343
rx / 5,
344
rx / 5,
345
-210 + deviationHands,
346
180
347
)
348
// close by connecting the last point with the first straight line
349
.close()
350
351
// draw wrist
352
.moveTo(
353
rightX + rx / 2 - deviationHands,
354
that.value + rx - deviationHands
355
)
356
.lineTo(rightX, that.value + 2 * rx)
357
.circularArc(
358
rightX + rx / 2 - deviationHands,
359
that.value + rx - deviationHands,
360
rx / 5,
361
rx / 5,
362
210 - deviationHands,
363
180
364
)
365
// close by connecting the last point with the first straight line
366
.close();
367
368
if (deviationHands >= rx / 5) {
369
clearInterval(intervalSecond);
370
intervalSecond = null;
371
deviationHandsFinal = deviationHands;
372
flag = false;
373
}
374
}, 10);
375
}
376
} else {
377
// hover point state
378
shapes.pupils
379
// resets all 'pupils' operations
380
.clear()
381
// draw pupils
382
.moveTo(leftX, this.value + rx)
383
.circularArc(
384
this.x - rx / 2,
385
this.value + rx / 4 - gap / 2,
386
rx / 6,
387
rx / 6,
388
360,
389
360
390
)
391
.moveTo(rightX, this.value + rx)
392
.circularArc(
393
this.x + rx / 2,
394
this.value + rx / 4 - gap / 2,
395
rx / 6,
396
rx / 6,
397
360,
398
360
399
)
400
.stroke('1 #546269')
401
.fill('#DD3F2A');
402
}
403
} else {
404
// pointState === 0, then normal point state
405
shapes.path
406
// resets all 'path' operations
407
.clear()
408
// draw path (body)
409
.moveTo(leftX, this.zero)
410
.lineTo(leftX, this.value + rx)
411
.lineTo(rightX, this.value + rx)
412
.lineTo(rightX, this.zero)
413
// close by connecting the last point with the first straight line
414
.close()
415
416
// draw path (head)
417
.moveTo(leftX, this.value)
418
.circularArc(this.x, this.value + rx, rx, rx, 180, 180)
419
// close by connecting the last point with the first straight line
420
.close();
421
422
shapes['rect-transparent']
423
// resets all 'rect-transparent' operations
424
.clear();
425
426
shapes.hands
427
// resets all 'hands' operations
428
.clear()
429
// draw hands
430
.stroke('1 #546269')
431
.moveTo(leftX, this.value + 2 * rx)
432
.lineTo(leftX - rx / 2, this.value + 3 * rx)
433
.circularArc(
434
leftX - rx / 2,
435
this.value + 3 * rx,
436
rx / 5,
437
rx / 5,
438
30,
439
180
440
)
441
// close by connecting the last point with the first straight line
442
.close()
443
444
// draw wrist
445
.moveTo(rightX, this.value + 2 * rx)
446
.lineTo(rightX + rx / 2, this.value + 3 * rx)
447
.circularArc(
448
rightX + rx / 2,
449
this.value + 3 * rx,
450
rx / 5,
451
rx / 5,
452
-30,
453
180
454
)
455
.fill('blue 0.5')
456
// close by connecting the last point with the first straight line
457
.close();
458
459
shapes.eyes
460
// resets all 'eyes' operations
461
.clear()
462
// draw eyes
463
.moveTo(leftX, this.value + rx)
464
.circularArc(
465
this.x - rx / 2,
466
this.value + rx / 4,
467
rx / 4,
468
rx / 3,
469
360,
470
360
471
)
472
.moveTo(rightX, this.value + rx)
473
.circularArc(
474
this.x + rx / 2,
475
this.value + rx / 4,
476
rx / 4,
477
rx / 3,
478
360,
479
360
480
)
481
.stroke('#546269')
482
.fill('#fff');
483
484
shapes.pupils
485
// resets all 'pupils' operations
486
.clear()
487
// draw pupils
488
.moveTo(leftX, this.value + rx)
489
.circularArc(
490
this.x - rx / 2,
491
this.value + rx / 4,
492
rx / 6,
493
rx / 6,
494
360,
495
360
496
)
497
.moveTo(rightX, this.value + rx)
498
.circularArc(
499
this.x + rx / 2,
500
this.value + rx / 4,
501
rx / 6,
502
rx / 6,
503
360,
504
360
505
)
506
.fill('blue 0.5')
507
.stroke('1 #546269');
508
}
509
}