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 stage = acgraph.create('container');
3
4
$('#container').append(
5
'<div class="seat-map-title">' +
6
'<h1>Reservation of seats in Chamber theatre.</h1>' +
7
'<p>Source <a href="https://cdn.anychart.com/svg-data/' +
8
'seat-map/theater.svg"' +
9
'target="_blank">SVG Image</a></p></div>'
10
);
11
12
// get svg file
13
$.ajax({
14
type: 'GET',
15
url: 'https://cdn.anychart.com/svg-data/seat-map/theater.svg',
16
// The data that have been used for this sample can be taken from the CDN
17
// load SVG image using jQuery ajax
18
success: function (svgData) {
19
// Data for creating a SeatMap
20
var chart = anychart.seatMap([
21
{ id: '1', value: 'Row - 1' },
22
{ id: '2', value: 'Row - 1' },
23
{ id: '3', value: 'Row - 1' },
24
{ id: '4', value: 'Row - 2' },
25
{ id: '5', value: 'Row - 2' },
26
{ id: '6', value: 'Row - 2' },
27
{ id: '7', value: 'Row - 3' },
28
{ id: '8', value: 'Row - 3' },
29
{ id: '9', value: 'Row - 3' },
30
{ id: '10', value: 'Row - 4' },
31
{ id: '11', value: 'Row - 4' },
32
{ id: '12', value: 'Row - 4' }
33
]);
34
35
// set svg data
36
chart.geoData(svgData);
37
chart.padding([70, 20, 50, 20]);
38
39
// create chart legend
40
chart
41
.legend()
42
.enabled(true)
43
// items source mode categories
44
.itemsSourceMode('categories')
45
.position('right')
46
.itemsLayout('vertical');
47
48
var series = chart.getSeries(0);
49
50
// Set color scale.
51
series.colorScale(
52
anychart.scales.ordinalColor([
53
{ equal: 'Row - 4', color: '#109BC7' },
54
{ equal: 'Row - 3', color: '#109BC7' },
55
{ equal: 'Row - 2', color: '#109BC7' },
56
{ equal: 'Row - 1', color: '#d38d5f' }
57
])
58
);
59
60
// sets fill series
61
series.fill(function () {
62
var attrs = this.attributes;
63
if (attrs) {
64
// attr in svg.file
65
var itemClass = attrs.class;
66
switch (itemClass) {
67
case 'rect':
68
return attrs.fill;
69
default:
70
return '#fff';
71
}
72
} else {
73
return this.sourceColor;
74
}
75
});
76
77
// sets stroke series
78
series.stroke(function () {
79
var attrs = this.attributes;
80
if (attrs) {
81
// attr in svg.file
82
var itemClass = attrs.class;
83
switch (itemClass) {
84
case 'rect':
85
return attrs.stroke;
86
default:
87
return '#467fac';
88
}
89
} else {
90
return this.sourceColor;
91
}
92
});
93
94
series.tooltip().title().useHtml(true);
95
// set tooltip settings
96
series
97
.tooltip()
98
.useHtml(true)
99
.titleFormat(function () {
100
var col = this.id;
101
var VIP = 3;
102
103
if (col <= VIP) {
104
return '<strong style="color: gold;">VIP Place:</strong>';
105
}
106
return '<strong>Place:</strong>';
107
})
108
.format(function () {
109
var row = this.value;
110
// col data from svg-file attribute
111
var col = this.regionProperties.col;
112
113
return row + '<br>Col - ' + col;
114
});
115
116
// sets fill on hover series
117
series.hovered().fill(function () {
118
var attrs = this.attributes;
119
if (attrs) {
120
// attr in svg.file
121
var itemClass = attrs.class;
122
switch (itemClass) {
123
case 'chair-color-1':
124
return anychart.color.darken('#109BC7', 0.25);
125
case 'chair-color-2':
126
return '#109BC7';
127
case 'chair-color-3':
128
return anychart.color.darken('#109BC7', 0.75);
129
case 'chair-color-4':
130
return '#09546C';
131
case 'chair-vip-color-1':
132
return anychart.color.darken('#d38d5f', 0.25);
133
case 'chair-vip-color-2':
134
return '#d38d5f';
135
case 'chair-vip-color-3':
136
return anychart.color.darken('#6b3c1e', 0.75);
137
case 'chair-vip-color-4':
138
return anychart.color.darken('#6b3c1e', 0.1);
139
case 'rect':
140
return attrs.fill;
141
default:
142
return this.sourceColor;
143
// It returns the original color for
144
// those elements that are not fill over
145
}
146
}
147
});
148
149
// sets stroke on hover series
150
series.hovered().stroke(function () {
151
var attrs = this.attributes;
152
if (attrs) {
153
// attr in svg.file
154
var itemClass = attrs.class;
155
switch (itemClass) {
156
case 'rect':
157
return attrs.stroke;
158
default:
159
return '#000 0.3';
160
// It returns the original color for
161
// those elements that are not fill over
162
}
163
}
164
});
165
166
// sets fill on select series
167
series.selected().fill(function () {
168
var attrs = this.attributes;
169
if (attrs) {
170
// attr in svg.file
171
var itemClass = attrs.class;
172
switch (itemClass) {
173
case 'rect':
174
return attrs.fill;
175
default:
176
return '#455a64';
177
// It returns the original color for
178
// those elements that are not fill over
179
}
180
}
181
});
182
183
// sets fill on select series
184
series.selected().stroke(function () {
185
var attrs = this.attributes;
186
if (attrs) {
187
// attr in svg.file
188
var itemClass = attrs.class;
189
switch (itemClass) {
190
case 'rect':
191
return attrs.stroke;
192
default:
193
return '#000';
194
// It returns the original color for
195
// those elements that are not fill over
196
}
197
}
198
});
199
200
// label info
201
var labelInfo = chart.label();
202
labelInfo
203
.useHtml(true)
204
.padding(10)
205
.hAlign('left')
206
.position('left-top')
207
.anchor('left-top')
208
.offsetY(75)
209
.offsetX(20)
210
.width(265)
211
.text(
212
'<span style="color: #545f69; font-size: 14px;">' +
213
'<b>Please select a location.</b><br><br>You can do this by ' +
214
'clicking on the<br>desired location , so you can select' +
215
'<br>multiple locations with the aid<br>of a combination ' +
216
'of keys:<br><b><i>shift/ctrl' +
217
' + target place</i></b>.</span>'
218
);
219
labelInfo.background({
220
fill: '#FCFCFC',
221
stroke: '#E1E1E1',
222
corners: 3,
223
cornerType: 'ROUND'
224
});
225
226
// set container id for the chart
227
chart.container(stage);
228
// initiate chart drawing
229
chart.draw();
230
}
231
});
232
});