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
3
// This sample uses 3rd party proj4 component
4
// that makes it possible to set coordinates
5
// for the points and labels on the map and
6
// required for custom projections and grid labels formatting.
7
// See https://docs.anychart.com/7.14.3/Maps/Map_Projections
8
9
// create a container for maps and a button
10
stage = anychart.graphics.create("container");
11
12
// world map
13
chart = anychart.map();
14
15
// major maps
16
usaMap = anychart.map();
17
18
// canada map
19
canadaMap = anychart.map();
20
21
worldDataSet = anychart.data.set([
22
{id: "US", name: "USA", value: "1"},
23
{id: "CA", name: "Canada", value: "2", fill: "#FF9966"}
24
]);
25
26
usaDataSet = anychart.data.set([
27
{"id": "US.LA", "value": 22},
28
{"id": "US.TX", "value": 23},
29
{"id": "US.NY", "value": 45}
30
]);
31
32
canadaDataSet = anychart.data.set([
33
{"id": "CA.BC", "value": 3},
34
{"id": "CA.NF", "value": 11},
35
{"id": "CA.PE", "value": 12}
36
]);
37
38
// world data and series
39
chart.geoData(anychart.maps.world);
40
worldSeries = chart.choropleth(worldDataSet);
41
42
// usa data and series
43
usaMap.geoData(anychart.maps.united_states_of_america);
44
usaSeries = usaMap.choropleth(usaDataSet);
45
46
// canada data and series
47
canadaMap.geoData(anychart.maps.canada);
48
canadaSeries = canadaMap.choropleth(canadaDataSet);
49
canadaSeries.fill("#FF9966");
50
51
// regions maps
52
txMap = anychart.map();
53
txMap.geoData(anychart.maps["texas"]);
54
55
laMap = anychart.map();
56
laMap.geoData(anychart.maps["louisiana"]);
57
58
nyMap = anychart.map();
59
nyMap.geoData(anychart.maps["new_york"]);
60
61
bcMap = anychart.map();
62
bcMap.geoData(anychart.maps["british_columbia"]);
63
64
nfMap = anychart.map();
65
nfMap.geoData(anychart.maps["newfoundland_and_labrador"]);
66
67
peMap = anychart.map();
68
peMap.geoData(anychart.maps["prince_edward_island"]);
69
70
71
// set the drillDownMaps
72
chart.drillDownMap({
73
"US": usaMap,
74
"CA": canadaMap
75
});
76
77
usaMap.drillDownMap({
78
"US.LA": laMap,
79
"US.TX": txMap,
80
"US.NY": nyMap
81
});
82
83
canadaMap.drillDownMap({
84
"CA.BC": bcMap,
85
"CA.NF": nfMap,
86
"CA.PE": peMap
87
});
88
89
// create drill up label
90
drillToLabel = createLabel("Drill Up", 0, function() {
91
// Drill down to the specified item.
92
chart.drillUp();
93
});
94
95
// set the selectionMode
96
chart.interactivity({selectionMode: "drillDown"});
97
98
chart.container(stage);
99
chart.draw();
100
101
});
102
103
104
// helper function to create buttons
105
function createLabel(text, offset, action){
106
var label = anychart.standalones.label();
107
label.background({fill: "#9E9E9E"});
108
label.zIndex(1000);
109
label.text(text);
110
label.fontColor("#fff");
111
label.padding(5);
112
label.parentBounds(offset, 5, 130, 100);
113
label.listen("click", action);
114
label.container(stage);
115
label.draw();
116
return label;
117
}