HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
$.ajax({
3
type: "GET",
4
url: "https://static.anychart.com/images/docs/seat_map/house.svg",
5
success: function (svgData) {
6
createSeatMap(svgData);
7
}
8
});
9
});
10
11
function createSeatMap(svg){
12
// create a new seat map
13
var chart = anychart.seatMap();
14
// load SVG data
15
chart.geoData(svg);
16
// set the title
17
chart.title("Set colors using standard methods");
18
// create new series
19
seatMapSeries = chart.choropleth();
20
// load data
21
seatMapSeries.data([
22
{id: "Hall", value: "720"},
23
{id: "Room2", value: "165"},
24
{id: "WC", value: "49"},
25
{id: "Room1", value: "143"},
26
{id: "Kitchen", value: "208"}
27
]);
28
29
// load svg-file how it looked(colors stroke/fill except for elements of series)
30
chart.unboundRegions("as-is");
31
32
// set the fill in the normal state
33
seatMapSeries.normal().fill(function () {
34
var attrs = this.attributes;
35
if (attrs) return attrs.fill;
36
});
37
38
// set the fill in the hover state
39
seatMapSeries.hovered().fill(function() {
40
var attrs = this.attributes;
41
return attrs ? anychart.color.lighten(attrs.fill, 0.5) : this.sourceColor;
42
});
43
44
// set the fill in the selected state
45
seatMapSeries.selected().fill(function() {
46
var attrs = this.attributes;
47
return attrs ? anychart.color.darken(attrs.fill, 0.2) : this.sourceColor;
48
});
49
50
// set the stroke in the normal state
51
seatMapSeries.normal().stroke(function () {
52
var attrs = this.attributes;
53
// if the stroke attribute exists in the SVG file then color it with a color set in the document
54
return attrs ? attrs.stroke : this.sourceColor;
55
});
56
57
// set the stroke in the hover state
58
seatMapSeries.hovered().stroke(function () {
59
var attrs = this.attributes;
60
return attrs ? attrs.stroke : this.sourceColor;
61
});
62
63
// set the stroke in the selected state
64
seatMapSeries.selected().stroke(function () {
65
var attrs = this.attributes;
66
return attrs ? attrs.stroke : this.sourceColor;
67
});
68
69
// set container id for the chart
70
chart.container("container");
71
// initiate chart drawing
72
chart.draw();
73
};