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
// sets fill series
33
seatMapSeries.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
// sets stroke series
51
seatMapSeries.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 hoverFill color
58
seatMapSeries.hoverFill(function(){
59
var attrs = this.attributes;
60
if (attrs) {
61
// get the class
62
var clas = attrs.class;
63
switch (clas) {
64
case "inner_elements" :
65
return "red";
66
default:
67
return anychart.color.lighten(attrs.fill, 0.5);
68
}
69
} else {
70
return this.sourceColor;
71
}
72
});
73
74
// set the selectFill color
75
seatMapSeries.selectFill(function(){
76
var attrs = this.attributes;
77
return attrs ? anychart.color.darken(attrs.fill, 0.2) : this.sourceColor;
78
});
79
80
// sets stroke series
81
seatMapSeries.hoverStroke(function () {
82
var attrs = this.attributes;
83
return attrs ? attrs.stroke : this.sourceColor;
84
});
85
86
// sets stroke series
87
seatMapSeries.selectStroke(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
};