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/house1.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("Coloring the attributes using classes");
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
if (attrs) {
37
// get the class
38
var clas = attrs.class;
39
switch (clas) {
40
case "inner_elements" :
41
return "red";
42
default:
43
return "red";
44
}
45
} else {
46
return this.sourceColor;
47
}
48
});
49
50
// set the fill in the hover state
51
seatMapSeries.hovered().fill(function() {
52
var attrs = this.attributes;
53
if (attrs) {
54
// get the class
55
var clas = attrs.class;
56
switch (clas) {
57
case "inner_elements" :
58
return "red";
59
default:
60
return anychart.color.lighten(attrs.fill, 0.5);
61
}
62
} else {
63
return this.sourceColor;
64
}
65
});
66
67
// set the fill in the selected state
68
seatMapSeries.selected().fill(function() {
69
var attrs = this.attributes;
70
return attrs ? anychart.color.darken(attrs.fill, 0.2) : this.sourceColor;
71
});
72
73
// set the stroke in the normal state
74
seatMapSeries.normal().stroke(function () {
75
var attrs = this.attributes;
76
// if the stroke attribute exists in the SVG file then color it with a color set in the document
77
return attrs ? attrs.stroke : this.sourceColor;
78
});
79
80
// set the stroke in the hover state
81
seatMapSeries.hovered().stroke(function () {
82
var attrs = this.attributes;
83
return attrs ? attrs.stroke : this.sourceColor;
84
});
85
86
// set the stroke in the selected state
87
seatMapSeries.selected().stroke(function () {
88
var attrs = this.attributes;
89
return attrs ? attrs.stroke : this.sourceColor;
90
});
91
92
// set container id for the chart
93
chart.container("container");
94
// initiate chart drawing
95
chart.draw();
96
};