HTMLcopy
1
<div id="container"></div>
2
<img src="http://cdn.anychart.com/ts/icons/anychart.svg">
3
<img src="http://cdn.anychart.com/ts/icons/anystock.svg">
4
<img src="http://cdn.anychart.com/ts/icons/anymap.svg">
CSScopy
9
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
img {
8
display: none;
9
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function() {
2
3
// minimum size of a series logo in px
4
var sizeThreshold = 30;
5
6
var data = anychart.data.set([
7
["2018-01-01", 12, 32, 10],
8
["2018-01-02", 8, 2, 12],
9
["2018-01-03", 34, 15, 1],
10
["2018-01-04", 2, 19, 7],
11
["2018-01-05", 10, 12, 9]
12
]);
13
14
var chart = anychart.column();
15
chart.yScale().stackMode("value");
16
chart.legend(true);
17
chart.pointWidth('65%');
18
chart.palette(["#087dc9", "#ff8500", "#fd0002"]);
19
20
// set data from the table
21
var mapping1 = data.mapAs({'x': 0, 'value': 1});
22
var mapping2 = data.mapAs({'x': 0, 'value': 2});
23
var mapping3 = data.mapAs({'x': 0, 'value': 3});
24
var series1 = chart.column(mapping1);
25
series1
26
.name('AnyChart')
27
.meta('image', 'http://cdn.anychart.com/ts/icons/anychart.svg');
28
29
var series2 = chart.column(mapping2);
30
series2
31
.name('AnyStock')
32
.meta('image', 'http://cdn.anychart.com/ts/icons/anystock.svg');
33
34
var series3 = chart.column(mapping3);
35
series3
36
.name('AnyMap')
37
.meta('image', 'http://cdn.anychart.com/ts/icons/anymap.svg');
38
39
for (var i = 0; i < chart.getSeriesCount(); i++) {
40
setupDrawer(chart.getSeriesAt(i), sizeThreshold);
41
}
42
43
chart.container("container").draw();
44
45
//custom drawer
46
function setupDrawer(series, sizeThreshold) {
47
var images = [];
48
var tmp = series.rendering().shapes();
49
tmp.push({
50
name: 'image',
51
shapeType: 'path',
52
fillName: 'fill',
53
canBeHoveredSelected: true,
54
strokeName: 'stroke',
55
isHatchFill: false
56
});
57
58
series.rendering()
59
.shapes(tmp)
60
.needsZero(true)
61
.point(function() {
62
// get shapes group
63
var shapes = this.getShapesGroup(this.pointState);
64
65
// calculate the left value of the x axis
66
var leftX = this.x - this.pointWidth / 2;
67
// calculate the right value of the x axis
68
var rightX = leftX + this.pointWidth;
69
70
shapes['path']
71
// resets all 'line' operations
72
.clear()
73
.moveTo(leftX, this.zero)
74
.lineTo(leftX, this.value)
75
.lineTo(rightX, this.value)
76
.lineTo(rightX, this.zero)
77
// close by connecting the last point with the first straight line
78
.close();
79
80
// draw the logo if the image is greater than a threshold
81
if (Math.abs(this.zero - this.value) >= sizeThreshold) {
82
shapes['image']
83
// resets all 'line' operations
84
.clear()
85
.moveTo(leftX, this.zero)
86
.lineTo(leftX, this.value)
87
.lineTo(rightX, this.value)
88
.lineTo(rightX, this.zero)
89
// close by connecting the last point with the first straight line
90
.close()
91
.zIndex(3)
92
.fill({
93
src: series.meta('image'),
94
mode: "fit",
95
opacity: 1
96
});
97
98
shapes = this.getShapesGroup(1);
99
shapes['image']
100
// resets all 'line' operations
101
.clear()
102
.moveTo(leftX, this.zero)
103
.lineTo(leftX, this.value)
104
.lineTo(rightX, this.value)
105
.lineTo(rightX, this.zero)
106
// close by connecting the last point with the first straight line
107
.close()
108
.zIndex(2);
109
}
110
})
111
}
112
});