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();
32
33
// helper function to create several series
34
var createSeries = function (name, data, color) {
35
36
// set the marker series
37
var series = map.marker(data);
38
39
// configure the series settings
40
series
41
.name(name)
42
.type("circle")
43
.fill(color)
44
.stroke(anychart.color.darken(color, 0.4))
45
.labels(false);
46
47
// configure the series legend items
48
series
49
.legendItem()
50
.iconType("circle")
51
.iconFill(color)
52
.iconStroke(anychart.color.darken(color, 0.4))
53
54
};
55
56
// create 5 series, filtering the data by number of millionaires
57
createSeries(
58
"Over 100,000",
59
citiesDataSet.filter("Millionaires", filterFunction(100000, 1000000)),
60
"#D1FAE9"
61
);
62
createSeries(
63
"50,000–100,000",
64
citiesDataSet.filter("Millionaires", filterFunction(50000, 100000)),
65
"#9CE0E5"
66
);
67
createSeries(
68
"10,000–50,000",
69
citiesDataSet.filter("Millionaires", filterFunction(10000, 50000)),
70
"#00ACC3"
71
);
72
createSeries(
73
"1,000–10,000",
74
citiesDataSet.filter("Millionaires", filterFunction(1000, 10000)),
75
"#355CB1"
76
);
77
createSeries(
78
"Up to 1,000",
79
citiesDataSet.filter("Millionaires", filterFunction(0, 1000)),
80
"#002D79"
81
);
82
83
// add a legend
84
map.legend(true);
85
86
// configure the map tooltip
87
map.tooltip()
88
.useHtml(true)
89
.titleFormat(function () {
90
return this.getData("name") +
91
" (" +
92
this.getData("Country") +
93
")";
94
})
95
.format(function () {
96
return (
97
"<span style='color: #bfbfbf'>Millionaires: </span>" +
98
this.getData("Millionaires") +
99
"<br/>" +
100
"<span style='color: #bfbfbf'>Centimillionaires: </span>" +
101
this.getData("Centimillionaires") +
102
"<br/>" +
103
"<span style='color: #bfbfbf'>Billionaires: </span>" +
104
this.getData("Billionaires")
105
);
106
});
107
108
// set a title
109
map.title()
110
.enabled(true)
111
.useHtml(true)
112
.text(
113
"Wealthiest Cities<br/>" +
114
"<span style='color: #929292; font-size: 12px;'>" +
115
"Based on the number of millionaires</span>"
116
);
117
118
// specify a container
119
map.container("container");
120
121
// draw the resulting map
122
map.draw();
123
124
}
125
);
126
127
});
128
129
// helper filter function
130
function filterFunction(val1, val2) {
131
if (val2) {
132
return function (fieldVal) {
133
return val1 <= fieldVal && fieldVal < val2;
134
};
135
}
136
return function (fieldVal) {
137
return val1 <= fieldVal;
138
};
139
}