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
3
// load data from a json file
4
anychart.data.loadJsonFile("https://gist.githubusercontent.com/awanshrestha/9e91dbd3ac4626446cd84f8be97016ae/raw/160d5ab2da59a5264e716dcbe3239ce7ac9104b6/Wealthiest%2520Cities%25202023.json",
5
function(data) {
6
7
// create a map chart
8
var map = anychart.map();
9
10
// set the global map geodata
11
map.geoData("anychart.maps.world");
12
13
// add zoom ui controls
14
var zoomController = anychart.ui.zoom();
15
zoomController.render(map);
16
17
// set the land area color
18
map.unboundRegions()
19
.enabled(true)
20
.fill('#E1E1E1')
21
.stroke('#D2D2D2');
22
23
// set the background color
24
map.background()
25
.fill({
26
color: '#daedea',
27
opacity: 0.5
28
});
29
30
// create a dataset from data
31
var citiesDataSet = anychart.data.set(data).mapAs({size: "Billionaires"});
32
33
// helper function to create several series
34
var createSeries = function (name, data, color) {
35
36
// set the bubble series
37
var series = map.bubble(data);
38
39
// set the max and min bubble sizes
40
map.maxBubbleSize(20);
41
map.minBubbleSize(3);
42
43
// configure the series settings
44
series
45
.name(name)
46
.type("circle")
47
.fill(color)
48
.stroke(anychart.color.darken(color, 0.4))
49
.labels(false);
50
51
// configure the series legend items
52
series
53
.legendItem()
54
.iconType("circle")
55
.iconFill(color)
56
.iconStroke(anychart.color.darken(color, 0.4))
57
58
};
59
60
// create 5 series, filtering the data by number of millionaires
61
createSeries(
62
"Over 100,000",
63
citiesDataSet.filter("Millionaires", filterFunction(100000, 1000000)),
64
"#D1FAE9"
65
);
66
createSeries(
67
"50,000–100,000",
68
citiesDataSet.filter("Millionaires", filterFunction(50000, 100000)),
69
"#9CE0E5"
70
);
71
createSeries(
72
"10,000–50,000",
73
citiesDataSet.filter("Millionaires", filterFunction(10000, 50000)),
74
"#00ACC3"
75
);
76
createSeries(
77
"1,000–10,000",
78
citiesDataSet.filter("Millionaires", filterFunction(1000, 10000)),
79
"#355CB1"
80
);
81
createSeries(
82
"Up to 1,000",
83
citiesDataSet.filter("Millionaires", filterFunction(0, 1000)),
84
"#002D79"
85
);
86
87
// add a legend
88
map.legend(true);
89
90
// configure the map tooltip
91
map.tooltip()
92
.useHtml(true)
93
.titleFormat(function () {
94
return this.getData("name") +
95
" (" +
96
this.getData("Country") +
97
")";
98
})
99
.format(function () {
100
return (
101
"<span style='color: #bfbfbf'>Millionaires: </span>" +
102
this.getData("Millionaires") +
103
"<br/>" +
104
"<span style='color: #bfbfbf'>Centimillionaires: </span>" +
105
this.getData("Centimillionaires") +
106
"<br/>" +
107
"<span style='color: #bfbfbf'>Billionaires: </span>" +
108
this.getData("Billionaires")
109
);
110
});
111
112
// set a title
113
map.title()
114
.enabled(true)
115
.useHtml(true)
116
.text(
117
"Wealthiest Cities<br/>" +
118
"<span style='color: #929292; font-size: 12px;'>" +
119
"Based on the number of millionaires</span>"
120
);
121
122
// specify a container
123
map.container("container");
124
125
// draw the resulting map
126
map.draw();
127
128
}
129
);
130
131
});
132
133
// helper filter function
134
function filterFunction(val1, val2) {
135
if (val2) {
136
return function (fieldVal) {
137
return val1 <= fieldVal && fieldVal < val2;
138
};
139
}
140
return function (fieldVal) {
141
return val1 <= fieldVal;
142
};
143
}